diff options
Diffstat (limited to 'client/src/app/shared/video/video-thumbnail.component.ts')
-rw-r--r-- | client/src/app/shared/video/video-thumbnail.component.ts | 85 |
1 files changed, 16 insertions, 69 deletions
diff --git a/client/src/app/shared/video/video-thumbnail.component.ts b/client/src/app/shared/video/video-thumbnail.component.ts index 6f9292d52..2420ec715 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 @@ | |||
1 | import { Component, Input, OnInit, ChangeDetectorRef } from '@angular/core' | 1 | import { Component, EventEmitter, Input, Output } from '@angular/core' |
2 | import { Video } from './video.model' | 2 | import { Video } from './video.model' |
3 | import { ScreenService } from '@app/shared/misc/screen.service' | 3 | import { ScreenService } from '@app/shared/misc/screen.service' |
4 | import { AuthService, ThemeService } from '@app/core' | 4 | import { I18n } from '@ngx-translate/i18n-polyfill' |
5 | import { VideoPlaylistService } from '../video-playlist/video-playlist.service' | ||
6 | import { VideoPlaylistElementCreate } from '../../../../../shared' | ||
7 | 5 | ||
8 | @Component({ | 6 | @Component({ |
9 | selector: 'my-video-thumbnail', | 7 | selector: 'my-video-thumbnail', |
@@ -16,45 +14,20 @@ export class VideoThumbnailComponent { | |||
16 | @Input() routerLink: any[] | 14 | @Input() routerLink: any[] |
17 | @Input() queryParams: any[] | 15 | @Input() queryParams: any[] |
18 | 16 | ||
19 | addToWatchLaterText = 'Add to watch later' | 17 | @Input() displayWatchLaterPlaylist: boolean |
20 | addedToWatchLaterText = 'Added to watch later' | 18 | @Input() inWatchLaterPlaylist: boolean |
21 | addedToWatchLater: boolean | ||
22 | 19 | ||
23 | watchLaterPlaylist: any | 20 | @Output() watchLaterClick = new EventEmitter<boolean>() |
21 | |||
22 | addToWatchLaterText: string | ||
23 | addedToWatchLaterText: string | ||
24 | 24 | ||
25 | constructor ( | 25 | constructor ( |
26 | private screenService: ScreenService, | 26 | private screenService: ScreenService, |
27 | private authService: AuthService, | 27 | private i18n: I18n |
28 | private videoPlaylistService: VideoPlaylistService, | 28 | ) { |
29 | private cd: ChangeDetectorRef | 29 | this.addToWatchLaterText = this.i18n('Add to watch later') |
30 | ) {} | 30 | this.addedToWatchLaterText = this.i18n('Remove from watch later') |
31 | |||
32 | load () { | ||
33 | if (this.addedToWatchLater !== undefined) return | ||
34 | if (!this.isUserLoggedIn()) return | ||
35 | |||
36 | this.videoPlaylistService.doesVideoExistInPlaylist(this.video.id) | ||
37 | .subscribe( | ||
38 | existResult => { | ||
39 | for (const playlist of this.authService.getUser().specialPlaylists) { | ||
40 | const existingPlaylist = existResult[ this.video.id ].find(p => p.playlistId === playlist.id) | ||
41 | this.addedToWatchLater = !!existingPlaylist | ||
42 | |||
43 | if (existingPlaylist) { | ||
44 | this.watchLaterPlaylist = { | ||
45 | playlistId: existingPlaylist.playlistId, | ||
46 | playlistElementId: existingPlaylist.playlistElementId | ||
47 | } | ||
48 | } else { | ||
49 | this.watchLaterPlaylist = { | ||
50 | playlistId: playlist.id | ||
51 | } | ||
52 | } | ||
53 | |||
54 | this.cd.markForCheck() | ||
55 | } | ||
56 | } | ||
57 | ) | ||
58 | } | 31 | } |
59 | 32 | ||
60 | getImageUrl () { | 33 | getImageUrl () { |
@@ -81,36 +54,10 @@ export class VideoThumbnailComponent { | |||
81 | return [ '/videos/watch', this.video.uuid ] | 54 | return [ '/videos/watch', this.video.uuid ] |
82 | } | 55 | } |
83 | 56 | ||
84 | isUserLoggedIn () { | 57 | onWatchLaterClick (event: Event) { |
85 | return this.authService.isLoggedIn() | 58 | this.watchLaterClick.emit(this.inWatchLaterPlaylist) |
86 | } | ||
87 | |||
88 | addToWatchLater () { | ||
89 | if (this.addedToWatchLater === undefined) return | ||
90 | this.addedToWatchLater = true | ||
91 | |||
92 | this.videoPlaylistService.addVideoInPlaylist( | ||
93 | this.watchLaterPlaylist.playlistId, | ||
94 | { videoId: this.video.id } as VideoPlaylistElementCreate | ||
95 | ).subscribe( | ||
96 | res => { | ||
97 | this.addedToWatchLater = true | ||
98 | this.watchLaterPlaylist.playlistElementId = res.videoPlaylistElement.id | ||
99 | } | ||
100 | ) | ||
101 | } | ||
102 | |||
103 | removeFromWatchLater () { | ||
104 | if (this.addedToWatchLater === undefined) return | ||
105 | this.addedToWatchLater = false | ||
106 | 59 | ||
107 | this.videoPlaylistService.removeVideoFromPlaylist( | 60 | event.stopPropagation() |
108 | this.watchLaterPlaylist.playlistId, | 61 | return false |
109 | this.watchLaterPlaylist.playlistElementId | ||
110 | ).subscribe( | ||
111 | _ => { | ||
112 | this.addedToWatchLater = false | ||
113 | } | ||
114 | ) | ||
115 | } | 62 | } |
116 | } | 63 | } |