Skip to content

Commit ee987e4

Browse files
avinashsharma080Avinash Sharma
and
Avinash Sharma
authored
fixed bug that caused state revert in darkmode button (#353)
* fixed bug that caused state revert in darkmode button * code cleanup * code cleanup --------- Co-authored-by: Avinash Sharma <[email protected]>
1 parent f7fd288 commit ee987e4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/components/NavToggleDarkMode.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
>
99
<svg
1010
id="sun"
11-
v-show="isDark"
11+
v-show="isLight"
1212
xmlns="http://www.w3.org/2000/svg"
1313
class="h-6 w-6"
1414
fill="none"
@@ -26,7 +26,7 @@
2626
<svg
2727
id="moon"
2828
xmlns="http://www.w3.org/2000/svg"
29-
v-show="!isDark"
29+
v-show="!isLight"
3030
class="h-6 w-6"
3131
fill="none"
3232
viewBox="0 0 24 24"
@@ -114,15 +114,15 @@ export default {
114114
115115
data() {
116116
return {
117-
userTheme: 'light-theme',
118-
isDark: true
117+
isLight: true
118+
? localStorage.getItem('user-theme') == 'light-theme'
119+
: false
119120
}
120121
},
121122
122123
methods: {
123124
toggleTheme() {
124-
const activeTheme = localStorage.getItem('user-theme')
125-
if (activeTheme === 'light-theme') {
125+
if (localStorage.getItem('user-theme') == 'light-theme') {
126126
this.setTheme('dark-theme')
127127
} else {
128128
this.setTheme('light-theme')
@@ -137,7 +137,7 @@ export default {
137137
localStorage.setItem('user-theme', theme)
138138
this.userTheme = theme
139139
document.documentElement.className = theme
140-
this.isDark = !this.isDark
140+
this.isLight = !this.isLight
141141
},
142142
143143
getMediaPreference() {

0 commit comments

Comments
 (0)