X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-video-playlist%2Fvideo-add-to-playlist.component.ts;h=e4972ec10ab7dd6376a20dfa2462f56e7d585b93;hb=64324ac646b0938e35cd88771492623b640bd0d8;hp=8b019103c2c41fa4949d596adff4d79b4d09ca9f;hpb=421ff4618da64f0849353383f690a014024c40da;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts index 8b019103c..e4972ec10 100644 --- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts +++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts @@ -47,7 +47,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, isNewPlaylistBlockOpened = false videoPlaylistSearch: string - videoPlaylistSearchChanged = new Subject() + videoPlaylistSearchChanged = new Subject() videoPlaylists: PlaylistSummary[] = [] @@ -56,6 +56,8 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, private listenToPlaylistChangeSub: Subscription private playlistsData: CachedPlaylist[] = [] + private pendingAddId: number + constructor ( protected formValidatorService: FormValidatorService, private authService: AuthService, @@ -191,22 +193,23 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, } createPlaylist () { - const displayName = this.form.value[ 'displayName' ] + const displayName = this.form.value['displayName'] const videoPlaylistCreate: VideoPlaylistCreate = { displayName, privacy: VideoPlaylistPrivacy.PRIVATE } - this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate).subscribe( - () => { - this.isNewPlaylistBlockOpened = false + this.videoPlaylistService.createVideoPlaylist(videoPlaylistCreate) + .subscribe({ + next: () => { + this.isNewPlaylistBlockOpened = false - this.cd.markForCheck() - }, + this.cd.markForCheck() + }, - err => this.notifier.error(err.message) - ) + error: err => this.notifier.error(err.message) + }) } onVideoPlaylistSearchChanged () { @@ -214,8 +217,9 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, } 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) { @@ -268,17 +272,15 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, } this.videoPlaylistService.updateVideoOfPlaylist(playlist.id, element.playlistElementId, body, this.video.id) - .subscribe( - () => { + .subscribe({ + next: () => { this.notifier.success($localize`Timestamps updated`) }, - err => { - this.notifier.error(err.message) - }, + error: err => this.notifier.error(err.message), - () => this.cd.markForCheck() - ) + complete: () => this.cd.markForCheck() + }) } private isOptionalRowDisplayed (playlist: PlaylistSummary) { @@ -302,17 +304,15 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, private removeVideoFromPlaylist (playlist: PlaylistSummary, elementId: number) { this.videoPlaylistService.removeVideoFromPlaylist(playlist.id, elementId, this.video.id) - .subscribe( - () => { + .subscribe({ + next: () => { this.notifier.success($localize`Video removed from ${playlist.displayName}`) }, - err => { - this.notifier.error(err.message) - }, + error: err => this.notifier.error(err.message), - () => this.cd.markForCheck() - ) + complete: () => this.cd.markForCheck() + }) } private listenToVideoPlaylistChange () { @@ -370,9 +370,11 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, 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( - res => { + .subscribe({ + next: res => { const message = body.startTimestamp || body.stopTimestamp ? $localize`Video added in ${playlist.displayName} at timestamps ${this.formatTimestamp(element)}` : $localize`Video added in ${playlist.displayName}` @@ -382,12 +384,18 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, if (element) element.playlistElementId = res.videoPlaylistElement.id }, - err => { + error: err => { + this.pendingAddId = undefined + this.cd.markForCheck() + this.notifier.error(err.message) }, - () => this.cd.markForCheck() - ) + complete: () => { + this.pendingAddId = undefined + this.cd.markForCheck() + } + }) } private formatTimestamp (element: PlaylistElement) {