Passed
Pull Request — master (#312)
by
unknown
03:23 queued 01:23
created

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

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 20
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
mnd 1
bc 1
fnc 0
dl 0
loc 20
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
import { Theme } from "src/constants";
4
5
const THEME_COOKIE = "permacoop_theme";
6
7
export const getThemeCookie = (
8
  cookieStore: { get: (v: string) => string | undefined } = Cookies
9
): Theme | null => {
10
  return (cookieStore.get(THEME_COOKIE) as Theme | undefined) || null;
11
};
12
13
export const theme = writable(getThemeCookie(Cookies));
14
15
export const toggleTheme = () => {
16
  const newTheme = get(theme) === Theme.DARK ? Theme.LIGHT : Theme.DARK;
17
  Cookies.set(THEME_COOKIE, newTheme.toString());
18
  theme.set(newTheme);
19
};
20