mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
42 lines
1000 B
TypeScript
42 lines
1000 B
TypeScript
import { produce } from 'immer';
|
|
import { merge } from 'lodash';
|
|
import { create } from 'zustand';
|
|
import { persist } from 'zustand/middleware';
|
|
import { Region } from '../constants/regions';
|
|
import { Stat } from '../core/blitz/generateStats';
|
|
import { IndividualTankStats } from '../types/tanksStats';
|
|
|
|
interface SessionBase {
|
|
columns: Stat[];
|
|
}
|
|
|
|
export interface SessionTracking extends SessionBase {
|
|
tracking: true;
|
|
player: {
|
|
id: number;
|
|
region: Region;
|
|
since: number;
|
|
stats: IndividualTankStats[];
|
|
};
|
|
}
|
|
|
|
interface SessionNotTracking extends SessionBase {
|
|
tracking: false;
|
|
}
|
|
|
|
type Session = SessionTracking | SessionNotTracking;
|
|
|
|
export const useSession = create<Session>()(
|
|
persist(
|
|
(set) => ({
|
|
columns: ['battles', 'winrate', 'wn8', 'damage'],
|
|
tracking: false,
|
|
}),
|
|
{ name: 'session-2', merge: (a, b) => merge(b, a) },
|
|
),
|
|
);
|
|
|
|
export default function mutateSession(recipe: (draft: Session) => void) {
|
|
useSession.setState(produce(recipe));
|
|
}
|