refactor(ui): move bootstrap cache sync out of preferences
This commit is contained in:
20
packages/ui/src/lib/ui-bootstrap-cache-sync.tsx
Normal file
20
packages/ui/src/lib/ui-bootstrap-cache-sync.tsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { createEffect } from "solid-js"
|
||||||
|
import { useConfig } from "../stores/preferences"
|
||||||
|
import { writeUiBootstrapCache } from "./ui-bootstrap-cache"
|
||||||
|
|
||||||
|
export function UiBootstrapCacheSync() {
|
||||||
|
const { isLoaded, preferences, themePreference } = useConfig()
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (!isLoaded()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeUiBootstrapCache({
|
||||||
|
theme: themePreference(),
|
||||||
|
locale: preferences().locale ?? null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ 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 { readUiBootstrapCache } from "./lib/ui-bootstrap-cache"
|
import { readUiBootstrapCache } from "./lib/ui-bootstrap-cache"
|
||||||
|
import { UiBootstrapCacheSync } from "./lib/ui-bootstrap-cache-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"
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ async function bootstrap() {
|
|||||||
render(
|
render(
|
||||||
() => (
|
() => (
|
||||||
<ConfigProvider>
|
<ConfigProvider>
|
||||||
|
<UiBootstrapCacheSync />
|
||||||
<InstanceConfigProvider>
|
<InstanceConfigProvider>
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { createContext, createEffect, createMemo, createSignal, onMount, useContext } from "solid-js"
|
import { createContext, createMemo, createSignal, onMount, useContext } from "solid-js"
|
||||||
import type { Accessor, ParentComponent } from "solid-js"
|
import type { Accessor, ParentComponent } from "solid-js"
|
||||||
import { storage, type OwnerBucket } from "../lib/storage"
|
import { storage, type OwnerBucket } from "../lib/storage"
|
||||||
import { writeUiBootstrapCache } from "../lib/ui-bootstrap-cache"
|
|
||||||
import {
|
import {
|
||||||
ensureInstanceConfigLoaded,
|
ensureInstanceConfigLoaded,
|
||||||
getInstanceConfig,
|
getInstanceConfig,
|
||||||
@@ -599,21 +598,6 @@ const configContextValue: ConfigContextValue = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ConfigProvider: ParentComponent = (props) => {
|
export const ConfigProvider: ParentComponent = (props) => {
|
||||||
createEffect(() => {
|
|
||||||
if (!isLoaded()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const bucket = uiConfigBucket()
|
|
||||||
const theme = bucket.theme
|
|
||||||
const locale = bucket.settings?.locale
|
|
||||||
|
|
||||||
writeUiBootstrapCache({
|
|
||||||
theme: theme ?? null,
|
|
||||||
locale: locale ?? null,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
ensureLoaded().catch((error: unknown) => {
|
ensureLoaded().catch((error: unknown) => {
|
||||||
log.error("Failed to initialize settings", error)
|
log.error("Failed to initialize settings", error)
|
||||||
|
|||||||
Reference in New Issue
Block a user