mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
- Document unused output_dir parameter in _download_by_id_remote - Apply default theme to DOM when no stored value exists - Clear auth token from state after successful authentication - Fix misleading comment in vite.config.ts - Clarify CDG generation comment in lyrics_processor.py - Improve accessibility in AIFeedbackModal (role, aria, labels, keyboard) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
import { useState, useEffect, useCallback } from "react"
|
|
|
|
const THEME_STORAGE_KEY = "nomad-karaoke-theme"
|
|
|
|
export type Theme = "dark" | "light"
|
|
|
|
export function useTheme() {
|
|
const [theme, setThemeState] = useState<Theme>("dark")
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
// Load theme from localStorage on mount
|
|
useEffect(() => {
|
|
setMounted(true)
|
|
const stored = localStorage.getItem(THEME_STORAGE_KEY) as Theme | null
|
|
if (stored === "light" || stored === "dark") {
|
|
setThemeState(stored)
|
|
applyTheme(stored)
|
|
} else {
|
|
// Apply default theme to DOM when no valid stored value exists
|
|
applyTheme("dark")
|
|
}
|
|
}, [])
|
|
|
|
const applyTheme = (newTheme: Theme) => {
|
|
const root = document.documentElement
|
|
if (newTheme === "light") {
|
|
root.classList.add("light")
|
|
} else {
|
|
root.classList.remove("light")
|
|
}
|
|
}
|
|
|
|
const setTheme = useCallback((newTheme: Theme) => {
|
|
setThemeState(newTheme)
|
|
localStorage.setItem(THEME_STORAGE_KEY, newTheme)
|
|
applyTheme(newTheme)
|
|
}, [])
|
|
|
|
const toggleTheme = useCallback(() => {
|
|
const newTheme = theme === "dark" ? "light" : "dark"
|
|
setTheme(newTheme)
|
|
}, [theme, setTheme])
|
|
|
|
const isDarkMode = theme === "dark"
|
|
|
|
return {
|
|
theme,
|
|
setTheme,
|
|
toggleTheme,
|
|
isDarkMode,
|
|
mounted,
|
|
}
|
|
}
|