X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-custom-markup%2Fpeertube-custom-tags%2Fchannel-miniature-markup.component.ts;h=e9c466a904bd641e4682aeff5fe47efe4d865683;hb=ab4b8974997777373a6032073f9c1aaf33ba9931;hp=25deafb80ff120eac19fbfe8798599c445edf43f;hpb=8ee25e17b88b970703f4df9e74cb4726bbffd837;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts index 25deafb80..e9c466a90 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts @@ -1,5 +1,11 @@ -import { Component, Input, OnInit } from '@angular/core' -import { VideoChannel, VideoChannelService } from '../../shared-main' +import { from } from 'rxjs' +import { finalize, map, switchMap, tap } from 'rxjs/operators' +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' +import { MarkdownService, Notifier, UserService } from '@app/core' +import { FindInBulkService } from '@app/shared/shared-search' +import { VideoSortField } from '@shared/models' +import { Video, VideoChannel, VideoService } from '../../shared-main' +import { CustomMarkupComponent } from './shared' /* * Markup component that creates a channel miniature only @@ -10,17 +16,67 @@ import { VideoChannel, VideoChannelService } from '../../shared-main' templateUrl: 'channel-miniature-markup.component.html', styleUrls: [ 'channel-miniature-markup.component.scss' ] }) -export class ChannelMiniatureMarkupComponent implements OnInit { +export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, OnInit { @Input() name: string + @Input() displayLatestVideo: boolean + @Input() displayDescription: boolean + + @Output() loaded = new EventEmitter() channel: VideoChannel + descriptionHTML: string + totalVideos: number + video: Video constructor ( - private channelService: VideoChannelService + private markdown: MarkdownService, + private findInBulk: FindInBulkService, + private videoService: VideoService, + private userService: UserService, + private notifier: Notifier ) { } ngOnInit () { - this.channelService.getVideoChannel(this.name) - .subscribe(channel => this.channel = channel) + this.findInBulk.getChannel(this.name) + .pipe( + tap(channel => { + this.channel = channel + }), + switchMap(() => from(this.markdown.textMarkdownToHTML(this.channel.description))), + tap(html => { + this.descriptionHTML = html + }), + switchMap(() => this.loadVideosObservable()), + finalize(() => this.loaded.emit(true)) + ).subscribe({ + next: ({ total, data }) => { + this.totalVideos = total + this.video = data[0] + }, + + error: err => this.notifier.error($localize`Error in channel miniature component: ${err.message}`) + }) + } + + getVideoChannelLink () { + return [ '/c', this.channel.nameWithHost ] + } + + private loadVideosObservable () { + const videoOptions = { + videoChannel: this.channel, + videoPagination: { + currentPage: 1, + itemsPerPage: 1 + }, + sort: '-publishedAt' as VideoSortField, + count: 1 + } + + return this.userService.getAnonymousOrLoggedUser() + .pipe( + map(user => user.nsfwPolicy), + switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy })) + ) } }