From 61cbafc1f80a33a895b54b15751a42e0d78af231 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 Jun 2021 10:31:27 +0200 Subject: Improve channel card custom markup --- .../channel-miniature-markup.component.ts | 49 ++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts') 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..87caec8a5 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,8 @@ +import { map, switchMap } from 'rxjs/operators' import { Component, Input, OnInit } from '@angular/core' -import { VideoChannel, VideoChannelService } from '../../shared-main' +import { MarkdownService, UserService } from '@app/core' +import { Video, VideoSortField } from '@shared/models/videos' +import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main' /* * Markup component that creates a channel miniature only @@ -12,15 +15,55 @@ import { VideoChannel, VideoChannelService } from '../../shared-main' }) export class ChannelMiniatureMarkupComponent implements OnInit { @Input() name: string + @Input() displayLatestVideo: boolean + @Input() displayDescription: boolean channel: VideoChannel + descriptionHTML: string + totalVideos: number + video: Video constructor ( - private channelService: VideoChannelService + private markdown: MarkdownService, + private channelService: VideoChannelService, + private videoService: VideoService, + private userService: UserService ) { } ngOnInit () { this.channelService.getVideoChannel(this.name) - .subscribe(channel => this.channel = channel) + .subscribe(async channel => { + this.channel = channel + + this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description) + + this.loadVideos() + }) + } + + getVideoChannelLink () { + return [ '/c', this.channel.nameWithHost ] + } + + private loadVideos () { + const videoOptions = { + videoChannel: this.channel, + videoPagination: { + currentPage: 1, + itemsPerPage: 1 + }, + sort: '-publishedAt' as VideoSortField, + count: 1 + } + + this.userService.getAnonymousOrLoggedUser() + .pipe( + map(user => user.nsfwPolicy), + switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy })) + ) + .subscribe(({ total, data }) => { + this.totalVideos = total + this.video = data[0] + }) } } -- cgit v1.2.3