Little fix due to better mark
This commit is contained in:
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user