fix(frontend): share one theme setting between the login page and console

The login page stored its theme under thecloud-theme while the console read floci-theme, so a choice made at sign-in was lost. Both now use floci-theme (falling back to the old key once), and useTheme tolerates unavailable storage.
This commit is contained in:
Zakaria
2026-10-23 12:00:10 -04:00
parent ece36e4a34
commit 9f38313e59
2 changed files with 19 additions and 5 deletions
+15 -3
View File
@@ -2,9 +2,17 @@ import {useEffect, useState} from 'react'
export type Theme = 'dark' | 'light' | 'cyber'
/** Shared with the login page (public/login.js) and index.html. */
const THEME_KEY = 'floci-theme'
function getStored(): Theme {
const v = localStorage.getItem('floci-theme')
return v === 'light' || v === 'cyber' ? v : 'dark'
try {
const v = localStorage.getItem(THEME_KEY)
return v === 'light' || v === 'cyber' ? v : 'dark'
} catch {
// localStorage unavailable (private mode) — fall back to the default theme.
return 'dark'
}
}
export function useTheme() {
@@ -12,7 +20,11 @@ export function useTheme() {
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme)
localStorage.setItem('floci-theme', theme)
try {
localStorage.setItem(THEME_KEY, theme)
} catch {
// Persisting the choice is optional when storage is unavailable.
}
}, [theme])
return {theme, setTheme}