- Admin page split into tabs (Server/Players/Chat/Mods/Backups/Logs) with hash + localStorage persistence; inactive tabs no longer mount. - Log viewer: level color-coding, search, level filter chips, auto-scroll toggle, copy button, visible-line count. - Installed mods list: search field + side filter (all/both/server/client) with live count; public ModList gets skeleton + empty states and search. - Theme toggle with no-flash inline init, localStorage + system preference. - Layout: full OG / Twitter metadata, title template, keywords, dual-theme themeColor, metadataBase. - lib/mods.ts: per-jar mtime+size parse cache (cold 6s -> warm ~45ms on /api/mods for the full mod list); cache eviction on mod removal. - ChatBridge polling eased 3s -> 5s with 2s stale window. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
type Theme = "light" | "dark";
|
|
|
|
function applyTheme(t: Theme) {
|
|
const html = document.documentElement;
|
|
html.classList.toggle("dark", t === "dark");
|
|
html.classList.toggle("light", t === "light");
|
|
html.style.colorScheme = t;
|
|
}
|
|
|
|
export function ThemeToggle() {
|
|
const [theme, setTheme] = useState<Theme>("dark");
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const saved = (localStorage.getItem("theme") as Theme | null) ?? null;
|
|
const prefers =
|
|
typeof window !== "undefined" &&
|
|
window.matchMedia("(prefers-color-scheme: light)").matches
|
|
? "light"
|
|
: "dark";
|
|
const initial: Theme = saved ?? prefers;
|
|
setTheme(initial);
|
|
applyTheme(initial);
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
const toggle = () => {
|
|
const next: Theme = theme === "dark" ? "light" : "dark";
|
|
setTheme(next);
|
|
applyTheme(next);
|
|
localStorage.setItem("theme", next);
|
|
};
|
|
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
onClick={toggle}
|
|
aria-label="Toggle theme"
|
|
className="px-2 text-muted-foreground"
|
|
title={mounted ? `${theme === "dark" ? "Light" : "Dark"} mode` : undefined}
|
|
>
|
|
<span aria-hidden="true" className="text-base leading-none">
|
|
{mounted ? (theme === "dark" ? "☀" : "☾") : "☾"}
|
|
</span>
|
|
</Button>
|
|
);
|
|
}
|