Little fix due to better mark

This commit is contained in:
2025-06-17 19:09:27 +02:00
parent 5e2926b9ef
commit 7b275c4e39
4 changed files with 23 additions and 15 deletions

View File

@@ -17,7 +17,6 @@ const useLocationStore = create((set, get) => ({
},
addLocation: async (location) => {
set({loading: true, error: null});
try {
const newLoc = await api.addLocation(location);
const normalizedLoc = {
@@ -26,7 +25,6 @@ const useLocationStore = create((set, get) => ({
};
set((state) => ({
locations: [...state.locations, normalizedLoc],
loading: false,
}));
return normalizedLoc;
} catch (error) {
@@ -36,18 +34,22 @@ const useLocationStore = create((set, get) => ({
},
updateLocation: async (id, location) => {
set({loading: true, error: null});
try {
const updated = await api.updateLocation(id, location);
const normalizedLoc = {
...updated,
imageSource: api.normalizeImageSource(updated.image)
};
const stringId = String(id);
set((state) => ({
locations: state.locations.map((loc) =>
loc.id === id ? updated : loc
String(loc.id) === stringId ? normalizedLoc : loc
),
loading: false,
}));
return updated;
return normalizedLoc;
} catch (error) {
set({error, loading: false});
return null;
@@ -55,13 +57,15 @@ const useLocationStore = create((set, get) => ({
},
deleteLocation: async (id) => {
set({loading: true, error: null});
try {
const deleted = await api.deleteLocation(id);
const stringId = String(id);
set((state) => ({
locations: state.locations.filter((loc) => loc.id !== id),
locations: state.locations.filter((loc) => String(loc.id) !== stringId),
loading: false,
}));
return deleted;
} catch (error) {
set({error, loading: false});