AeThex-OS/client/src/components/ThemeToggle.tsx
sirpiglr 9901ea3e2d Add AI chatbot and theme toggle functionality for improved user experience
Integrates a new AI chatbot using OpenAI, adds a theme toggle for light/dark modes, and includes a live activity feed for administrators.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 279f1558-c0e3-40e4-8217-be7e9f4c6eca
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: c19480f5-d8f1-4a0b-98ea-7bfe9144b25d
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/b984cb14-1d19-4944-922b-bc79e821ed35/279f1558-c0e3-40e4-8217-be7e9f4c6eca/yVjwaR4
Replit-Helium-Checkpoint-Created: true
2025-12-16 00:00:42 +00:00

58 lines
1.5 KiB
TypeScript

import { useState, useEffect } from "react";
import { Moon, Sun } from "lucide-react";
export function useTheme() {
const [theme, setTheme] = useState<"light" | "dark">("dark");
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
if (typeof window !== "undefined") {
const stored = localStorage.getItem("aethex_theme");
if (stored === "light" || stored === "dark") {
setTheme(stored);
}
}
}, []);
useEffect(() => {
if (!mounted) return;
const root = document.documentElement;
if (theme === "light") {
root.classList.remove("dark");
root.classList.add("light");
} else {
root.classList.remove("light");
root.classList.add("dark");
}
if (typeof window !== "undefined") {
localStorage.setItem("aethex_theme", theme);
}
}, [theme, mounted]);
const toggleTheme = () => {
setTheme((prev) => (prev === "dark" ? "light" : "dark"));
};
return { theme, setTheme, toggleTheme };
}
export function ThemeToggle() {
const { theme, toggleTheme } = useTheme();
return (
<button
onClick={toggleTheme}
className="p-2 rounded-lg border border-white/10 bg-card/50 hover:bg-card transition-colors"
data-testid="button-theme-toggle"
aria-label={`Switch to ${theme === "dark" ? "light" : "dark"} mode`}
>
{theme === "dark" ? (
<Sun className="w-4 h-4 text-primary" />
) : (
<Moon className="w-4 h-4 text-primary" />
)}
</button>
);
}