Files
blitzkit/src/stores/session.ts
T
2023-10-01 19:00:05 -05:00

57 lines
1.3 KiB
TypeScript

import { produce } from 'immer';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { CustomColumnDisplay } from '../app/tools/session/components/CustomColumn';
import { Region } from '../constants/regions';
import { NormalizedTankStats } from '../types/tanksStats';
type Session = (
| {
isTracking: false;
}
| {
isTracking: true;
region: Region;
id: number;
nickname: string;
tankStats: NormalizedTankStats;
time: number;
}
) & {
promptBeforeReset: boolean;
customColumns: {
display: CustomColumnDisplay;
showDelta: boolean;
}[] & { length: 4 };
showTotal: boolean;
showCareer: boolean;
};
export const useSession = create<Session>()(
devtools(
persist(
(set) => ({
isTracking: false,
promptBeforeReset: true,
showTotal: true,
showCareer: true,
customColumns: [
{ display: 'battles', showDelta: false },
{ display: 'winrate', showDelta: true },
{ display: 'wn8', showDelta: false },
{ display: 'damage', showDelta: true },
],
}),
{
name: 'session',
},
),
),
);
export default function mutateSession(recipe: (draft: Session) => void) {
useSession.setState(produce(recipe));
}