Skip to content

Commit

Permalink
Fix dark theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Jun 2, 2022
1 parent c34525a commit 95ecec4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
11 changes: 0 additions & 11 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"nprogress": "^0.2.0",
"pinia": "^2.0.0-rc.10",
"pinia-plugin-persistedstate": "^1.6.1",
"theme-change": "^2.0.2",
"vue": "^3.2.25",
"vue-axios": "^3.4.1"
},
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import Mappings from "./routes/Mappings.vue"
import OpenSourceLicenses from "./routes/OpenSourceLicenses.vue"
import NotFound from "./routes/NotFound.vue"
import {Alert, useAlertsStore} from "./app/alerts-store"
// @ts-ignore
import {themeChange} from "theme-change"
import {mapActions, mapState} from "pinia"
import Footer from "./components/Footer.vue"
Expand Down Expand Up @@ -41,7 +39,13 @@ export default defineComponent({
...mapActions(useAlertsStore, ["removeAlert"]),
},
mounted() {
themeChange(false)
let theme = localStorage.getItem("theme")
if (theme) {
document.documentElement.setAttribute("data-theme", theme)
} else {
localStorage.setItem("theme", "cupcake")
document.documentElement.setAttribute("data-theme", "cupcake")
}
},
})
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<li>
<label class="cursor-pointer">
Dark Mode
<input type="checkbox" class="toggle" :checked="darkMode" data-toggle-theme="dark,cupcake" data-act-class="ACTIVECLASS"/>
<input type="checkbox" class="toggle" :checked="darkMode" @click="setDarkMode(($event.target as any)?.checked ?? darkMode)"/>
</label>
</li>
</ul>
Expand All @@ -30,6 +30,12 @@ export default defineComponent({
return localStorage.getItem("theme") === "dark"
},
},
methods: {
setDarkMode(darkMode: boolean) {
localStorage.setItem("theme", darkMode ? "dark" : "cupcake");
document.documentElement.setAttribute("data-theme", localStorage.getItem("theme")!);
},
},
})
</script>

Expand Down

0 comments on commit 95ecec4

Please sign in to comment.