private listenToPlaylistChangeSub: Subscription
private playlistsData: CachedPlaylist[] = []
+ private pendingAddId: number
+
constructor (
protected formValidatorService: FormValidatorService,
private authService: AuthService,
}
createPlaylist () {
- const displayName = this.form.value[ 'displayName' ]
+ const displayName = this.form.value['displayName']
const videoPlaylistCreate: VideoPlaylistCreate = {
displayName,
}
isPrimaryCheckboxChecked (playlist: PlaylistSummary) {
- return playlist.elements.filter(e => e.enabled)
- .length !== 0
+ // Reduce latency when adding a video to a playlist using pendingAddId
+ return this.pendingAddId === playlist.id ||
+ playlist.elements.filter(e => e.enabled).length !== 0
}
toggleOptionalRow (playlist: PlaylistSummary) {
if (element.startTimestamp) body.startTimestamp = element.startTimestamp
if (element.stopTimestamp && element.stopTimestamp !== this.video.duration) body.stopTimestamp = element.stopTimestamp
+ this.pendingAddId = playlist.id
+
this.videoPlaylistService.addVideoInPlaylist(playlist.id, body)
.subscribe({
next: res => {
if (element) element.playlistElementId = res.videoPlaylistElement.id
},
- error: err => this.notifier.error(err.message),
+ error: err => {
+ this.pendingAddId = undefined
+ this.cd.markForCheck()
+
+ this.notifier.error(err.message)
+ },
- complete: () => this.cd.markForCheck()
+ complete: () => {
+ this.pendingAddId = undefined
+ this.cd.markForCheck()
+ }
})
}