Files
blitzkit/src/stores/tankopedia.ts
T

45 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-12-03 19:45:43 -06:00
import { produce } from 'immer';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
2023-12-04 12:35:27 -06:00
import { TankType, TreeTypeString } from '../components/Tanks';
2023-12-05 17:36:18 -06:00
import { Tier } from '../core/blitzkrieg/definitions/tanks';
2023-12-03 19:45:43 -06:00
2023-12-04 10:25:54 -06:00
export type TankopediaSortBy = 'tier' | 'name';
2023-12-03 19:45:43 -06:00
export type TankopediaSortDirection = 'ascending' | 'descending';
type Tankopedia = {
2023-12-04 11:47:33 -06:00
sort: {
by: TankopediaSortBy;
direction: TankopediaSortDirection;
};
filters: {
tiers: Tier[];
2023-12-04 12:35:27 -06:00
types: TankType[];
treeTypes: TreeTypeString[];
2023-12-04 19:10:26 -06:00
nations: string[];
2023-12-04 11:47:33 -06:00
};
2023-12-03 19:45:43 -06:00
};
export const useTankopedia = create<Tankopedia>()(
devtools(
persist(
(set) => ({
2023-12-04 11:47:33 -06:00
sort: {
by: 'tier',
direction: 'descending',
},
filters: {
2023-12-04 12:35:27 -06:00
tiers: [],
types: [],
treeTypes: [],
2023-12-04 19:10:26 -06:00
nations: [],
2023-12-04 11:47:33 -06:00
},
2023-12-03 19:45:43 -06:00
}),
{ name: 'tankopedia' },
),
),
);
export default function mutateTankopedia(recipe: (draft: Tankopedia) => void) {
useTankopedia.setState(produce(recipe));
}