fix(frontend): update theme context usage

- Add theme-context.tsx
- Update ThemeToggle.tsx to use ThemeContext
This commit is contained in:
Yunxiao Xu
2026-02-21 08:32:29 -08:00
parent 7be24d8884
commit eca24046dc
2 changed files with 21 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import { Moon, Sun } from "lucide-react"
import { Button } from "@/components/ui/button"
import { useTheme } from "@/components/theme-provider"
import { useTheme } from "@/components/theme-context"
export function ThemeToggle() {
const { theme, toggleTheme } = useTheme()

View File

@@ -0,0 +1,20 @@
import { createContext, useContext } from "react"
export type Theme = "light" | "dark"
export interface ThemeContextType {
theme: Theme
setTheme: (theme: Theme) => void
setThemeLocal: (theme: Theme) => void
toggleTheme: () => void
}
export const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
export const useTheme = () => {
const context = useContext(ThemeContext)
if (context === undefined) {
throw new Error("useTheme must be used within a ThemeProvider")
}
return context
}