Fix local storage read (now with ttl attached)

This commit is contained in:
MartinBraquet
2026-02-28 01:45:12 +01:00
parent fbb10344e1
commit 8548b85d03
4 changed files with 10 additions and 5 deletions

View File

@@ -34,5 +34,6 @@ export const applyFontPreference = (font: FontOption) => {
const getStoredFontPreference = (): FontOption => {
if (typeof window === 'undefined') return 'atkinson'
return JSON.parse(localStorage.getItem('font-preference') ?? 'null') ?? 'atkinson'
const theme = JSON.parse(localStorage.getItem('font-preference') ?? 'null') ?? 'atkinson'
return theme.value ?? (theme as FontOption)
}

View File

@@ -9,7 +9,8 @@ export const useMeasurementSystem = () => {
try {
const saved = localStorage.getItem('measurement-system')
if (saved) {
const parsed = JSON.parse(saved)
let parsed = JSON.parse(saved)
parsed = parsed.value ?? parsed
if (parsed === 'metric' || parsed === 'imperial') {
return parsed
}

View File

@@ -49,7 +49,8 @@ const reRenderTheme = () => {
}
function getTheme() {
return JSON.parse(localStorage.getItem('theme') ?? 'null') ?? 'auto'
const theme = JSON.parse(localStorage.getItem('theme') ?? 'null') ?? 'auto'
return theme.value ?? theme
}
function isDark(theme: theme_option | null) {

View File

@@ -1,7 +1,8 @@
// run this in <head> as blocking to prevent flash of unstyled content. See theme-provider.tsx
{
const localTheme = localStorage.getItem('theme')
const theme = localTheme ? JSON.parse(localTheme) : 'auto'
let theme = localTheme ? JSON.parse(localTheme) : 'auto'
theme = theme.value ?? theme
if (
theme === 'dark' ||
@@ -11,7 +12,8 @@
}
const localFontPreference = localStorage.getItem('font-preference')
const fontPreference = localFontPreference ? JSON.parse(localFontPreference) : 'atkinson'
let fontPreference = localFontPreference ? JSON.parse(localFontPreference) : 'atkinson'
fontPreference = fontPreference.value ?? fontPreference
const fontFamilies = {
atkinson: '"Atkinson Hyperlegible Next", Georgia, "Times New Roman", Times, serif',