From 111fdc267b36201cf1be1fdf91017005102b4a5e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 11 Mar 2020 16:41:38 +0100 Subject: Handle overview pagination in client --- client/src/app/menu/language-chooser.component.ts | 1 + client/src/app/menu/menu.component.ts | 50 ++++++++++++++++------- 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'client/src/app/menu') diff --git a/client/src/app/menu/language-chooser.component.ts b/client/src/app/menu/language-chooser.component.ts index fb74cdf19..9bc934ad4 100644 --- a/client/src/app/menu/language-chooser.component.ts +++ b/client/src/app/menu/language-chooser.component.ts @@ -36,6 +36,7 @@ export class LanguageChooserComponent { getCurrentLanguage () { const english = 'English' const locale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) + if (locale) return I18N_LOCALES[locale] || english return english } diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index ce209457c..37702e975 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts @@ -23,8 +23,10 @@ export class MenuComponent implements OnInit { userHasAdminAccess = false helpVisible = false - languages: VideoConstant[] = [] + videoLanguages: string[] = [] + + private languages: VideoConstant[] = [] private serverConfig: ServerConfig private routesPerRight: { [ role in UserRight ]?: string } = { [UserRight.MANAGE_USERS]: '/admin/users', @@ -71,30 +73,32 @@ export class MenuComponent implements OnInit { } ) - this.hotkeysService.cheatSheetToggle.subscribe(isOpen => this.helpVisible = isOpen) + this.hotkeysService.cheatSheetToggle + .subscribe(isOpen => this.helpVisible = isOpen) + + this.serverService.getVideoLanguages() + .subscribe(languages => { + this.languages = languages - this.serverService.getVideoLanguages().subscribe(languages => this.languages = languages) + this.authService.userInformationLoaded + .subscribe(() => this.buildUserLanguages()) + }) } get language () { return this.languageChooserModal.getCurrentLanguage() } - get videoLanguages (): string[] { - if (!this.user) return - if (!this.user.videoLanguages) return [this.i18n('any language')] - return this.user.videoLanguages - .map(locale => this.langForLocale(locale)) - .map(value => value === undefined ? '?' : value) - } - get nsfwPolicy () { if (!this.user) return + switch (this.user.nsfwPolicy) { case 'do_not_list': return this.i18n('hide') + case 'blur': return this.i18n('blur') + case 'display': return this.i18n('display') } @@ -156,13 +160,29 @@ export class MenuComponent implements OnInit { toggleUseP2P () { if (!this.user) return this.user.webTorrentEnabled = !this.user.webTorrentEnabled - this.userService.updateMyProfile({ - webTorrentEnabled: this.user.webTorrentEnabled - }).subscribe(() => this.authService.refreshUserInformation()) + + this.userService.updateMyProfile({ webTorrentEnabled: this.user.webTorrentEnabled }) + .subscribe(() => this.authService.refreshUserInformation()) } langForLocale (localeId: string) { - return this.languages.find(lang => lang.id = localeId).label + return this.languages.find(lang => lang.id === localeId).label + } + + private buildUserLanguages () { + if (!this.user) { + this.videoLanguages = [] + return + } + + if (!this.user.videoLanguages) { + this.videoLanguages = [ this.i18n('any language') ] + return + } + + this.videoLanguages = this.user.videoLanguages + .map(locale => this.langForLocale(locale)) + .map(value => value === undefined ? '?' : value) } private computeIsUserHasAdminAccess () { -- cgit v1.2.3