aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-02-28 13:52:21 +0100
committerGitHub <noreply@github.com>2020-02-28 13:52:21 +0100
commitd3217560a611b94f888ecf3de93b428a7521d4de (patch)
tree26fc984f351afb994dc13c94e138476ded50c76a /client/src/app/core
parent64645512b08875c18ebdc009a550cdfa69def955 (diff)
downloadPeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.gz
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.zst
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.zip
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
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/auth/auth-user.model.ts15
-rw-r--r--client/src/app/core/theme/theme.service.ts31
2 files changed, 18 insertions, 28 deletions
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 {
67} 67}
68 68
69export class AuthUser extends User implements ServerMyUserModel { 69export class AuthUser extends User implements ServerMyUserModel {
70 private static KEYS = {
71 ID: 'id',
72 ROLE: 'role',
73 EMAIL: 'email',
74 VIDEOS_HISTORY_ENABLED: 'videos-history-enabled',
75 USERNAME: 'username',
76 NSFW_POLICY: 'nsfw_policy',
77 WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled',
78 AUTO_PLAY_VIDEO: 'auto_play_video'
79 }
80
81 tokens: Tokens 70 tokens: Tokens
82 specialPlaylists: MyUserSpecialPlaylist[] 71 specialPlaylists: MyUserSpecialPlaylist[]
83 72
@@ -106,10 +95,6 @@ export class AuthUser extends User implements ServerMyUserModel {
106 peertubeLocalStorage.removeItem(this.KEYS.USERNAME) 95 peertubeLocalStorage.removeItem(this.KEYS.USERNAME)
107 peertubeLocalStorage.removeItem(this.KEYS.ID) 96 peertubeLocalStorage.removeItem(this.KEYS.ID)
108 peertubeLocalStorage.removeItem(this.KEYS.ROLE) 97 peertubeLocalStorage.removeItem(this.KEYS.ROLE)
109 peertubeLocalStorage.removeItem(this.KEYS.NSFW_POLICY)
110 peertubeLocalStorage.removeItem(this.KEYS.WEBTORRENT_ENABLED)
111 peertubeLocalStorage.removeItem(this.KEYS.VIDEOS_HISTORY_ENABLED)
112 peertubeLocalStorage.removeItem(this.KEYS.AUTO_PLAY_VIDEO)
113 peertubeLocalStorage.removeItem(this.KEYS.EMAIL) 98 peertubeLocalStorage.removeItem(this.KEYS.EMAIL)
114 Tokens.flush() 99 Tokens.flush()
115 } 100 }
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'
4import { environment } from '../../../environments/environment' 4import { environment } from '../../../environments/environment'
5import { PluginService } from '@app/core/plugins/plugin.service' 5import { PluginService } from '@app/core/plugins/plugin.service'
6import { ServerConfig, ServerConfigTheme } from '@shared/models' 6import { ServerConfig, ServerConfigTheme } from '@shared/models'
7import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
8import { first } from 'rxjs/operators' 7import { first } from 'rxjs/operators'
8import { User } from '@app/shared/users/user.model'
9import { UserService } from '@app/shared/users/user.service'
10import { LocalStorageService } from '@app/shared/misc/storage.service'
11import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
9 12
10@Injectable() 13@Injectable()
11export class ThemeService { 14export class ThemeService {
12 15
13 private static KEYS = {
14 LAST_ACTIVE_THEME: 'last_active_theme'
15 }
16
17 private oldThemeName: string 16 private oldThemeName: string
18 private themes: ServerConfigTheme[] = [] 17 private themes: ServerConfigTheme[] = []
19 18
@@ -24,8 +23,10 @@ export class ThemeService {
24 23
25 constructor ( 24 constructor (
26 private auth: AuthService, 25 private auth: AuthService,
26 private userService: UserService,
27 private pluginService: PluginService, 27 private pluginService: PluginService,
28 private server: ServerService 28 private server: ServerService,
29 private localStorageService: LocalStorageService
29 ) {} 30 ) {}
30 31
31 initialize () { 32 initialize () {
@@ -77,11 +78,11 @@ export class ThemeService {
77 private getCurrentTheme () { 78 private getCurrentTheme () {
78 if (this.themeFromLocalStorage) return this.themeFromLocalStorage.name 79 if (this.themeFromLocalStorage) return this.themeFromLocalStorage.name
79 80
80 if (this.auth.isLoggedIn()) { 81 const theme = this.auth.isLoggedIn()
81 const theme = this.auth.getUser().theme 82 ? this.auth.getUser().theme
82 if (theme !== 'instance-default') return theme 83 : this.userService.getAnonymousUser().theme
83 }
84 84
85 if (theme !== 'instance-default') return theme
85 return this.serverConfig.theme.default 86 return this.serverConfig.theme.default
86 } 87 }
87 88
@@ -111,9 +112,9 @@ export class ThemeService {
111 112
112 this.pluginService.reloadLoadedScopes() 113 this.pluginService.reloadLoadedScopes()
113 114
114 peertubeLocalStorage.setItem(ThemeService.KEYS.LAST_ACTIVE_THEME, JSON.stringify(theme)) 115 this.localStorageService.setItem(User.KEYS.THEME, JSON.stringify(theme), false)
115 } else { 116 } else {
116 peertubeLocalStorage.removeItem(ThemeService.KEYS.LAST_ACTIVE_THEME) 117 this.localStorageService.removeItem(User.KEYS.THEME, false)
117 } 118 }
118 119
119 this.oldThemeName = currentTheme 120 this.oldThemeName = currentTheme
@@ -126,6 +127,10 @@ export class ThemeService {
126 127
127 if (!this.auth.isLoggedIn()) { 128 if (!this.auth.isLoggedIn()) {
128 this.updateCurrentTheme() 129 this.updateCurrentTheme()
130
131 this.localStorageService.watch([User.KEYS.THEME]).subscribe(
132 () => this.updateCurrentTheme()
133 )
129 } 134 }
130 135
131 this.auth.userInformationLoaded 136 this.auth.userInformationLoaded
@@ -134,7 +139,7 @@ export class ThemeService {
134 } 139 }
135 140
136 private loadAndSetFromLocalStorage () { 141 private loadAndSetFromLocalStorage () {
137 const lastActiveThemeString = peertubeLocalStorage.getItem(ThemeService.KEYS.LAST_ACTIVE_THEME) 142 const lastActiveThemeString = this.localStorageService.getItem(User.KEYS.THEME)
138 if (!lastActiveThemeString) return 143 if (!lastActiveThemeString) return
139 144
140 try { 145 try {