Reduce latency when adding a video to playlist

This commit is contained in:
Chocobozzz 2022-02-22 11:41:44 +01:00
parent 4edee628a0
commit 89e3de8dc6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 17 additions and 4 deletions

View File

@ -56,6 +56,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
private listenToPlaylistChangeSub: Subscription private listenToPlaylistChangeSub: Subscription
private playlistsData: CachedPlaylist[] = [] private playlistsData: CachedPlaylist[] = []
private pendingAddId: number
constructor ( constructor (
protected formValidatorService: FormValidatorService, protected formValidatorService: FormValidatorService,
private authService: AuthService, private authService: AuthService,
@ -215,8 +217,9 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
} }
isPrimaryCheckboxChecked (playlist: PlaylistSummary) { isPrimaryCheckboxChecked (playlist: PlaylistSummary) {
return playlist.elements.filter(e => e.enabled) // Reduce latency when adding a video to a playlist using pendingAddId
.length !== 0 return this.pendingAddId === playlist.id ||
playlist.elements.filter(e => e.enabled).length !== 0
} }
toggleOptionalRow (playlist: PlaylistSummary) { toggleOptionalRow (playlist: PlaylistSummary) {
@ -367,6 +370,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
if (element.startTimestamp) body.startTimestamp = element.startTimestamp if (element.startTimestamp) body.startTimestamp = element.startTimestamp
if (element.stopTimestamp && element.stopTimestamp !== this.video.duration) body.stopTimestamp = element.stopTimestamp if (element.stopTimestamp && element.stopTimestamp !== this.video.duration) body.stopTimestamp = element.stopTimestamp
this.pendingAddId = playlist.id
this.videoPlaylistService.addVideoInPlaylist(playlist.id, body) this.videoPlaylistService.addVideoInPlaylist(playlist.id, body)
.subscribe({ .subscribe({
next: res => { next: res => {
@ -379,9 +384,17 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
if (element) element.playlistElementId = res.videoPlaylistElement.id if (element) element.playlistElementId = res.videoPlaylistElement.id
}, },
error: err => this.notifier.error(err.message), error: err => {
this.pendingAddId = undefined
this.cd.markForCheck()
complete: () => this.cd.markForCheck() this.notifier.error(err.message)
},
complete: () => {
this.pendingAddId = undefined
this.cd.markForCheck()
}
}) })
} }