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