From d3217560a611b94f888ecf3de93b428a7521d4de Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 28 Feb 2020 13:52:21 +0100 Subject: Add visitor settings, rework logged-in dropdown (#2514) * Add visitor settings, rework logged-in dropdown * Make user dropdown P2P switch functional * Fix lint * Fix unnecessary notification when user logs out * Simplify visitor settings code and remove unnecessary icons * Catch parsing errors and reindent menu styles --- client/src/app/core/auth/auth-user.model.ts | 15 -------------- client/src/app/core/theme/theme.service.ts | 31 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 28 deletions(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 1447daead..4ad904beb 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -67,17 +67,6 @@ class Tokens { } export class AuthUser extends User implements ServerMyUserModel { - private static KEYS = { - ID: 'id', - ROLE: 'role', - EMAIL: 'email', - VIDEOS_HISTORY_ENABLED: 'videos-history-enabled', - USERNAME: 'username', - NSFW_POLICY: 'nsfw_policy', - WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled', - AUTO_PLAY_VIDEO: 'auto_play_video' - } - tokens: Tokens specialPlaylists: MyUserSpecialPlaylist[] @@ -106,10 +95,6 @@ export class AuthUser extends User implements ServerMyUserModel { peertubeLocalStorage.removeItem(this.KEYS.USERNAME) peertubeLocalStorage.removeItem(this.KEYS.ID) peertubeLocalStorage.removeItem(this.KEYS.ROLE) - peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY) - peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_ENABLED) - peertubeLocalStorage.removeItem(this.KEYS.VIDEOS_HISTORY_ENABLED) - peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO) peertubeLocalStorage.removeItem(this.KEYS.EMAIL) Tokens.flush() } diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts index 2c5873cb3..3c066ca74 100644 --- a/client/src/app/core/theme/theme.service.ts +++ b/client/src/app/core/theme/theme.service.ts @@ -4,16 +4,15 @@ import { ServerService } from '@app/core/server' import { environment } from '../../../environments/environment' import { PluginService } from '@app/core/plugins/plugin.service' import { ServerConfig, ServerConfigTheme } from '@shared/models' -import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' import { first } from 'rxjs/operators' +import { User } from '@app/shared/users/user.model' +import { UserService } from '@app/shared/users/user.service' +import { LocalStorageService } from '@app/shared/misc/storage.service' +import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' @Injectable() export class ThemeService { - private static KEYS = { - LAST_ACTIVE_THEME: 'last_active_theme' - } - private oldThemeName: string private themes: ServerConfigTheme[] = [] @@ -24,8 +23,10 @@ export class ThemeService { constructor ( private auth: AuthService, + private userService: UserService, private pluginService: PluginService, - private server: ServerService + private server: ServerService, + private localStorageService: LocalStorageService ) {} initialize () { @@ -77,11 +78,11 @@ export class ThemeService { private getCurrentTheme () { if (this.themeFromLocalStorage) return this.themeFromLocalStorage.name - if (this.auth.isLoggedIn()) { - const theme = this.auth.getUser().theme - if (theme !== 'instance-default') return theme - } + const theme = this.auth.isLoggedIn() + ? this.auth.getUser().theme + : this.userService.getAnonymousUser().theme + if (theme !== 'instance-default') return theme return this.serverConfig.theme.default } @@ -111,9 +112,9 @@ export class ThemeService { this.pluginService.reloadLoadedScopes() - peertubeLocalStorage.setItem(ThemeService.KEYS.LAST_ACTIVE_THEME, JSON.stringify(theme)) + this.localStorageService.setItem(User.KEYS.THEME, JSON.stringify(theme), false) } else { - peertubeLocalStorage.removeItem(ThemeService.KEYS.LAST_ACTIVE_THEME) + this.localStorageService.removeItem(User.KEYS.THEME, false) } this.oldThemeName = currentTheme @@ -126,6 +127,10 @@ export class ThemeService { if (!this.auth.isLoggedIn()) { this.updateCurrentTheme() + + this.localStorageService.watch([User.KEYS.THEME]).subscribe( + () => this.updateCurrentTheme() + ) } this.auth.userInformationLoaded @@ -134,7 +139,7 @@ export class ThemeService { } private loadAndSetFromLocalStorage () { - const lastActiveThemeString = peertubeLocalStorage.getItem(ThemeService.KEYS.LAST_ACTIVE_THEME) + const lastActiveThemeString = this.localStorageService.getItem(User.KEYS.THEME) if (!lastActiveThemeString) return try { -- cgit v1.2.3