Merge branch 'main' of https://github.com/VAR-Virtual-Air-Rescue/var-monorepo
This commit is contained in:
@@ -6,6 +6,7 @@ interface MissionStore {
|
||||
missions: MissionOptionalDefaults[];
|
||||
setMissions: (missions: MissionOptionalDefaults[]) => void;
|
||||
getMissions: () => Promise<undefined>;
|
||||
setMission: (mission: MissionOptionalDefaults) => void;
|
||||
}
|
||||
|
||||
export const useMissionsStore = create<MissionStore>((set) => ({
|
||||
@@ -47,4 +48,17 @@ export const useMissionsStore = create<MissionStore>((set) => ({
|
||||
set({ missions: data });
|
||||
return undefined;
|
||||
},
|
||||
setMission: (mission) =>
|
||||
set((state) => {
|
||||
const existingMissionIndex = state.missions.findIndex(
|
||||
(m) => m.id === mission.id,
|
||||
);
|
||||
if (existingMissionIndex !== -1) {
|
||||
const updatedMissions = [...state.missions];
|
||||
updatedMissions[existingMissionIndex] = mission;
|
||||
return { missions: updatedMissions };
|
||||
} else {
|
||||
return { missions: [...state.missions, mission] };
|
||||
}
|
||||
}),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user