- Pages: login, register, tasks list, task detail - Components: TaskCard, TaskForm, GroupSelector, StatusBadge, Header - Tailwind CSS, dark/light mode, PWA manifest - Running on :3001 via systemd Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { createContext, useContext, useEffect, useState, ReactNode } from "react";
|
|
|
|
type Theme = "light" | "dark";
|
|
|
|
interface ThemeContextType {
|
|
theme: Theme;
|
|
toggleTheme: () => void;
|
|
}
|
|
|
|
const ThemeContext = createContext<ThemeContextType>({
|
|
theme: "light",
|
|
toggleTheme: () => {},
|
|
});
|
|
|
|
export function useTheme() {
|
|
return useContext(ThemeContext);
|
|
}
|
|
|
|
export default function ThemeProvider({ children }: { children: ReactNode }) {
|
|
const [theme, setTheme] = useState<Theme>("light");
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
const stored = localStorage.getItem("taskteam_theme") as Theme | null;
|
|
if (stored) {
|
|
setTheme(stored);
|
|
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
setTheme("dark");
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!mounted) return;
|
|
document.documentElement.classList.toggle("dark", theme === "dark");
|
|
localStorage.setItem("taskteam_theme", theme);
|
|
}, [theme, mounted]);
|
|
|
|
function toggleTheme() {
|
|
setTheme((prev) => (prev === "light" ? "dark" : "light"));
|
|
}
|
|
|
|
if (!mounted) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, toggleTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
);
|
|
}
|