Remove public registration, support administrator-managed accounts, and persist personal preferences. Refs #2 #5 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
28 lines
806 B
TypeScript
28 lines
806 B
TypeScript
import { useState, type ReactNode, useEffect } from 'react'
|
|
import { ThemeContext, type Theme } from './theme'
|
|
|
|
export function ThemeProvider({ children }: { children: ReactNode }) {
|
|
const [theme, setThemeState] = useState<Theme>(() => {
|
|
const saved = localStorage.getItem('theme') as Theme | null
|
|
if (saved === 'light' || saved === 'dark') return saved
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
})
|
|
|
|
useEffect(() => {
|
|
const root = document.documentElement
|
|
root.classList.toggle('dark', theme === 'dark')
|
|
localStorage.setItem('theme', theme)
|
|
}, [theme])
|
|
|
|
function setTheme(t: Theme) {
|
|
setThemeState(t)
|
|
}
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, setTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
)
|
|
}
|
|
|