mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Fix local storage read (now with ttl attached)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user