Ability to change theme from url on init and made it stateful

pull/1021/head
Cagatay Civici 2021-02-18 12:57:08 +03:00
parent f1683a8995
commit f981737c35
1 changed files with 22 additions and 0 deletions

View File

@ -51,6 +51,7 @@ export default {
} }
this.newsActive = this.newsActive && sessionStorage.getItem('primevue-news-hidden') == null; this.newsActive = this.newsActive && sessionStorage.getItem('primevue-news-hidden') == null;
this.initTheme();
}, },
watch: { watch: {
$route: { $route: {
@ -70,6 +71,22 @@ export default {
} }
}, },
methods: { methods: {
initTheme() {
let appTheme;
const queryString = window.location.search;
if (queryString)
appTheme = new URLSearchParams(queryString.substring(1)).get('theme');
else
appTheme = localStorage.getItem('theme');
if (appTheme) {
let darkTheme = this.isDarkTheme(appTheme);
this.changeTheme({
theme: appTheme,
dark: darkTheme
});
}
},
onMenuButtonClick() { onMenuButtonClick() {
if (this.sidebarActive) { if (this.sidebarActive) {
this.sidebarActive = false; this.sidebarActive = false;
@ -101,6 +118,8 @@ export default {
if (event.theme.startsWith('md')) { if (event.theme.startsWith('md')) {
this.$primevue.config.ripple = true; this.$primevue.config.ripple = true;
} }
localStorage.setItem('theme', this.theme);
}, },
addClass(element, className) { addClass(element, className) {
if (!this.hasClass(element, className)) { if (!this.hasClass(element, className)) {
@ -129,6 +148,9 @@ export default {
} }
return false; return false;
},
isDarkTheme(theme) {
return theme.indexOf('dark') !== -1 || theme === 'vela' || theme === 'arya' || theme === 'luna';
} }
}, },
computed: { computed: {