refactor(ui): drop bootstrap config cache layer
This commit is contained in:
@@ -1,28 +0,0 @@
|
|||||||
import { createEffect } from "solid-js"
|
|
||||||
import { useGlobalCache } from "./hooks/use-global-cache"
|
|
||||||
import { useConfig } from "../stores/preferences"
|
|
||||||
import type { UiBootstrapConfig } from "./ui-config-bootstrap"
|
|
||||||
|
|
||||||
export function UiConfigBootstrapSync() {
|
|
||||||
const { isLoaded, preferences, themePreference } = useConfig()
|
|
||||||
const cache = useGlobalCache({
|
|
||||||
scope: "ui-bootstrap",
|
|
||||||
cacheId: "ui-config",
|
|
||||||
version: "1",
|
|
||||||
})
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
if (!isLoaded()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const next: UiBootstrapConfig = {
|
|
||||||
theme: themePreference(),
|
|
||||||
locale: preferences().locale,
|
|
||||||
}
|
|
||||||
|
|
||||||
cache.set(next)
|
|
||||||
})
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { getCacheEntry } from "./global-cache"
|
|
||||||
|
|
||||||
export interface UiBootstrapConfig {
|
|
||||||
theme?: "light" | "dark" | "system"
|
|
||||||
locale?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const UI_BOOTSTRAP_CACHE_ENTRY = {
|
|
||||||
scope: "ui-bootstrap",
|
|
||||||
cacheId: "ui-config",
|
|
||||||
version: "1",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export function readUiBootstrapConfig(): UiBootstrapConfig {
|
|
||||||
return getCacheEntry<UiBootstrapConfig>(UI_BOOTSTRAP_CACHE_ENTRY) ?? {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getUiBootstrapCacheEntry() {
|
|
||||||
return UI_BOOTSTRAP_CACHE_ENTRY
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,6 @@ import { InstanceConfigProvider } from "./stores/instance-config"
|
|||||||
import { runtimeEnv } from "./lib/runtime-env"
|
import { runtimeEnv } from "./lib/runtime-env"
|
||||||
import { I18nProvider, preloadLocaleMessages } from "./lib/i18n"
|
import { I18nProvider, preloadLocaleMessages } from "./lib/i18n"
|
||||||
import { storage } from "./lib/storage"
|
import { storage } from "./lib/storage"
|
||||||
import { readUiBootstrapConfig } from "./lib/ui-config-bootstrap"
|
|
||||||
import { UiConfigBootstrapSync } from "./lib/ui-config-bootstrap-sync"
|
|
||||||
import "./index.css"
|
import "./index.css"
|
||||||
import "@git-diff-view/solid/styles/diff-view-pure.css"
|
import "@git-diff-view/solid/styles/diff-view-pure.css"
|
||||||
|
|
||||||
@@ -31,38 +29,27 @@ async function bootstrap() {
|
|||||||
// (and then refine once persisted config loads).
|
// (and then refine once persisted config loads).
|
||||||
document.documentElement.removeAttribute("data-theme")
|
document.documentElement.removeAttribute("data-theme")
|
||||||
|
|
||||||
const cachedUiConfig = readUiBootstrapConfig()
|
|
||||||
let theme = cachedUiConfig.theme
|
|
||||||
let locale = cachedUiConfig.locale
|
|
||||||
|
|
||||||
if (theme === undefined || locale === undefined) {
|
|
||||||
try {
|
try {
|
||||||
const uiConfig = await storage.loadConfigOwner("ui")
|
const uiConfig = await storage.loadConfigOwner("ui")
|
||||||
if (theme === undefined) {
|
const theme = (uiConfig as any)?.theme
|
||||||
const nextTheme = (uiConfig as any)?.theme
|
const locale = typeof (uiConfig as any)?.settings?.locale === "string" ? (uiConfig as any).settings.locale : undefined
|
||||||
theme = nextTheme === "light" || nextTheme === "dark" || nextTheme === "system" ? nextTheme : undefined
|
|
||||||
}
|
|
||||||
if (locale === undefined) {
|
|
||||||
locale = typeof (uiConfig as any)?.settings?.locale === "string" ? (uiConfig as any).settings.locale : undefined
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// If config fails to load, fall back to CSS defaults.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!theme || theme === "system") {
|
if (theme === "light" || theme === "dark") {
|
||||||
document.documentElement.removeAttribute("data-theme")
|
|
||||||
} else {
|
|
||||||
document.documentElement.setAttribute("data-theme", theme)
|
document.documentElement.setAttribute("data-theme", theme)
|
||||||
|
} else {
|
||||||
|
document.documentElement.removeAttribute("data-theme")
|
||||||
}
|
}
|
||||||
|
|
||||||
await preloadLocaleMessages(locale)
|
await preloadLocaleMessages(locale)
|
||||||
|
} catch {
|
||||||
|
// If config fails to load, fall back to CSS defaults.
|
||||||
|
await preloadLocaleMessages()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
() => (
|
() => (
|
||||||
<ConfigProvider>
|
<ConfigProvider>
|
||||||
<UiConfigBootstrapSync />
|
|
||||||
<InstanceConfigProvider>
|
<InstanceConfigProvider>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
|
|||||||
Reference in New Issue
Block a user