import * as debug from 'debug'
import { switchMap } from 'rxjs/operators'
import { Component, OnInit, ViewChild } from '@angular/core'
-import { AuthService, AuthStatus, AuthUser, RedirectService, ScreenService, ServerService, UserService } from '@app/core'
+import { Router } from '@angular/router'
+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'
import { ServerConfig, UserRight, VideoConstant } from '@shared/models'
private serverService: ServerService,
private redirectService: RedirectService,
private hotkeysService: HotkeysService,
- private screenService: ScreenService
- ) { }
+ private screenService: ScreenService,
+ private menuService: MenuService,
+ private router: Router
+ ) { }
get isInMobileView () {
return this.screenService.isInMobileView()
return this.languages.find(lang => lang.id === localeId).label
}
+ onSameUrlRestoreScrollPosition (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'
+ })
+ }
+
+ // 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' })
+ }
+
+ if (this.screenService.isInSmallView()) {
+ this.menuService.toggleMenu()
+ }
+ }
+
private buildUserLanguages () {
if (!this.user) {
this.videoLanguages = []