-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dark mode #242
base: develop
Are you sure you want to change the base?
Dark mode #242
Changes from 1 commit
2090467
cc85be4
7682c8c
8802689
92c4317
ca990d8
9fd5006
85c07f8
6224ca0
1225995
fa519c1
99a20ea
b16b137
f34c9d2
daf5b90
142500f
fbb6599
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,24 @@ export const useDarkMode = () => { | |
const [theme, setTheme] = useState('light'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The names are not clear. It should be ' |
||
const [themeData, setThemeData] = useState(lightTheme); | ||
const [mountedComponent, setMountedComponent] = useState(false); | ||
const setCookie = (name, value, days) => { | ||
const domain = '.realdevsquad.com'; | ||
const expires = new Date(Date.now() + 24 * days * 60 * 60 * 1000); | ||
const cookieStr = `${name}=${value}; expires=${expires}; domain=${domain}; path=/`; | ||
shubham-y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
document.cookie = cookieStr; | ||
}; | ||
const accessCookie = (cookieName) => { | ||
shubham-y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const name = `${cookieName}=`; | ||
shubham-y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const allCookieArray = document.cookie.split(';'); | ||
for (let i = 0; i < allCookieArray.length; i += 1) { | ||
const temp = allCookieArray[i].trim(); | ||
if (temp.indexOf(name) === 0) | ||
return temp.substring(name.length, temp.length); | ||
} | ||
return ''; | ||
}; | ||
const setMode = (mode) => { | ||
window.localStorage.setItem('theme', mode); | ||
setCookie('theme', mode, 30); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for using |
||
setTheme(mode); | ||
const themeMode = mode === 'light' ? lightTheme : darkTheme; | ||
setThemeData(themeMode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name should be change to |
||
|
@@ -18,14 +34,13 @@ export const useDarkMode = () => { | |
}; | ||
|
||
useEffect(() => { | ||
const localTheme = window.localStorage.getItem('theme'); | ||
const localTheme = accessCookie('theme'); | ||
const themeMode = localTheme === 'light' ? lightTheme : darkTheme; | ||
if (localTheme) { | ||
setTheme(localTheme); | ||
setThemeData(themeMode); | ||
} | ||
setMountedComponent(true); | ||
console.log('here'); | ||
}, []); | ||
return [theme, themeData, themeToggler, mountedComponent]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should return the |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move '
light
' toconstant
file