X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Fmenu.component.ts;h=be6e8af519f85c13b06c987524c905738753f6f2;hb=262f8ff63109c8a95d9d149c1951cffd4c8301ef;hp=c767f19b27186f957905802063127e747fd36e80;hpb=2989628b7913383b39ac34c7db8666a21f8e5037;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index c767f19b2..be6e8af51 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts @@ -8,7 +8,8 @@ import { AuthService, AuthStatus, AuthUser, - MenuLink, + HooksService, + MenuSection, MenuService, RedirectService, ScreenService, @@ -45,7 +46,7 @@ export class MenuComponent implements OnInit { currentInterfaceLanguage: string - commonMenuLinks: MenuLink[] = [] + menuSections: MenuSection[] = [] private languages: VideoConstant[] = [] @@ -71,7 +72,8 @@ export class MenuComponent implements OnInit { private screenService: ScreenService, private menuService: MenuService, private modalService: PeertubeModalService, - private router: Router + private router: Router, + private hooks: HooksService ) { } get isInMobileView () { @@ -88,46 +90,24 @@ export class MenuComponent implements OnInit { return this.languageChooserModal.getCurrentLanguage() } - get instanceName () { - return this.htmlServerConfig.instance.name - } - ngOnInit () { this.htmlServerConfig = this.serverService.getHTMLConfig() - this.buildMenuLinks() + this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage() this.isLoggedIn = this.authService.isLoggedIn() - if (this.isLoggedIn === true) { - this.user = this.authService.getUser() - - this.computeNSFWPolicy() - this.computeVideosLink() - } - - this.computeAdminAccess() - - this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage() + this.updateUserState() + this.buildMenuSections() this.authService.loginChangedSource.subscribe( status => { if (status === AuthStatus.LoggedIn) { this.isLoggedIn = true - this.user = this.authService.getUser() - - this.computeAdminAccess() - this.computeVideosLink() - - logger('Logged in.') } else if (status === AuthStatus.LoggedOut) { this.isLoggedIn = false - this.user = undefined - - this.computeAdminAccess() - - logger('Logged out.') - } else { - console.error('Unknown auth status: ' + status) } + + this.updateUserState() + this.buildMenuSections() } ) @@ -257,8 +237,20 @@ export class MenuComponent implements OnInit { } } - private buildMenuLinks () { - this.commonMenuLinks = this.menuService.buildCommonLinks(this.htmlServerConfig) + private async buildMenuSections () { + const menuSections = [] + + if (this.isLoggedIn) { + menuSections.push( + this.menuService.buildLibraryLinks(this.user?.canSeeVideosLink) + ) + } + + menuSections.push( + this.menuService.buildCommonLinks(this.htmlServerConfig) + ) + + this.menuSections = await this.hooks.wrapObject(menuSections, 'common', 'filter:left-menu.links.create.result') } private buildUserLanguages () { @@ -268,7 +260,7 @@ export class MenuComponent implements OnInit { } if (!this.user.videoLanguages) { - this.videoLanguages = [$localize`any language`] + this.videoLanguages = [ $localize`any language` ] return } @@ -284,6 +276,8 @@ export class MenuComponent implements OnInit { } private computeVideosLink () { + if (!this.isLoggedIn) return + this.authService.userInformationLoaded .pipe( switchMap(() => this.user.computeCanSeeVideosLink(this.userService.getMyVideoQuotaUsed())) @@ -313,4 +307,14 @@ export class MenuComponent implements OnInit { break } } + + private updateUserState () { + this.user = this.isLoggedIn + ? this.authService.getUser() + : undefined + + this.computeAdminAccess() + this.computeNSFWPolicy() + this.computeVideosLink() + } }