forked from DeterminateSystems/zero-to-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.ts
41 lines (33 loc) · 1.09 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
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);
};