fix build

This commit is contained in:
ryanchristo 2026-11-17 22:15:27 -08:00
parent c0ee8a4a11
commit 71590024e7
No known key found for this signature in database
28 changed files with 943 additions and 2 deletions

56
contexts/ThemeContext.tsx Normal file
View file

@ -0,0 +1,56 @@
'use client'
import * as React from 'react'
import { createContext, useEffect, useState } from 'react'
export const cachedDarkKey = 'chora-web-dark'
const initDarkTheme = () => {
let initDarkTheme = false
if (
typeof localStorage !== 'undefined' &&
localStorage.getItem(cachedDarkKey)
) {
initDarkTheme = localStorage.getItem(cachedDarkKey) === 'true'
} else if (typeof window !== 'undefined') {
initDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
}
return initDarkTheme
}
const ThemeContext = createContext<any>({})
const ThemeContextProvider = (props: any) => {
const [darkTheme, setDarkTheme] = useState<boolean>(initDarkTheme())
useEffect(() => {
if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
const root = window.document.documentElement
if (darkTheme) {
root.classList.add('dark-theme')
root.style.backgroundColor = '#161616' // --background-secondary (dark-theme)
} else {
root.classList.remove('dark-theme')
root.style.backgroundColor = '#FCFCFC' // --background-secondary (light-theme)
}
localStorage.setItem(cachedDarkKey, darkTheme ? 'true' : 'false')
}
}, [darkTheme])
return (
<ThemeContext.Provider
value={{
darkTheme,
setDarkTheme,
}}
>
{props.children}
</ThemeContext.Provider>
)
}
export { ThemeContext, ThemeContextProvider }