diff options
Diffstat (limited to 'client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts')
-rw-r--r-- | client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts | 39 |
1 files changed, 20 insertions, 19 deletions
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 a91debbef..7043a7ec9 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,6 +1,7 @@ | |||
1 | import { map, switchMap } from 'rxjs/operators' | 1 | import { from } from 'rxjs' |
2 | import { finalize, map, switchMap, tap } from 'rxjs/operators' | ||
2 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' | 3 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
3 | import { MarkdownService, UserService } from '@app/core' | 4 | import { MarkdownService, Notifier, UserService } from '@app/core' |
4 | import { Video, VideoSortField } from '@shared/models/videos' | 5 | import { Video, VideoSortField } from '@shared/models/videos' |
5 | import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main' | 6 | import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main' |
6 | import { CustomMarkupComponent } from './shared' | 7 | import { CustomMarkupComponent } from './shared' |
@@ -30,25 +31,33 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O | |||
30 | private markdown: MarkdownService, | 31 | private markdown: MarkdownService, |
31 | private channelService: VideoChannelService, | 32 | private channelService: VideoChannelService, |
32 | private videoService: VideoService, | 33 | private videoService: VideoService, |
33 | private userService: UserService | 34 | private userService: UserService, |
35 | private notifier: Notifier | ||
34 | ) { } | 36 | ) { } |
35 | 37 | ||
36 | ngOnInit () { | 38 | ngOnInit () { |
37 | this.channelService.getVideoChannel(this.name) | 39 | this.channelService.getVideoChannel(this.name) |
38 | .subscribe(async channel => { | 40 | .pipe( |
39 | this.channel = channel | 41 | tap(channel => this.channel = channel), |
40 | 42 | switchMap(() => from(this.markdown.textMarkdownToHTML(this.channel.description))), | |
41 | this.descriptionHTML = await this.markdown.textMarkdownToHTML(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 | }, | ||
42 | 51 | ||
43 | this.loadVideos() | 52 | err => this.notifier.error('Error in channel miniature component: ' + err.message) |
44 | }) | 53 | ) |
45 | } | 54 | } |
46 | 55 | ||
47 | getVideoChannelLink () { | 56 | getVideoChannelLink () { |
48 | return [ '/c', this.channel.nameWithHost ] | 57 | return [ '/c', this.channel.nameWithHost ] |
49 | } | 58 | } |
50 | 59 | ||
51 | private loadVideos () { | 60 | private loadVideosObservable () { |
52 | const videoOptions = { | 61 | const videoOptions = { |
53 | videoChannel: this.channel, | 62 | videoChannel: this.channel, |
54 | videoPagination: { | 63 | videoPagination: { |
@@ -59,18 +68,10 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O | |||
59 | count: 1 | 68 | count: 1 |
60 | } | 69 | } |
61 | 70 | ||
62 | this.userService.getAnonymousOrLoggedUser() | 71 | return this.userService.getAnonymousOrLoggedUser() |
63 | .pipe( | 72 | .pipe( |
64 | map(user => user.nsfwPolicy), | 73 | map(user => user.nsfwPolicy), |
65 | switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy })) | 74 | switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy })) |
66 | ) | 75 | ) |
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 | } |
76 | } | 77 | } |