Homepage error handling

This commit is contained in:
Chocobozzz 2021-07-01 17:28:47 +02:00
parent c171d85253
commit 8b61dcaf23
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 47 additions and 36 deletions

View File

@ -1,6 +1,7 @@
import { map, switchMap } from 'rxjs/operators' import { from } from 'rxjs'
import { finalize, map, switchMap, tap } from 'rxjs/operators'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { MarkdownService, UserService } from '@app/core' import { MarkdownService, Notifier, UserService } from '@app/core'
import { Video, VideoSortField } from '@shared/models/videos' import { Video, VideoSortField } from '@shared/models/videos'
import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main' import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main'
import { CustomMarkupComponent } from './shared' import { CustomMarkupComponent } from './shared'
@ -30,25 +31,33 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
private markdown: MarkdownService, private markdown: MarkdownService,
private channelService: VideoChannelService, private channelService: VideoChannelService,
private videoService: VideoService, private videoService: VideoService,
private userService: UserService private userService: UserService,
private notifier: Notifier
) { } ) { }
ngOnInit () { ngOnInit () {
this.channelService.getVideoChannel(this.name) this.channelService.getVideoChannel(this.name)
.subscribe(async channel => { .pipe(
this.channel = channel tap(channel => this.channel = channel),
switchMap(() => from(this.markdown.textMarkdownToHTML(this.channel.description))),
tap(html => this.descriptionHTML = html),
switchMap(() => this.loadVideosObservable()),
finalize(() => this.loaded.emit(true))
).subscribe(
({ total, data }) => {
this.totalVideos = total
this.video = data[0]
},
this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description) err => this.notifier.error('Error in channel miniature component: ' + err.message)
)
this.loadVideos()
})
} }
getVideoChannelLink () { getVideoChannelLink () {
return [ '/c', this.channel.nameWithHost ] return [ '/c', this.channel.nameWithHost ]
} }
private loadVideos () { private loadVideosObservable () {
const videoOptions = { const videoOptions = {
videoChannel: this.channel, videoChannel: this.channel,
videoPagination: { videoPagination: {
@ -59,18 +68,10 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
count: 1 count: 1
} }
this.userService.getAnonymousOrLoggedUser() return this.userService.getAnonymousOrLoggedUser()
.pipe( .pipe(
map(user => user.nsfwPolicy), map(user => user.nsfwPolicy),
switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy })) switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
) )
.subscribe({
next: ({ total, data }) => {
this.totalVideos = total
this.video = data[0]
},
complete: () => this.loaded.emit(true)
})
} }
} }

View File

@ -1,4 +1,6 @@
import { finalize } from 'rxjs/operators'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { Notifier } from '@app/core'
import { MiniatureDisplayOptions } from '../../shared-video-miniature' import { MiniatureDisplayOptions } from '../../shared-video-miniature'
import { VideoPlaylist, VideoPlaylistService } from '../../shared-video-playlist' import { VideoPlaylist, VideoPlaylistService } from '../../shared-video-playlist'
import { CustomMarkupComponent } from './shared' import { CustomMarkupComponent } from './shared'
@ -31,15 +33,17 @@ export class PlaylistMiniatureMarkupComponent implements CustomMarkupComponent,
} }
constructor ( constructor (
private playlistService: VideoPlaylistService private playlistService: VideoPlaylistService,
private notifier: Notifier
) { } ) { }
ngOnInit () { ngOnInit () {
this.playlistService.getVideoPlaylist(this.uuid) this.playlistService.getVideoPlaylist(this.uuid)
.subscribe({ .pipe(finalize(() => this.loaded.emit(true)))
next: playlist => this.playlist = playlist, .subscribe(
playlist => this.playlist = playlist,
complete: () => this.loaded.emit(true) err => this.notifier.error('Error in playlist miniature component: ' + err.message)
}) )
} }
} }

View File

@ -1,5 +1,6 @@
import { finalize } from 'rxjs/operators'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { AuthService } from '@app/core' import { AuthService, Notifier } from '@app/core'
import { Video, VideoService } from '../../shared-main' import { Video, VideoService } from '../../shared-main'
import { MiniatureDisplayOptions } from '../../shared-video-miniature' import { MiniatureDisplayOptions } from '../../shared-video-miniature'
import { CustomMarkupComponent } from './shared' import { CustomMarkupComponent } from './shared'
@ -34,7 +35,8 @@ export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnI
constructor ( constructor (
private auth: AuthService, private auth: AuthService,
private videoService: VideoService private videoService: VideoService,
private notifier: Notifier
) { } ) { }
getUser () { getUser () {
@ -49,10 +51,11 @@ export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnI
} }
this.videoService.getVideo({ videoId: this.uuid }) this.videoService.getVideo({ videoId: this.uuid })
.subscribe({ .pipe(finalize(() => this.loaded.emit(true)))
next: video => this.video = video, .subscribe(
video => this.video = video,
complete: () => this.loaded.emit(true) err => this.notifier.error('Error in video miniature component: ' + err.message)
}) )
} }
} }

View File

@ -1,5 +1,6 @@
import { finalize } from 'rxjs/operators'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { AuthService } from '@app/core' import { AuthService, Notifier } from '@app/core'
import { VideoFilter, VideoSortField } from '@shared/models' import { VideoFilter, VideoSortField } from '@shared/models'
import { Video, VideoService } from '../../shared-main' import { Video, VideoService } from '../../shared-main'
import { MiniatureDisplayOptions } from '../../shared-video-miniature' import { MiniatureDisplayOptions } from '../../shared-video-miniature'
@ -40,7 +41,8 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
constructor ( constructor (
private auth: AuthService, private auth: AuthService,
private videoService: VideoService private videoService: VideoService,
private notifier: Notifier
) { } ) { }
getUser () { getUser () {
@ -76,10 +78,11 @@ export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit
} }
this.videoService.getVideos(options) this.videoService.getVideos(options)
.subscribe({ .pipe(finalize(() => this.loaded.emit(true)))
next: ({ data }) => this.videos = data, .subscribe(
({ data }) => this.videos = data,
complete: () => this.loaded.emit(true) err => this.notifier.error('Error in videos list component: ' + err.message)
}) )
} }
} }