]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-playlist / video-add-to-playlist.component.ts
index 5539305956394d2930aae4d19f845df6a869888f..e4972ec10ab7dd6376a20dfa2462f56e7d585b93 100644 (file)
@@ -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,
@@ -215,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) {
@@ -367,6 +370,8 @@ 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({
         next: res => {
@@ -379,9 +384,17 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
           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()
+        }
       })
   }