X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo%2Fvideo-thumbnail.component.ts;h=111b4c8bbe57e3fde7f028bda6867a971e5f6322;hb=be27ef3b4682c5639039474c39ee0d234d16f482;hp=6f9292d52fd00355dc4783d6580415e58e9bc372;hpb=3fbba1d28a80b9e8bd97b422280a7465c5f7c89f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/video/video-thumbnail.component.ts b/client/src/app/shared/video/video-thumbnail.component.ts index 6f9292d52..111b4c8bb 100644 --- a/client/src/app/shared/video/video-thumbnail.component.ts +++ b/client/src/app/shared/video/video-thumbnail.component.ts @@ -1,9 +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 { VideoPlaylistElementCreate } from '../../../../../shared' +import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ selector: 'my-video-thumbnail', @@ -14,47 +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() + + addToWatchLaterText: string + addedToWatchLaterText: string constructor ( private screenService: ScreenService, - private authService: AuthService, - private videoPlaylistService: VideoPlaylistService, - private cd: ChangeDetectorRef - ) {} - - load () { - if (this.addedToWatchLater !== undefined) return - if (!this.isUserLoggedIn()) 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 () { @@ -81,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 } }