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