(fix) dark theme,train modal

This commit is contained in:
ManishMadan2882
2024-07-30 18:01:49 +05:30
parent f75ed4bc66
commit 09f2f2a9e7
8 changed files with 26 additions and 53 deletions

View File

@@ -70,35 +70,18 @@ export function useDarkTheme() {
localStorage.getItem('selectedTheme') === 'Dark' || false,
);
useEffect(() => {
// Check if dark mode preference exists in local storage
const savedMode: string | null = localStorage.getItem('selectedTheme');
// Set dark mode based on local storage preference
if (savedMode === 'Dark') {
setIsDarkTheme(true);
document
.getElementById('root')
?.classList.add('dark', 'dark:bg-raisin-black');
} else {
// If no preference found, set to default (light mode)
setIsDarkTheme(false);
document.getElementById('root')?.classList.remove('dark');
}
}, []);
useEffect(() => {
localStorage.setItem('selectedTheme', isDarkTheme ? 'Dark' : 'Light');
if (isDarkTheme) {
document
.getElementById('root')
?.classList.add('dark', 'dark:bg-raisin-black');
document.body?.classList.add('dark');
} else {
document.getElementById('root')?.classList.remove('dark');
document.body?.classList.remove('dark');
}
}, [isDarkTheme]);
//method to toggle theme
const toggleTheme: any = () => {
setIsDarkTheme(!isDarkTheme);
};
return [isDarkTheme, toggleTheme];
}