Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/context/ThemeContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@ import { createContext, useContext, useState, useEffect } from 'react'
const ThemeCtx = createContext(null)

export function ThemeProvider({ children }) {

const [theme, setTheme] = useState(() => {
return localStorage.getItem('oe_theme') || 'dark'
try {
const stored = localStorage.getItem('oe_theme')

if (stored === 'dark' || stored === 'light') {
return stored
}

if (stored !== null) {
console.warn(`Invalid theme value found in localStorage: "${stored}". Falling back to 'dark'.`)
}

} catch (error) {
console.warn('Failed to read theme from localStorage:', error)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return 'dark'
})

useEffect(() => {
document.documentElement.setAttribute('data-theme', theme)
localStorage.setItem('oe_theme', theme)
try {
localStorage.setItem('oe_theme', theme)
} catch (error) {
console.warn('Failed to save theme to localStorage:', error)
}
}, [theme])

const toggleTheme = () => {
Expand Down
Loading