diff options
Diffstat (limited to 'js/setTheme.ts')
-rw-r--r-- | js/setTheme.ts | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/js/setTheme.ts b/js/setTheme.ts index d9a6cf8..25debba 100644 --- a/js/setTheme.ts +++ b/js/setTheme.ts @@ -1,8 +1,24 @@ -function setTheme(theme: string) { - console.log("setting theme to `" + theme + "`"); +enum Theme { + Light, + Dark, +} + +function setTheme(theme: Theme) { + let is_valid_theme = + theme == Theme.Light + || theme == Theme.Dark; + + if (!is_valid_theme) { + console.log("invalid theme \"" + theme + "\""); + + // Use default: + theme = Theme.Dark; + } + + console.log("setting theme to `" + Theme[theme] + "`"); let body = document.getElementById("body")!; - body.setAttribute("data-theme", theme); + body.setAttribute("data-theme", Theme[theme]); - localStorage.setItem("theme", theme); + localStorage.setItem("theme", JSON.stringify(theme)); } |