diff options
Diffstat (limited to 'apps/web-shared/src/lib/helpers.ts')
| -rw-r--r-- | apps/web-shared/src/lib/helpers.ts | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/web-shared/src/lib/helpers.ts b/apps/web-shared/src/lib/helpers.ts index acf74d7..f2d0cca 100644 --- a/apps/web-shared/src/lib/helpers.ts +++ b/apps/web-shared/src/lib/helpers.ts @@ -1,4 +1,4 @@ -import {StorageKeys} from "$shared/lib/configuration"; +import {base_domain, CookieNames, StorageKeys} from "$shared/lib/configuration"; import {TimeEntryDto} from "$shared/lib/models/TimeEntryDto"; import {UnwrappedEntryDateTime} from "$shared/lib/models/UnwrappedEntryDateTime"; import {Temporal} from "@js-temporal/polyfill"; @@ -36,14 +36,24 @@ export function is_norwegian_phone_number(value: string): boolean { export function switch_theme() { const html = document.querySelector("html"); - if (html) { - if (html.dataset.theme === "dark") { - html.dataset.theme = "light"; - } else { - html.dataset.theme = "dark"; - } - localStorage.setItem(StorageKeys.theme, html.dataset.theme); + if (html.dataset.theme === "dark") { + html.dataset.theme = "light"; + } else { + html.dataset.theme = "dark"; } + set_cookie(CookieNames.theme, html.dataset.theme, base_domain()); +} + +export function get_cookie(name) { + const value = `; ${document.cookie}`; + const parts = value.split(`; ${name}=`); + if (parts.length === 2) return parts.pop().split(";").shift(); +} + +export function set_cookie(name, value, baseDomain = window.location.host) { + let asdf = name + "=" + encodeURIComponent(value) + (baseDomain ? ";domain=" + baseDomain : ""); + console.log(asdf); + document.cookie = asdf; } export function unwrap_date_time_from_entry(entry: TimeEntryDto): UnwrappedEntryDateTime { |
