Set and persist theme preference in localStorage

Implemented logic to store and retrieve theme preferences using localStorage for both logged-in users and guests. This ensures the selected theme is applied immediately on load, preventing theme flash issues. Adjusted initialization to apply the correct theme at app startup.
This commit is contained in:
2026-02-06 18:41:45 +01:00
parent 6434256dfb
commit 070057afb3
3 changed files with 26 additions and 3 deletions

View File

@@ -342,6 +342,14 @@ export default function App() {
setThemeKey(key);
applyTheme(key);
// ✅ sofort für nächsten Start merken (verhindert Flash)
try {
localStorage.setItem(`hpTheme:${(me?.email || "guest").toLowerCase()}`, key);
localStorage.setItem("hpTheme:guest", key); // fallback, falls noch nicht eingeloggt
} catch {
// ignore
}
try {
await api("/auth/theme", {
method: "PATCH",
@@ -351,6 +359,7 @@ export default function App() {
// theme locally already applied; ignore backend error
}
};
// ===== Stats (always fresh on open) =====
const openStatsModal = async () => {