Passed
Pull Request — master (#312)
by
unknown
02:07
created

client/kit/src/lib/stores/theme.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 19
mnd 1
bc 1
fnc 0
dl 0
loc 24
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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