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
+4 -2
View File
@@ -1,4 +1,6 @@
(() => {
// Shared with the console (useTheme.ts, index.html) so one choice applies everywhere.
const THEME_KEY = 'floci-theme';
const root = document.documentElement;
const buttons = document.querySelectorAll('.tg button');
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
@@ -6,7 +8,7 @@
function setTheme(theme) {
root.setAttribute('data-theme', theme);
try {
localStorage.setItem('thecloud-theme', theme);
localStorage.setItem(THEME_KEY, theme);
} catch (ignored) {
// Theme persistence is optional when browser storage is unavailable.
}
@@ -15,7 +17,7 @@
let initialTheme = matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
try {
const savedTheme = localStorage.getItem('thecloud-theme');
const savedTheme = localStorage.getItem(THEME_KEY) ?? localStorage.getItem('thecloud-theme');
if (savedTheme === 'dark' || savedTheme === 'light' || savedTheme === 'cyber') {
initialTheme = savedTheme;
}