Naprawiono poprawne wyświetlanie zdjęcia od razu po dodaniu.
NORMALIZACJA ZDJECIA JEST NAJWAŻNIESZA
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user