-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore.ts
33 lines (30 loc) · 1008 Bytes
/
store.ts
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
import createStore, { type State } from "zustand";
import { persist } from "zustand/middleware";
interface IState extends State {
isBurgerMenuOpen: boolean;
isPageLoaded: boolean;
isRouteChanged: boolean;
setPageLoaded: (isLoaded: boolean) => void;
setRouteChanged: (isChanged: boolean) => void;
setBurgerMenuOpen: (isOpen: boolean) => void;
}
export const useDarkModeStore = createStore<{
isDarkMode: boolean;
toggleDarkMode: () => void;
}>(
persist(
set => ({
isDarkMode: false as boolean,
toggleDarkMode: () => set(state => ({ isDarkMode: !state.isDarkMode }))
}),
{ name: "theme-mode-storage" }
)
);
export const usePageStore = createStore<IState>(set => ({
isBurgerMenuOpen: false,
isPageLoaded: false,
isRouteChanged: false,
setPageLoaded: isLoaded => set(() => ({ isPageLoaded: isLoaded })),
setRouteChanged: isChanged => set(() => ({ isRouteChanged: isChanged })),
setBurgerMenuOpen: isOpen => set(() => ({ isBurgerMenuOpen: isOpen }))
}));