From 40848fe321159e79ce0a07e1890070087d4a44e2 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Sun, 8 Oct 2023 13:24:43 +0200 Subject: [PATCH] feat: support dark mode within loader --- index.html | 135 +++++++++++++++++++++++++++++------ src/store/index.ts | 2 + src/store/tables/settings.ts | 14 ++++ 3 files changed, 128 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 72afc330..5c3e9d22 100644 --- a/index.html +++ b/index.html @@ -33,33 +33,122 @@ /> Prose + + + + + +
- +
- - diff --git a/src/store/index.ts b/src/store/index.ts index 103c9997..b02dd848 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -32,6 +32,7 @@ import $settings from "@/store/tables/settings"; const STORE_PERSIST_PREFIX = "prose"; const STORE_PERSIST_REVISION = "v1"; +const STORE_PERSIST_BOOT = "boot"; const STORE_KEY_PREFIX = "$"; const STORE_RESET_IGNORES = ["account", "layout"]; @@ -122,4 +123,5 @@ class Store { * EXPORTS * ************************************************************************* */ +export { STORE_PERSIST_PREFIX, STORE_PERSIST_BOOT }; export default new Store(); diff --git a/src/store/tables/settings.ts b/src/store/tables/settings.ts index 74287d61..a76a8241 100644 --- a/src/store/tables/settings.ts +++ b/src/store/tables/settings.ts @@ -11,6 +11,9 @@ // NPM import { defineStore } from "pinia"; +// PROJECT: STORES +import { STORE_PERSIST_PREFIX, STORE_PERSIST_BOOT } from "@/store"; + /************************************************************************** * TABLE * ************************************************************************* */ @@ -109,6 +112,17 @@ const $settings = defineStore("settings", { actions: { setAppearanceTheme(value: string): void { this.setGeneric(this.appearance, "theme", value); + + // Store in local storage? (for use during boot, before store is loaded) + if (window.localStorage !== undefined) { + const bootStorageKey = [ + STORE_PERSIST_PREFIX, + STORE_PERSIST_BOOT, + "theme" + ].join(":"); + + window.localStorage.setItem(bootStorageKey, value); + } }, setAvailabilityAutoAwayEnabled(value: boolean): void {