Naprawiono poprawne wyświetlanie zdjęcia od razu po dodaniu.

NORMALIZACJA ZDJECIA JEST NAJWAŻNIESZA
This commit is contained in:
2025-05-23 21:19:11 +02:00
parent f22de8150d
commit 9d253c4c86
4 changed files with 28 additions and 22 deletions

View File

@@ -16,20 +16,24 @@ const useLocationStore = create((set, get) => ({
}
},
addLocation: async (location) => {
set({ loading: true, error: null });
try {
const newLoc = await api.addLocation(location);
set((state) => ({
locations: [...state.locations, newLoc],
loading: false,
}));
return newLoc;
} catch (error) {
set({ error, loading: false });
return null;
}
},
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, normalizedLoc],
loading: false,
}));
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) {