From e3f7f600e87a19079abd79e9d04d9a150484557c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 11 Sep 2018 11:41:10 +0200 Subject: remember theme in localStorage --- client/src/app/core/theme/theme.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'client/src/app/core/theme/theme.service.ts') 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?) { -- cgit v1.2.3