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 <noreply@anthropic.com>
This commit is contained in:
parent
24df7a602c
commit
6392c77de4
1 changed files with 11 additions and 2 deletions
|
|
@ -2,11 +2,20 @@ import { createContext, useContext, useEffect, useState } from 'react';
|
||||||
|
|
||||||
const ThemeContext = createContext(null);
|
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 }) {
|
export function ThemeProvider({ children }) {
|
||||||
const [theme, setTheme] = useState(() => {
|
const [theme, setTheme] = useState(() => {
|
||||||
const stored = localStorage.getItem('hifi-theme');
|
const stored = localStorage.getItem('hifi-theme');
|
||||||
if (stored) return stored;
|
if (stored === 'light' || stored === 'dark') return stored;
|
||||||
return 'light';
|
return detectDefaultTheme();
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue