-
Notifications
You must be signed in to change notification settings - Fork 12
/
context.tsx
40 lines (34 loc) · 1.01 KB
/
context.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import create from 'zustand';
import { InititalState, Filters } from './types/interfaces';
import { User, Keycapset } from './types/types';
interface Actions {
setUser(user: User): void;
setUserWants(userWants: Keycapset[]): void;
setFilters(filters: Filters): void;
setDarkMode(darkmode: boolean): void;
}
export const emptyFilters = {
availability: 'none',
name: '',
brand: [],
type: [],
material: [],
};
export const INITITAL_STATE: InititalState = {
filters: emptyFilters,
keycapsets: [],
searchQuery: '',
allKeycapsetsCount: 0,
userWants: [],
isLoggedIn: false,
user: null,
isDarkMode: null,
};
const useStore = create<InititalState & Actions>((set) => ({
...INITITAL_STATE,
setUser: (user: User) => set({ user, isLoggedIn: true }),
setUserWants: (userWants: Keycapset[]) => set({ userWants }),
setFilters: (filters: Filters) => set({ filters }),
setDarkMode: (isDarkMode: boolean) => set({ isDarkMode }),
}));
export default useStore;