feat: Initialize the Electron frontend with core UI components and integrate Convex backend services.
This commit is contained in:
42
Frontend/Electron/src/contexts/ThemeContext.jsx
Normal file
42
Frontend/Electron/src/contexts/ThemeContext.jsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
|
||||
const STORAGE_KEY = 'discord-theme';
|
||||
|
||||
export const THEMES = {
|
||||
LIGHT: 'theme-light',
|
||||
DARK: 'theme-dark',
|
||||
ASH: 'theme-darker',
|
||||
ONYX: 'theme-midnight',
|
||||
};
|
||||
|
||||
export const THEME_LABELS = {
|
||||
[THEMES.LIGHT]: 'Light',
|
||||
[THEMES.DARK]: 'Dark',
|
||||
[THEMES.ASH]: 'Ash',
|
||||
[THEMES.ONYX]: 'Onyx',
|
||||
};
|
||||
|
||||
const ThemeContext = createContext();
|
||||
|
||||
export function ThemeProvider({ children }) {
|
||||
const [theme, setTheme] = useState(() => {
|
||||
return localStorage.getItem(STORAGE_KEY) || THEMES.DARK;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.className = theme;
|
||||
localStorage.setItem(STORAGE_KEY, theme);
|
||||
}, [theme]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ theme, setTheme, THEMES, THEME_LABELS }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
const ctx = useContext(ThemeContext);
|
||||
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user