-
Notifications
You must be signed in to change notification settings - Fork 66
/
state.ts
53 lines (42 loc) · 1.31 KB
/
state.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { persistentAtom } from "@nanostores/persistent";
import { useStore } from "@nanostores/vue";
import site from "~/site";
import { WritableAtom, atom } from "nanostores";
const { languages } = site;
// Get the default system based on browser hint
const defaultSystem: string =
typeof window !== "undefined"
? window.navigator.userAgent.indexOf("Mac") != -1
? "macOS"
: "Linux"
: "Linux";
// Current selected language (stored in localStorage)
export const languageState: WritableAtom<string> = persistentAtom<string>(
"zero-to-nix:language",
languages[0]!,
);
export const language = useStore(languageState);
// Current selected system (stored in localStorage)
export const systemState: WritableAtom<string> = persistentAtom<string>(
"zero-to-nix:system",
defaultSystem,
);
export const system = useStore(systemState);
// Nav drawer state
const drawerAtom = atom<boolean>(false);
export const drawerIsOpen = useStore(drawerAtom);
export const toggleDrawer = () => {
drawerAtom.set(!drawerAtom.get());
};
export const closeDrawer = () => {
drawerAtom.set(false);
};
// Mailing list modal
const modalAtom = atom<boolean>(false);
export const modalIsOpen = useStore(modalAtom);
export const openModal = () => {
modalAtom.set(true);
};
export const closeModal = () => {
modalAtom.set(false);
};