-import { fromEvent, Observable, Subject, Subscription } from 'rxjs'
+import { fromEvent, Observable, ReplaySubject, Subject, Subscription } from 'rxjs'
import { debounceTime, switchMap, tap } from 'rxjs/operators'
import {
AfterContentInit,
ViewChild,
ViewContainerRef
} from '@angular/core'
-import { ActivatedRoute, Router } from '@angular/router'
+import { ActivatedRoute, Params, Router } from '@angular/router'
import {
AuthService,
ComponentPaginationLight,
import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
import { GlobalIconName } from '@app/shared/shared-icons'
import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@shared/core-utils/miscs/date'
-import { ServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/models'
+import { HTMLServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/models'
import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
import { Syndication, Video } from '../shared-main'
-import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component'
import { GenericHeaderComponent, VideoListHeaderComponent } from './video-list-header.component'
+import { MiniatureDisplayOptions } from './video-miniature.component'
enum GroupDate {
UNKNOWN = 0,
syndicationItems: Syndication[] = []
loadOnInit = true
- useUserVideoPreferences = false
- ownerDisplayType: OwnerDisplayType = 'account'
+ loadUserVideoPreferences = false
+
displayModerationBlock = false
titleTooltip: string
displayVideoActions = true
userMiniature: User
- protected serverConfig: ServerConfig
+ protected onUserLoadedSubject = new ReplaySubject<void>(1)
+
+ protected serverConfig: HTMLServerConfig
protected abstract notifier: Notifier
protected abstract authService: AuthService
abstract generateSyndicationList (): void
ngOnInit () {
- this.serverConfig = this.serverService.getTmpConfig()
- this.serverService.getConfig()
- .subscribe(config => this.serverConfig = config)
+ this.serverConfig = this.serverService.getHTMLConfig()
this.groupedDateLabels = {
[GroupDate.UNKNOWN]: null,
this.calcPageSizes()
const loadUserObservable = this.loadUserAndSettings()
+ loadUserObservable.subscribe(() => {
+ this.onUserLoadedSubject.next()
- if (this.loadOnInit === true) {
- loadUserObservable.subscribe(() => this.loadMoreVideos())
- }
+ if (this.loadOnInit === true) this.loadMoreVideos()
+ })
this.userService.listenAnonymousUpdate()
.pipe(switchMap(() => this.loadUserAndSettings()))
viewContainerRef.createComponent(componentFactory, 0, injector)
}
+ // Can be redefined by child
+ displayAsRow () {
+ return false
+ }
+
// On videos hook for children that want to do something
protected onMoreVideos () { /* empty */ }
- protected loadRouteParams (routeParams: { [ key: string ]: any }) {
- this.sort = routeParams[ 'sort' ] as VideoSortField || this.defaultSort
- this.categoryOneOf = routeParams[ 'categoryOneOf' ]
- this.angularState = routeParams[ 'a-state' ]
+ protected load () { /* empty */ }
+
+ // Hook if the page has custom route params
+ protected loadPageRouteParams (_queryParams: Params) { /* empty */ }
+
+ protected loadRouteParams (queryParams: Params) {
+ this.sort = queryParams[ 'sort' ] as VideoSortField || this.defaultSort
+ this.categoryOneOf = queryParams[ 'categoryOneOf' ]
+ this.angularState = queryParams[ 'a-state' ]
+
+ this.loadPageRouteParams(queryParams)
}
protected buildLocalFilter (existing: VideoFilter, base: VideoFilter) {
categoryOneOf: this.categoryOneOf
}
- let path = this.router.url
+ let path = this.getUrlWithoutParams()
if (!path || path === '/') path = this.serverConfig.instance.defaultClientRoute
this.router.navigate([ path ], { queryParams, replaceUrl: true, queryParamsHandling: 'merge' })
.pipe(tap(user => {
this.userMiniature = user
- if (!this.useUserVideoPreferences) return
+ if (!this.loadUserVideoPreferences) return
this.languageOneOf = user.videoLanguages
this.nsfwPolicy = user.nsfwPolicy
}))
}
+
+ private getUrlWithoutParams () {
+ const urlTree = this.router.parseUrl(this.router.url)
+ urlTree.queryParams = {}
+
+ return urlTree.toString()
+ }
}