This commit is contained in:
PxlLoewe
2025-04-21 15:07:56 -07:00
11 changed files with 513 additions and 75 deletions

View File

@@ -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] };
}
}),
}));