mirror of
https://github.com/Xevion/banner.git
synced 2026-01-31 08:23:35 -06:00
Integrate ts-rs for Rust-to-TypeScript type generation, build course search page with filters, pagination, and expandable detail rows, and refactor theme toggle into a reactive store with view transition animation.
37 lines
892 B
TypeScript
37 lines
892 B
TypeScript
class ThemeStore {
|
|
isDark = $state<boolean>(false);
|
|
private initialized = false;
|
|
|
|
init() {
|
|
if (this.initialized || typeof window === "undefined") return;
|
|
this.initialized = true;
|
|
|
|
const stored = localStorage.getItem("theme");
|
|
if (stored === "light" || stored === "dark") {
|
|
this.isDark = stored === "dark";
|
|
} else {
|
|
this.isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
}
|
|
|
|
this.updateDOMClass();
|
|
}
|
|
|
|
toggle() {
|
|
this.isDark = !this.isDark;
|
|
localStorage.setItem("theme", this.isDark ? "dark" : "light");
|
|
this.updateDOMClass();
|
|
}
|
|
|
|
private updateDOMClass() {
|
|
if (typeof document === "undefined") return;
|
|
|
|
if (this.isDark) {
|
|
document.documentElement.classList.add("dark");
|
|
} else {
|
|
document.documentElement.classList.remove("dark");
|
|
}
|
|
}
|
|
}
|
|
|
|
export const themeStore = new ThemeStore();
|