Fix video playlist element removal
authorChocobozzz <me@florianbigard.com>
Thu, 22 Aug 2019 09:33:18 +0000 (11:33 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 22 Aug 2019 09:33:18 +0000 (11:33 +0200)
client/src/app/shared/video-playlist/video-add-to-playlist.component.ts
client/src/app/shared/video-playlist/video-playlist.service.ts

index 72de84703d1e99a83cd4ae6eb89c08484eb826fa..6380c2e512adf6fe3a7ef1f108a578b24cec69f2 100644 (file)
@@ -12,6 +12,7 @@ type PlaylistSummary = {
   inPlaylist: boolean
   displayName: string
 
+  playlistElementId?: number
   startTimestamp?: number
   stopTimestamp?: number
 }
@@ -37,8 +38,6 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
   }
   displayOptions = false
 
-  private playlistElementId: number
-
   constructor (
     protected formValidatorService: FormValidatorService,
     private authService: AuthService,
@@ -95,11 +94,10 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
               id: playlist.id,
               displayName: playlist.displayName,
               inPlaylist: !!existingPlaylist,
+              playlistElementId:  existingPlaylist ? existingPlaylist.playlistElementId : undefined,
               startTimestamp: existingPlaylist ? existingPlaylist.startTimestamp : undefined,
               stopTimestamp: existingPlaylist ? existingPlaylist.stopTimestamp : undefined
             })
-
-            this.playlistElementId = existingPlaylist ? existingPlaylist.playlistElementId : undefined
           }
 
           this.cd.markForCheck()
@@ -181,14 +179,15 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
   }
 
   private removeVideoFromPlaylist (playlist: PlaylistSummary) {
-    if (!this.playlistElementId) return
+    if (!playlist.playlistElementId) return
 
-    this.videoPlaylistService.removeVideoFromPlaylist(playlist.id, this.playlistElementId)
+    this.videoPlaylistService.removeVideoFromPlaylist(playlist.id, playlist.playlistElementId)
         .subscribe(
           () => {
             this.notifier.success(this.i18n('Video removed from {{name}}', { name: playlist.displayName }))
 
             playlist.inPlaylist = false
+            playlist.playlistElementId = undefined
           },
 
           err => {
@@ -209,8 +208,9 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit,
 
     this.videoPlaylistService.addVideoInPlaylist(playlist.id, body)
       .subscribe(
-        () => {
+        res => {
           playlist.inPlaylist = true
+          playlist.playlistElementId = res.videoPlaylistElement.id
 
           playlist.startTimestamp = body.startTimestamp
           playlist.stopTimestamp = body.stopTimestamp
index 376387082dfe2421d9c05e58bc48a1c864765279..42791af866fd282c6ea25f3c2594461d88d9bd7a 100644 (file)
@@ -113,11 +113,10 @@ export class VideoPlaylistService {
   }
 
   addVideoInPlaylist (playlistId: number, body: VideoPlaylistElementCreate) {
-    return this.authHttp.post(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos', body)
-               .pipe(
-                 map(this.restExtractor.extractDataBool),
-                 catchError(err => this.restExtractor.handleError(err))
-               )
+    const url = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos'
+
+    return this.authHttp.post<{ videoPlaylistElement: { id: number } }>(url, body)
+               .pipe(catchError(err => this.restExtractor.handleError(err)))
   }
 
   updateVideoOfPlaylist (playlistId: number, playlistElementId: number, body: VideoPlaylistElementUpdate) {