From 6392c77de4ca637d7e18592d82461a8aab257765 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Tue, 7 Jul 2026 02:17:48 +0200 Subject: [PATCH] Default to dark mode outside 6:30-21:00 based on the visitor's clock Only applies as the initial value when no theme preference is stored yet - a manual toggle still sticks afterward, same precedent as the browser-language auto-detection. Co-Authored-By: Claude Sonnet 5 --- hifi-src/src/context/ThemeContext.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hifi-src/src/context/ThemeContext.jsx b/hifi-src/src/context/ThemeContext.jsx index e1c81ca..b64938a 100644 --- a/hifi-src/src/context/ThemeContext.jsx +++ b/hifi-src/src/context/ThemeContext.jsx @@ -2,11 +2,20 @@ import { createContext, useContext, useEffect, useState } from 'react'; const ThemeContext = createContext(null); +// Hellmodus 6:30-21:00 Uhr, sonst Dunkelmodus - gilt nur als Startwert, solange noch +// keine manuelle Wahl gespeichert ist (die manuelle Umschaltung bleibt danach bestehen, +// genau wie bei der Spracherkennung). +function detectDefaultTheme() { + const now = new Date(); + const hour = now.getHours() + now.getMinutes() / 60; + return hour >= 6.5 && hour < 21 ? 'light' : 'dark'; +} + export function ThemeProvider({ children }) { const [theme, setTheme] = useState(() => { const stored = localStorage.getItem('hifi-theme'); - if (stored) return stored; - return 'light'; + if (stored === 'light' || stored === 'dark') return stored; + return detectDefaultTheme(); }); useEffect(() => {