Mission Popup WIP
This commit is contained in:
@@ -4,6 +4,7 @@ import { create } from "zustand";
|
||||
interface MissionStore {
|
||||
missions: MissionOptionalDefaults[];
|
||||
setMissions: (missions: MissionOptionalDefaults[]) => void;
|
||||
setMission: (mission: MissionOptionalDefaults) => void;
|
||||
}
|
||||
|
||||
export const useMissionsStore = create<MissionStore>((set) => ({
|
||||
@@ -24,4 +25,17 @@ export const useMissionsStore = create<MissionStore>((set) => ({
|
||||
},
|
||||
],
|
||||
setMissions: (missions) => set({ missions }),
|
||||
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