]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
Add video-playlist-element.created hook (#4196)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / channel-miniature-markup.component.ts
CommitLineData
61cbafc1 1import { map, switchMap } from 'rxjs/operators'
2539932e 2import { Component, Input, OnInit } from '@angular/core'
61cbafc1
C
3import { MarkdownService, UserService } from '@app/core'
4import { Video, VideoSortField } from '@shared/models/videos'
5import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main'
2539932e
C
6
7/*
8 * Markup component that creates a channel miniature only
9*/
10
11@Component({
12 selector: 'my-channel-miniature-markup',
13 templateUrl: 'channel-miniature-markup.component.html',
14 styleUrls: [ 'channel-miniature-markup.component.scss' ]
15})
16export class ChannelMiniatureMarkupComponent implements OnInit {
17 @Input() name: string
61cbafc1
C
18 @Input() displayLatestVideo: boolean
19 @Input() displayDescription: boolean
2539932e
C
20
21 channel: VideoChannel
61cbafc1
C
22 descriptionHTML: string
23 totalVideos: number
24 video: Video
2539932e
C
25
26 constructor (
61cbafc1
C
27 private markdown: MarkdownService,
28 private channelService: VideoChannelService,
29 private videoService: VideoService,
30 private userService: UserService
2539932e
C
31 ) { }
32
33 ngOnInit () {
34 this.channelService.getVideoChannel(this.name)
61cbafc1
C
35 .subscribe(async channel => {
36 this.channel = channel
37
38 this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description)
39
40 this.loadVideos()
41 })
42 }
43
44 getVideoChannelLink () {
45 return [ '/c', this.channel.nameWithHost ]
46 }
47
48 private loadVideos () {
49 const videoOptions = {
50 videoChannel: this.channel,
51 videoPagination: {
52 currentPage: 1,
53 itemsPerPage: 1
54 },
55 sort: '-publishedAt' as VideoSortField,
56 count: 1
57 }
58
59 this.userService.getAnonymousOrLoggedUser()
60 .pipe(
61 map(user => user.nsfwPolicy),
62 switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
63 )
64 .subscribe(({ total, data }) => {
65 this.totalVideos = total
66 this.video = data[0]
67 })
2539932e
C
68 }
69}