-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'
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
}
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'),
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 () {
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)
+ }
}