fix: typescript issue
This commit is contained in:
1 parent
b500bc8221
commit
dce4e4e751
2 files changed
+22
-5
No files matched your search
@@ -17,8 +17,9 @@ import { get, writable } from 'svelte/store'
|
||||
import { env } from '$env/dynamic/public'
|
||||
|
||||
const configuredTheme = env.PUBLIC_THEME ?? 'system'
|
||||
export const theme = writable<'system' | 'light' | 'dark'>(configuredTheme)
|
||||
|
||||
export const theme = writable<'system' | 'light' | 'dark'>(
|
||||
configuredTheme as 'system' | 'light' | 'dark'
|
||||
)
|
||||
|
||||
export const toggleTheme = () => {
|
||||
theme.update((theme) => {
|
||||
@@ -43,7 +44,8 @@ export const inDarkTheme = (): boolean => {
|
||||
|
||||
if (typeof localStorage != 'undefined') {
|
||||
const localTheme: 'system' | 'light' | 'dark' =
|
||||
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || configuredTheme
|
||||
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') ||
|
||||
configuredTheme
|
||||
|
||||
theme.update((theme) => localTheme)
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
import Sidebar from '$lib/components/ui/sidebar/Sidebar.svelte'
|
||||
// @ts-ignore
|
||||
import { pwaInfo } from 'virtual:pwa-info'
|
||||
import { inDarkTheme } from '$lib/ui/colors.js'
|
||||
import { inDarkTheme, theme } from '$lib/ui/colors.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { ToastContainer } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import { browser } from '$app/environment'
|
||||
|
||||
nProgress.configure({
|
||||
minimum: 0.4,
|
||||
@@ -34,10 +36,23 @@
|
||||
}
|
||||
|
||||
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
|
||||
$: darkTheme = $theme && inDarkTheme()
|
||||
|
||||
$: console.log(darkTheme)
|
||||
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
window
|
||||
.matchMedia('(prefers-color-scheme: dark)')
|
||||
.addEventListener('change', (event) => {
|
||||
darkTheme = inDarkTheme()
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta name="theme-color" content={inDarkTheme() ? '#020202' : '#f6f9fb'} />
|
||||
<meta name="theme-color" content={darkTheme ? '#020202' : '#f6f9fb'} />
|
||||
{@html webManifest}
|
||||
</svelte:head>
|
||||
|
||||
|
||||
Reference in new issue
Block a user