95c1f9b105
- Theme Context ausgelagert (ThemeContext.tsx + useDarkMode.ts) - Config Validation mit TMDB-API-Key Pflicht (config_validation.py) - Cache Key Centralization (cache/keys.py) - CD-Ripping mit abcde implementiert (Worker) - Docker Compose mit Healthchecks & LOG_LEVEL - ROADMAP.md & SAVEPOINT.md aktualisiert
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { createContext, useContext, useEffect, useState, ReactNode } from 'react'
|
|
|
|
type Theme = 'light' | 'dark'
|
|
|
|
interface ThemeContextType {
|
|
theme: Theme
|
|
toggleTheme: () => void
|
|
}
|
|
|
|
const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
|
|
|
|
export function ThemeProvider({ children }: { children: ReactNode }) {
|
|
const [theme, setTheme] = useState<Theme>('light')
|
|
|
|
useEffect(() => {
|
|
const savedTheme = localStorage.getItem('theme')
|
|
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
|
|
if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
|
|
setTheme('dark')
|
|
document.documentElement.setAttribute('data-theme', 'dark')
|
|
} else {
|
|
setTheme('light')
|
|
document.documentElement.setAttribute('data-theme', 'light')
|
|
}
|
|
}, [])
|
|
|
|
const toggleTheme = () => {
|
|
const newTheme = theme === 'dark' ? 'light' : 'dark'
|
|
setTheme(newTheme)
|
|
localStorage.setItem('theme', newTheme)
|
|
document.documentElement.setAttribute('data-theme', newTheme)
|
|
}
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, toggleTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useDarkMode() {
|
|
const context = useContext(ThemeContext)
|
|
if (!context) {
|
|
throw new Error('useDarkMode must be used within a ThemeProvider')
|
|
}
|
|
return context
|
|
}
|