2024-04-26 19:13:23 +02:00
|
|
|
import { create } from 'zustand';
|
2026-02-28 15:02:56 +08:00
|
|
|
import { Challenge } from '@bitsocialhq/pkc-react-hooks';
|
2024-04-26 19:13:23 +02:00
|
|
|
|
2026-02-24 15:15:44 +08:00
|
|
|
let nextChallengeId = 0;
|
|
|
|
|
|
2024-04-26 19:13:23 +02:00
|
|
|
interface State {
|
2026-02-24 15:15:44 +08:00
|
|
|
challenges: Array<{ challenge: Challenge; id: number }>;
|
2024-04-26 19:13:23 +02:00
|
|
|
addChallenge: (challenge: Challenge) => void;
|
|
|
|
|
removeChallenge: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useChallengesStore = create<State>((set) => ({
|
|
|
|
|
challenges: [],
|
|
|
|
|
addChallenge: (challenge: Challenge) => {
|
2026-02-24 15:15:44 +08:00
|
|
|
set((state) => ({
|
|
|
|
|
challenges: [...state.challenges, { challenge, id: nextChallengeId++ }],
|
|
|
|
|
}));
|
2024-04-26 19:13:23 +02:00
|
|
|
},
|
|
|
|
|
removeChallenge: () => {
|
|
|
|
|
set((state) => {
|
|
|
|
|
const challenges = [...state.challenges];
|
|
|
|
|
challenges.shift();
|
|
|
|
|
return { challenges };
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export default useChallengesStore;
|