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