X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fmisc%2Ftop-menu-dropdown.component.ts;h=a8cc9b593fa9d263536eb7f0bac5afba676622a6;hb=21393652621efba8a95715c6f340515d58599ec6;hp=66f8f7e553720a34e6ddb502154b69c68b1ab714;hpb=ed5bb517266c80904c44bf44a335f1003f5aa277;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.ts b/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.ts index 66f8f7e55..a8cc9b593 100644 --- a/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.ts +++ b/client/src/app/shared/shared-main/misc/top-menu-dropdown.component.ts @@ -1,20 +1,23 @@ import { Subscription } from 'rxjs' -import { filter, take } from 'rxjs/operators' +import { filter } from 'rxjs/operators' import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core' import { NavigationEnd, Router } from '@angular/router' import { MenuService, ScreenService } from '@app/core' +import { scrollToTop } from '@app/helpers' import { GlobalIconName } from '@app/shared/shared-icons' import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap' export type TopMenuDropdownParam = { label: string routerLink?: string + isDisplayed?: () => boolean // Default: () => true children?: { label: string routerLink: string - iconName?: GlobalIconName + + isDisplayed?: () => boolean // Default: () => true }[] } @@ -51,6 +54,10 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { return this.screen.isInSmallView(marginLeft) } + get isBroadcastMessageDisplayed () { + return this.screen.isBroadcastMessageDisplayed + } + ngOnInit () { this.updateChildLabels(window.location.pathname) @@ -59,7 +66,7 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { .subscribe(() => this.updateChildLabels(window.location.pathname)) this.hasIcons = this.menuEntries.some( - e => e.children && e.children.some(c => !!c.iconName) + e => e.children?.some(c => !!c.iconName) ) } @@ -77,8 +84,9 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { this.modalService.open(this.modal, { centered: true, - beforeDismiss: async () => { + beforeDismiss: () => { this.onModalDismiss() + return true } }) @@ -88,10 +96,22 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { this.isModalOpened = false } + onActiveLinkScrollToTop (link: HTMLAnchorElement) { + if (!this.isBroadcastMessageDisplayed && this.router.url.includes(link.getAttribute('href'))) { + scrollToTop('smooth') + } + } + dismissOtherModals () { this.modalService.dismissAll() } + isDisplayed (obj: { isDisplayed?: () => boolean }) { + if (typeof obj.isDisplayed !== 'function') return true + + return obj.isDisplayed() + } + private updateChildLabels (path: string) { this.suffixLabels = {}