X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fmenu%2Fmenu.component.ts;h=97a3b6d24ea3081781a9f880c4b1c082d79b4035;hb=07098c33df3f5e00c2a150d3025abb779d0edb6c;hp=f9a0a9f571ec0e7e69676d0b3b343910158923dc;hpb=30d55e75cae1adec3fc43c84691975bf8b97db34;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts index f9a0a9f57..97a3b6d24 100644 --- a/client/src/app/menu/menu.component.ts +++ b/client/src/app/menu/menu.component.ts @@ -1,8 +1,10 @@ +import { ViewportScroller } from '@angular/common' import { HotkeysService } from 'angular2-hotkeys' import * as debug from 'debug' import { switchMap } from 'rxjs/operators' import { Component, OnInit, ViewChild } from '@angular/core' import { Router } from '@angular/router' +import { scrollToTop } from '@app/helpers' import { AuthService, AuthStatus, AuthUser, MenuService, RedirectService, ScreenService, ServerService, UserService } from '@app/core' import { LanguageChooserComponent } from '@app/menu/language-chooser.component' import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component' @@ -39,6 +41,7 @@ export class MenuComponent implements OnInit { } constructor ( + private viewportScroller: ViewportScroller, private authService: AuthService, private userService: UserService, private serverService: ServerService, @@ -61,6 +64,29 @@ export class MenuComponent implements OnInit { } } + get language () { + return this.languageChooserModal.getCurrentLanguage() + } + + get nsfwPolicy () { + if (!this.user) return + + switch (this.user.nsfwPolicy) { + case 'do_not_list': + return $localize`hide` + + case 'blur': + return $localize`blur` + + case 'display': + return $localize`display` + } + } + + get instanceName () { + return this.serverConfig.instance.name + } + ngOnInit () { this.serverConfig = this.serverService.getTmpConfig() this.serverService.getConfig() @@ -109,25 +135,6 @@ export class MenuComponent implements OnInit { }) } - get language () { - return this.languageChooserModal.getCurrentLanguage() - } - - get nsfwPolicy () { - if (!this.user) return - - switch (this.user.nsfwPolicy) { - case 'do_not_list': - return $localize`hide` - - case 'blur': - return $localize`blur` - - case 'display': - return $localize`display` - } - } - isRegistrationAllowed () { return this.serverConfig.signup.allowed && this.serverConfig.signup.allowedForCurrentIP @@ -195,23 +202,18 @@ export class MenuComponent implements OnInit { return this.languages.find(lang => lang.id === localeId).label } - onSameUrlRestoreScrollPosition (link: HTMLAnchorElement) { + onActiveLinkScrollToAnchor (link: HTMLAnchorElement) { const linkURL = link.getAttribute('href') const linkHash = link.getAttribute('fragment') // On same url without fragment restore top scroll position if (!linkHash && this.router.url.includes(linkURL)) { - window.scrollTo({ - left: 0, - top: 0, - behavior: 'smooth' - }) + scrollToTop('smooth') } // On same url with fragment restore anchor scroll position if (linkHash && this.router.url === linkURL) { - const anchor = document.getElementById(link.getAttribute('fragment')) - anchor.scrollIntoView({ behavior: 'smooth', inline: 'nearest' }) + this.viewportScroller.scrollToAnchor(linkHash) } if (this.screenService.isInSmallView()) {