From 9ca0f688e9e8558233f1a538b96a43da44e35353 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Aug 2022 10:39:40 +0200 Subject: Add channel hooks --- .../video-channel-playlists.component.ts | 36 ++++++++++++++-------- .../video-channel-videos.component.html | 2 ++ .../video-channel-videos.component.ts | 21 ++++++++++--- 3 files changed, 41 insertions(+), 18 deletions(-) (limited to 'client/src/app/+video-channels') diff --git a/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts b/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts index 14465bb8d..82af65026 100644 --- a/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts +++ b/client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts @@ -1,6 +1,6 @@ import { Subject, Subscription } from 'rxjs' -import { Component, OnDestroy, OnInit } from '@angular/core' -import { ComponentPagination, hasMoreItems, ScreenService } from '@app/core' +import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core' +import { ComponentPagination, hasMoreItems, HooksService, ScreenService } from '@app/core' import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' @@ -9,7 +9,7 @@ import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-pl templateUrl: './video-channel-playlists.component.html', styleUrls: [ './video-channel-playlists.component.scss' ] }) -export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy { +export class VideoChannelPlaylistsComponent implements OnInit, AfterViewInit, OnDestroy { videoPlaylists: VideoPlaylist[] = [] pagination: ComponentPagination = { @@ -26,16 +26,24 @@ export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy { constructor ( private videoPlaylistService: VideoPlaylistService, private videoChannelService: VideoChannelService, - private screenService: ScreenService + private screenService: ScreenService, + private hooks: HooksService ) {} ngOnInit () { // Parent get the video channel for us this.videoChannelSub = this.videoChannelService.videoChannelLoaded - .subscribe(videoChannel => { - this.videoChannel = videoChannel - this.loadVideoPlaylists() - }) + .subscribe(videoChannel => { + this.videoChannel = videoChannel + + this.hooks.runAction('action:video-channel-playlists.video-channel.loaded', 'video-channel', { videoChannel }) + + this.loadVideoPlaylists() + }) + } + + ngAfterViewInit () { + this.hooks.runAction('action:video-channel-playlists.init', 'video-channel') } ngOnDestroy () { @@ -55,11 +63,13 @@ export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy { private loadVideoPlaylists () { this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination) - .subscribe(res => { - this.videoPlaylists = this.videoPlaylists.concat(res.data) - this.pagination.totalItems = res.total + .subscribe(res => { + this.videoPlaylists = this.videoPlaylists.concat(res.data) + this.pagination.totalItems = res.total + + this.hooks.runAction('action:video-channel-playlists.playlists.loaded', 'video-channel', { playlists: this.videoPlaylists }) - this.onDataSubject.next(res.data) - }) + this.onDataSubject.next(res.data) + }) } } diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html index 0a6c5fcb2..9e9e98c99 100644 --- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html +++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.html @@ -19,5 +19,7 @@ [loadUserVideoPreferences]="true" [disabled]="disabled" + + (videosLoaded)="onVideosLoaded($event)" > diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts index 43fce475d..5e3946bf5 100644 --- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts +++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts @@ -1,16 +1,16 @@ import { Subscription } from 'rxjs' import { first } from 'rxjs/operators' -import { Component, OnDestroy, OnInit } from '@angular/core' -import { ComponentPaginationLight, DisableForReuseHook, ScreenService } from '@app/core' +import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core' +import { ComponentPaginationLight, DisableForReuseHook, HooksService, ScreenService } from '@app/core' import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature' -import { VideoSortField } from '@shared/models/videos' +import { Video, VideoSortField } from '@shared/models' @Component({ selector: 'my-video-channel-videos', templateUrl: './video-channel-videos.component.html' }) -export class VideoChannelVideosComponent implements OnInit, OnDestroy, DisableForReuseHook { +export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDestroy, DisableForReuseHook { getVideosObservableFunction = this.getVideosObservable.bind(this) getSyndicationItemsFunction = this.getSyndicationItems.bind(this) @@ -36,7 +36,8 @@ export class VideoChannelVideosComponent implements OnInit, OnDestroy, DisableFo constructor ( private screenService: ScreenService, private videoChannelService: VideoChannelService, - private videoService: VideoService + private videoService: VideoService, + private hooks: HooksService ) { } @@ -45,9 +46,15 @@ export class VideoChannelVideosComponent implements OnInit, OnDestroy, DisableFo this.videoChannelService.videoChannelLoaded.pipe(first()) .subscribe(videoChannel => { this.videoChannel = videoChannel + + this.hooks.runAction('action:video-channel-videos.video-channel.loaded', 'video-channel', { videoChannel }) }) } + ngAfterViewInit () { + this.hooks.runAction('action:video-channel-videos.init', 'video-channel') + } + ngOnDestroy () { if (this.videoChannelSub) this.videoChannelSub.unsubscribe() } @@ -79,4 +86,8 @@ export class VideoChannelVideosComponent implements OnInit, OnDestroy, DisableFo enabledForReuse () { this.disabled = false } + + onVideosLoaded (videos: Video[]) { + this.hooks.runAction('action:video-channel-videos.videos.loaded', 'video-channel', { videos }) + } } -- cgit v1.2.3