Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 24 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import Cookies from "js-cookie"; |
||
2 | import { get, writable } from "svelte/store"; |
||
3 | |||
4 | export enum Theme { |
||
5 | LIGHT = "light", |
||
6 | DARK = "dark", |
||
7 | } |
||
8 | |||
9 | const THEME_COOKIE = "permacoop_theme"; |
||
10 | |||
11 | export const getThemeCookie = ( |
||
12 | cookieStore: { get: (v: string) => string | undefined } = Cookies |
||
13 | ): Theme | null => { |
||
14 | return (cookieStore.get(THEME_COOKIE) as Theme | undefined) || null; |
||
15 | }; |
||
16 | |||
17 | export const theme = writable(getThemeCookie(Cookies)); |
||
18 | |||
19 | export const toggleTheme = () => { |
||
20 | const newTheme = get(theme) === Theme.DARK ? Theme.LIGHT : Theme.DARK; |
||
21 | Cookies.set(THEME_COOKIE, newTheme.toString()); |
||
22 | theme.set(newTheme); |
||
23 | }; |
||
24 |