+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'
helpVisible = false
videoLanguages: string[] = []
+ nsfwPolicy: string
+
+ loggedInMorePlacement: string
+
+ currentInterfaceLanguage: string
private languages: VideoConstant<string>[] = []
private serverConfig: ServerConfig
}
constructor (
+ private viewportScroller: ViewportScroller,
private authService: AuthService,
private userService: UserService,
private serverService: ServerService,
private router: Router
) { }
- get isInMobileView () {
- return this.screenService.isInMobileView()
- }
-
- get placement () {
- if (this.isInMobileView) {
- return 'left-top auto'
- } else {
- return 'right-top auto'
- }
- }
-
- 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
}
this.isLoggedIn = this.authService.isLoggedIn()
if (this.isLoggedIn === true) {
this.user = this.authService.getUser()
+
+ this.computeNSFWPolicy()
this.computeVideosLink()
}
this.computeAdminAccess()
+ this.loggedInMorePlacement = this.screenService.isInMobileView()
+ ? 'left-top auto'
+ : 'right-top auto'
+
+ this.currentInterfaceLanguage = this.languageChooserModal.getCurrentLanguage()
+
this.authService.loginChangedSource.subscribe(
status => {
if (status === AuthStatus.LoggedIn) {
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()) {
else logger('User cannot see videos link.')
})
}
+
+ private computeNSFWPolicy () {
+ if (!this.user) {
+ this.nsfwPolicy = null
+ return
+ }
+
+ switch (this.user.nsfwPolicy) {
+ case 'do_not_list':
+ this.nsfwPolicy = $localize`hide`
+ break
+
+ case 'blur':
+ this.nsfwPolicy = $localize`blur`
+ break
+
+ case 'display':
+ this.nsfwPolicy = $localize`display`
+ break
+ }
+ }
}