chore: build
ci-api / test (push) Failing after 8m7s
ci-web / test (push) Failing after 5m5s

This commit is contained in:
Xor290
2026-09-20 12:18:33 +02:00
parent 8f4c7fa47a
commit 919c807004
174 changed files with 9669 additions and 1308 deletions
+39
View File
@@ -0,0 +1,39 @@
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
export type Theme = "dark" | "light";
const STORAGE_KEY = "ui_theme";
function detectInitialTheme(): Theme {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === "dark" || stored === "light") return stored;
return window.matchMedia?.("(prefers-color-scheme: light)").matches ? "light" : "dark";
}
interface ThemeContextValue {
theme: Theme;
toggleTheme: () => void;
}
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
export function ThemeProvider({ children }: { children: ReactNode }) {
const [theme, setTheme] = useState<Theme>(detectInitialTheme);
useEffect(() => {
document.documentElement.dataset.theme = theme;
localStorage.setItem(STORAGE_KEY, theme);
}, [theme]);
function toggleTheme() {
setTheme((current) => (current === "dark" ? "light" : "dark"));
}
return <ThemeContext.Provider value={{ theme, toggleTheme }}>{children}</ThemeContext.Provider>;
}
export function useTheme(): ThemeContextValue {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error("useTheme must be used within a ThemeProvider");
return ctx;
}