]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Reset playlist add component when video changes
authorChocobozzz <me@florianbigard.com>
Fri, 17 May 2019 12:34:21 +0000 (14:34 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 17 May 2019 12:34:21 +0000 (14:34 +0200)
client/src/app/shared/video-playlist/video-add-to-playlist.component.ts
client/src/app/shared/video/video-actions-dropdown.component.ts
client/src/app/videos/+video-watch/video-watch.component.ts

index 7dcdf7a9eb44e1325626424daaa35d46ba53c412..be15f23529f276ea4661f5cbda38cc88be7125b1 100644 (file)
@@ -1,4 +1,4 @@
-import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'
 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
 import { AuthService, Notifier } from '@app/core'
 import { forkJoin } from 'rxjs'
@@ -22,7 +22,7 @@ type PlaylistSummary = {
   templateUrl: './video-add-to-playlist.component.html',
   changeDetection: ChangeDetectionStrategy.OnPush
 })
-export class VideoAddToPlaylistComponent extends FormReactive implements OnInit {
+export class VideoAddToPlaylistComponent extends FormReactive implements OnInit, OnChanges {
   @Input() video: Video
   @Input() currentVideoTimestamp: number
   @Input() lazyLoad = false
@@ -54,15 +54,33 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
   }
 
   ngOnInit () {
-    this.resetOptions(true)
-
     this.buildForm({
       displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME
     })
 
+    this.init()
+  }
+
+  ngOnChanges (simpleChanges: SimpleChanges) {
+    if (simpleChanges['video']) {
+      this.unload()
+    }
+  }
+
+  init () {
+    this.resetOptions(true)
+
     if (this.lazyLoad !== true) this.load()
   }
 
+  unload () {
+    this.videoPlaylists = []
+
+    this.init()
+
+    this.cd.markForCheck()
+  }
+
   load () {
     forkJoin([
       this.videoPlaylistService.listAccountPlaylists(this.user.account, '-updatedAt'),
index ee2f44f9e4f9e69ce8b8d6bfb85709f2a2088b65..df799499e371d13651f9d383f34345538cbbc529 100644 (file)
@@ -79,6 +79,11 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   ngOnChanges () {
+    if (this.loaded) {
+      this.loaded = false
+      this.playlistAdd.unload()
+    }
+
     this.buildActions()
   }
 
index b147b75b04e7ebed3484ec3c7dc2aeb462996de2..631504eab6141472bf3e4389a519731864a65063 100644 (file)
@@ -119,23 +119,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
       if (videoId) this.loadVideo(videoId)
     })
 
-    this.hotkeys = [
-      new Hotkey('shift+l', (event: KeyboardEvent): boolean => {
-        this.setLike()
-        return false
-      }, undefined, this.i18n('Like the video')),
-      new Hotkey('shift+d', (event: KeyboardEvent): boolean => {
-        this.setDislike()
-        return false
-      }, undefined, this.i18n('Dislike the video')),
-      new Hotkey('shift+s', (event: KeyboardEvent): boolean => {
-        this.subscribeButton.subscribed ?
-          this.subscribeButton.unsubscribe() :
-          this.subscribeButton.subscribe()
-        return false
-      }, undefined, this.i18n('Subscribe to the account'))
-    ]
-    if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
+    this.initHotkeys()
   }
 
   ngOnDestroy () {
@@ -565,4 +549,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
       this.player = undefined
     }
   }
+
+  private initHotkeys () {
+    this.hotkeys = [
+      new Hotkey('shift+l', (event: KeyboardEvent): boolean => {
+        this.setLike()
+        return false
+      }, undefined, this.i18n('Like the video')),
+      new Hotkey('shift+d', (event: KeyboardEvent): boolean => {
+        this.setDislike()
+        return false
+      }, undefined, this.i18n('Dislike the video')),
+      new Hotkey('shift+s', (event: KeyboardEvent): boolean => {
+        this.subscribeButton.subscribed ?
+          this.subscribeButton.unsubscribe() :
+          this.subscribeButton.subscribe()
+        return false
+      }, undefined, this.i18n('Subscribe to the account'))
+    ]
+    if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
+  }
 }