Naprawiono poprawne wyświetlanie zdjęcia od razu po dodaniu.
NORMALIZACJA ZDJECIA JEST NAJWAŻNIESZA
This commit is contained in:
@@ -19,7 +19,7 @@ export async function listLocations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizeImageSource = (image) => {
|
export const normalizeImageSource = (image) => {
|
||||||
if (!image) return null;
|
if (!image) return null;
|
||||||
|
|
||||||
if (typeof image === 'string') {
|
if (typeof image === 'string') {
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ export default function FormScreen() {
|
|||||||
placeholder="Wpisz powierzchnię"
|
placeholder="Wpisz powierzchnię"
|
||||||
style={{margin: 10, width: "100%"}}
|
style={{margin: 10, width: "100%"}}
|
||||||
value={formData.area}
|
value={formData.area}
|
||||||
keyboardType="numeric"
|
keyboardType="numbers-and-punctuation"
|
||||||
onChangeText={(e) => setFormData({...formData, area: e})}
|
onChangeText={(e) => setFormData({...formData, area: e})}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ export default function EditLocation() {
|
|||||||
image: formData.image,
|
image: formData.image,
|
||||||
area: parseFloat(formData.area),
|
area: parseFloat(formData.area),
|
||||||
population: parseInt(formData.population, 10),
|
population: parseInt(formData.population, 10),
|
||||||
|
longitude: parseFloat(formData.longitude),
|
||||||
|
latitude: parseFloat(formData.latitude),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
@@ -142,7 +144,7 @@ export default function EditLocation() {
|
|||||||
placeholder="Wpisz powierzchnię"
|
placeholder="Wpisz powierzchnię"
|
||||||
style={{margin: 10, width: "100%"}}
|
style={{margin: 10, width: "100%"}}
|
||||||
value={formData.area}
|
value={formData.area}
|
||||||
keyboardType="numeric"
|
keyboardType="numbers-and-punctuation"
|
||||||
onChangeText={(e) => setFormData({...formData, area: e})}
|
onChangeText={(e) => setFormData({...formData, area: e})}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -160,7 +162,7 @@ export default function EditLocation() {
|
|||||||
placeholder="Wpisz długość geograficzną"
|
placeholder="Wpisz długość geograficzną"
|
||||||
style={{margin: 10, width: "100%"}}
|
style={{margin: 10, width: "100%"}}
|
||||||
value={formData.longitude}
|
value={formData.longitude}
|
||||||
keyboardType="numeric"
|
keyboardType="numbers-and-punctuation"
|
||||||
onChangeText={(e) => setFormData({...formData, longitude: e})}
|
onChangeText={(e) => setFormData({...formData, longitude: e})}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -169,7 +171,7 @@ export default function EditLocation() {
|
|||||||
placeholder="Wpisz szerokość geograficzną"
|
placeholder="Wpisz szerokość geograficzną"
|
||||||
style={{margin: 10, width: "100%"}}
|
style={{margin: 10, width: "100%"}}
|
||||||
value={formData.latitude}
|
value={formData.latitude}
|
||||||
keyboardType="numeric"
|
keyboardType="numbers-and-punctuation"
|
||||||
onChangeText={(e) => setFormData({...formData, latitude: e})}
|
onChangeText={(e) => setFormData({...formData, latitude: e})}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -187,9 +189,9 @@ export default function EditLocation() {
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
|
||||||
backgroundColor: "#25292e",
|
backgroundColor: "#25292e",
|
||||||
justifyContent: "flex-start",
|
justifyContent: "flex-start",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
flexGrow: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,20 +16,24 @@ const useLocationStore = create((set, get) => ({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addLocation: async (location) => {
|
addLocation: async (location) => {
|
||||||
set({ loading: true, error: null });
|
set({ loading: true, error: null });
|
||||||
try {
|
try {
|
||||||
const newLoc = await api.addLocation(location);
|
const newLoc = await api.addLocation(location);
|
||||||
set((state) => ({
|
const normalizedLoc = {
|
||||||
locations: [...state.locations, newLoc],
|
...newLoc,
|
||||||
loading: false,
|
imageSource: api.normalizeImageSource(newLoc.image)
|
||||||
}));
|
};
|
||||||
return newLoc;
|
set((state) => ({
|
||||||
} catch (error) {
|
locations: [...state.locations, normalizedLoc],
|
||||||
set({ error, loading: false });
|
loading: false,
|
||||||
return null;
|
}));
|
||||||
}
|
return normalizedLoc;
|
||||||
},
|
} catch (error) {
|
||||||
|
set({ error, loading: false });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
updateLocation: async (id, location) => {
|
updateLocation: async (id, location) => {
|
||||||
set({ loading: true, error: null });
|
set({ loading: true, error: null });
|
||||||
@@ -37,7 +41,7 @@ const useLocationStore = create((set, get) => ({
|
|||||||
const updated = await api.updateLocation(id, location);
|
const updated = await api.updateLocation(id, location);
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: state.locations.map((loc) =>
|
locations: state.locations.map((loc) =>
|
||||||
loc.id == id ? updated : loc
|
loc.id === id ? updated : loc
|
||||||
),
|
),
|
||||||
|
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -55,7 +59,7 @@ const useLocationStore = create((set, get) => ({
|
|||||||
try {
|
try {
|
||||||
const deleted = await api.deleteLocation(id);
|
const deleted = await api.deleteLocation(id);
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: state.locations.filter((loc) => loc.id != id),
|
locations: state.locations.filter((loc) => loc.id !== id),
|
||||||
loading: false,
|
loading: false,
|
||||||
}));
|
}));
|
||||||
if(deleted) {
|
if(deleted) {
|
||||||
|
|||||||
Reference in New Issue
Block a user