import { fromEvent, Observable, Subject, Subscription } from 'rxjs'
import { debounceTime, switchMap, tap } from 'rxjs/operators'
-import { Directive, OnDestroy, OnInit } from '@angular/core'
+import {
+ AfterContentInit,
+ ComponentFactoryResolver,
+ Directive,
+ Injector,
+ OnDestroy,
+ OnInit,
+ Type,
+ ViewChild,
+ ViewContainerRef
+} from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import {
AuthService,
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'
enum GroupDate {
UNKNOWN = 0,
@Directive()
// tslint:disable-next-line: directive-class-suffix
-export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook {
+export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterContentInit, DisableForReuseHook {
+ @ViewChild('videoListHeader', { static: true, read: ViewContainerRef }) videoListHeader: ViewContainerRef
+
+ HeaderComponent: Type<GenericHeaderComponent> = VideoListHeaderComponent
+ headerComponentInjector: Injector
+
pagination: ComponentPaginationLight = {
currentPage: 1,
itemsPerPage: 25
}
actions: {
- routerLink: string
iconName: GlobalIconName
label: string
+ justIcon?: boolean
+ routerLink?: string
+ href?: string
+ click?: (e: Event) => void
}[] = []
onDataSubject = new Subject<any[]>()
protected abstract screenService: ScreenService
protected abstract storageService: LocalStorageService
protected abstract router: Router
+ protected abstract cfr: ComponentFactoryResolver
abstract titlePage: string
private resizeSubscription: Subscription
if (this.resizeSubscription) this.resizeSubscription.unsubscribe()
}
+ ngAfterContentInit () {
+ if (this.videoListHeader) {
+ // some components don't use the header: they use their own template, like my-history.component.html
+ this.setHeader.apply(this, [ this.HeaderComponent, this.headerComponentInjector ])
+ }
+ }
+
disableForReuse () {
this.disabled = true
}
}
toggleModerationDisplay () {
- throw new Error('toggleModerationDisplay is not implemented')
+ throw new Error('toggleModerationDisplay ' + $localize`function is not implemented`)
+ }
+
+ setHeader (
+ t: Type<any> = this.HeaderComponent,
+ i: Injector = this.headerComponentInjector
+ ) {
+ const injector = i || Injector.create({
+ providers: [{
+ provide: 'data',
+ useValue: {
+ titlePage: this.titlePage,
+ titleTooltip: this.titleTooltip
+ }
+ }]
+ })
+ const viewContainerRef = this.videoListHeader
+ viewContainerRef.clear()
+
+ const componentFactory = this.cfr.resolveComponentFactory(t)
+ viewContainerRef.createComponent(componentFactory, 0, injector)
}
// On videos hook for children that want to do something