refactor: make components more modular

would help in implementing name route

also did some stylistic changes
This commit is contained in:
zyachel
2023-04-15 20:56:15 +05:30
parent 8ce02d0236
commit 18ca98fd4a
43 changed files with 757 additions and 796 deletions

View File

@@ -5,9 +5,9 @@ const getInitialTheme = () => {
// for server-side rendering, as window isn't availabe there
if (typeof window === 'undefined') return 'light';
const userPrefersTheme = isLocalStorageAvailable()
? window.localStorage.getItem('theme')
: null;
const userPrefersTheme = (
isLocalStorageAvailable() ? window.localStorage.getItem('theme') : null
) as 'light' | 'dark' | null;
const browserPrefersDarkTheme = window.matchMedia(
'(prefers-color-scheme: dark)'
).matches;
@@ -28,7 +28,7 @@ const updateMetaTheme = () => {
const initialContext = {
theme: '',
setTheme: (theme: string) => {},
setTheme: (theme: ReturnType<typeof getInitialTheme>) => { },
};
export const themeContext = createContext(initialContext);
@@ -36,7 +36,7 @@ export const themeContext = createContext(initialContext);
const ThemeProvider = ({ children }: { children: ReactNode }) => {
const [curTheme, setCurTheme] = useState(getInitialTheme);
const setTheme = (theme: string) => {
const setTheme = (theme: typeof curTheme) => {
setCurTheme(theme);
if (isLocalStorageAvailable()) window.localStorage.setItem('theme', theme);
document.documentElement.dataset.theme = theme;