mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
57 lines
1.3 KiB
TypeScript
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));
|
|
}
|