]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/video-thumbnail.component.ts
Strict templates enabled
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-thumbnail.component.ts
index 0f605e425d849b7dd82f6fd4d96c4f618ab727c4..111b4c8bbe57e3fde7f028bda6867a971e5f6322 100644 (file)
@@ -1,14 +1,7 @@
-import { Component, Input, OnInit, ChangeDetectorRef } from '@angular/core'
+import { Component, EventEmitter, Input, Output } from '@angular/core'
 import { Video } from './video.model'
 import { ScreenService } from '@app/shared/misc/screen.service'
-import { AuthService, ThemeService } from '@app/core'
-import { VideoPlaylistService } from '../video-playlist/video-playlist.service'
-import { VideoPlaylistType } from '@shared/models'
-import { forkJoin } from 'rxjs'
-import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model'
-import { VideoPlaylist } from '../video-playlist/video-playlist.model'
-import { VideoPlaylistElementCreate } from '../../../../../shared'
-import { VideoExistInPlaylist } from '@shared/models/videos/playlist/video-exist-in-playlist.model'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-video-thumbnail',
@@ -19,46 +12,22 @@ export class VideoThumbnailComponent {
   @Input() video: Video
   @Input() nsfw = false
   @Input() routerLink: any[]
-  @Input() queryParams: any[]
+  @Input() queryParams: { [ p: string ]: any }
 
-  addToWatchLaterText = 'Add to watch later'
-  addedToWatchLaterText = 'Added to watch later'
-  addedToWatchLater: boolean
+  @Input() displayWatchLaterPlaylist: boolean
+  @Input() inWatchLaterPlaylist: boolean
 
-  watchLaterPlaylist: any
+  @Output() watchLaterClick = new EventEmitter<boolean>()
+
+  addToWatchLaterText: string
+  addedToWatchLaterText: string
 
   constructor (
     private screenService: ScreenService,
-    private authService: AuthService,
-    private videoPlaylistService: VideoPlaylistService,
-    private cd: ChangeDetectorRef
-  ) {}
-
-  load () {
-    if (this.addedToWatchLater !== undefined) return
-
-    this.videoPlaylistService.doesVideoExistInPlaylist(this.video.id)
-      .subscribe(
-        existResult => {
-          for (const playlist of this.authService.getUser().specialPlaylists) {
-            const existingPlaylist = existResult[ this.video.id ].find(p => p.playlistId === playlist.id)
-            this.addedToWatchLater = !!existingPlaylist
-
-            if (existingPlaylist) {
-              this.watchLaterPlaylist = {
-                playlistId: existingPlaylist.playlistId,
-                playlistElementId: existingPlaylist.playlistElementId
-              }
-            } else {
-              this.watchLaterPlaylist = {
-                playlistId: playlist.id
-              }
-            }
-
-            this.cd.markForCheck()
-          }
-        }
-      )
+    private i18n: I18n
+  ) {
+    this.addToWatchLaterText = this.i18n('Add to watch later')
+    this.addedToWatchLaterText = this.i18n('Remove from watch later')
   }
 
   getImageUrl () {
@@ -85,36 +54,10 @@ export class VideoThumbnailComponent {
     return [ '/videos/watch', this.video.uuid ]
   }
 
-  isUserLoggedIn () {
-    return this.authService.isLoggedIn()
-  }
-
-  addToWatchLater () {
-    if (this.addedToWatchLater === undefined) return
-    this.addedToWatchLater = true
-
-    this.videoPlaylistService.addVideoInPlaylist(
-      this.watchLaterPlaylist.playlistId,
-      { videoId: this.video.id } as VideoPlaylistElementCreate
-    ).subscribe(
-      res => {
-        this.addedToWatchLater = true
-        this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id
-      }
-    )
-  }
-
-  removeFromWatchLater () {
-    if (this.addedToWatchLater === undefined) return
-    this.addedToWatchLater = false
+  onWatchLaterClick (event: Event) {
+    this.watchLaterClick.emit(this.inWatchLaterPlaylist)
 
-    this.videoPlaylistService.removeVideoFromPlaylist(
-      this.watchLaterPlaylist.playlistId,
-      this.watchLaterPlaylist.playlistElementId
-    ).subscribe(
-      _ => {
-        this.addedToWatchLater = false
-      }
-    )
+    event.stopPropagation()
+    return false
   }
 }