From: Rigel Kent Date: Tue, 11 Sep 2018 09:41:10 +0000 (+0200) Subject: remember theme in localStorage X-Git-Tag: v1.0.0-beta.13~13 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e3f7f600e87a19079abd79e9d04d9a150484557c;p=oweals%2Fpeertube.git remember theme in localStorage --- diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts index d8e02e2e5..17d33b4e5 100644 --- a/client/src/app/core/theme/theme.service.ts +++ b/client/src/app/core/theme/theme.service.ts @@ -1,8 +1,10 @@ import { Injectable } from '@angular/core' +import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' @Injectable() export class ThemeService { private theme = document.querySelector('body') + private darkTheme = false private previousTheme = {} constructor () { @@ -12,15 +14,24 @@ export class ThemeService { this.previousTheme['submenuColor'] = 'rgb(32,32,32)' this.previousTheme['inputColor'] = 'gray' this.previousTheme['inputPlaceholderColor'] = '#fff' + + this.darkTheme = (peertubeLocalStorage.getItem('theme') === 'dark') + console.log(this.darkTheme) + if (this.darkTheme) this.toggleDarkTheme(false) } - toggleDarkTheme () { + toggleDarkTheme (setLocalStorage = true) { // switch properties this.switchProperty('mainBackgroundColor') this.switchProperty('mainForegroundColor') this.switchProperty('submenuColor') this.switchProperty('inputColor') this.switchProperty('inputPlaceholderColor') + + if (setLocalStorage) { + this.darkTheme = !this.darkTheme + peertubeLocalStorage.setItem('theme', (this.darkTheme) ? 'dark' : 'default') + } } private switchProperty (property, newValue?) {