aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos
diff options
context:
space:
mode:
authorBenjamin Bouvier <public@benj.me>2018-01-07 14:48:10 +0100
committerChocobozzz <me@florianbigard.com>2018-01-07 14:48:10 +0100
commit57a49263e48739c31cd339730ac4cb24e3d5d723 (patch)
tree520de9caa84113e704b39ae3b6f068a4fca7a66d /client/src/app/videos
parentcbca00dfc14fe47260e8d081f4ed0bec7c66fd09 (diff)
downloadPeerTube-57a49263e48739c31cd339730ac4cb24e3d5d723.tar.gz
PeerTube-57a49263e48739c31cd339730ac4cb24e3d5d723.tar.zst
PeerTube-57a49263e48739c31cd339730ac4cb24e3d5d723.zip
A few updates for the watch video view (#181)
* Fixes #156: Filter out the video being watched from the list of other videos of the same author; * Fixes #167: in the video view, hide the author's domain when it's from the current host; * Fixes #171: Allow undoing a like/dislike;
Diffstat (limited to 'client/src/app/videos')
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.html2
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.ts71
2 files changed, 44 insertions, 29 deletions
diff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.html
index 514a86e28..a5c387638 100644
--- a/client/src/app/videos/+video-watch/video-watch.component.html
+++ b/client/src/app/videos/+video-watch/video-watch.component.html
@@ -165,7 +165,7 @@
165 Other videos 165 Other videos
166 </div> 166 </div>
167 167
168 <div *ngFor="let video of otherVideos"> 168 <div *ngFor="let video of otherVideosDisplayed">
169 <my-video-miniature [video]="video" [user]="user"></my-video-miniature> 169 <my-video-miniature [video]="video" [user]="user"></my-video-miniature>
170 </div> 170 </div>
171 </div> 171 </div>
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts
index f1f194764..01e4bbf4a 100644
--- a/client/src/app/videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/videos/+video-watch/video-watch.component.ts
@@ -29,6 +29,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
29 @ViewChild('videoReportModal') videoReportModal: VideoReportComponent 29 @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
30 30
31 otherVideos: Video[] = [] 31 otherVideos: Video[] = []
32 otherVideosDisplayed: Video[] = []
32 33
33 error = false 34 error = false
34 loading = false 35 loading = false
@@ -69,8 +70,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
69 this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt') 70 this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
70 .subscribe( 71 .subscribe(
71 data => this.otherVideos = data.videos, 72 data => this.otherVideos = data.videos,
72 73 err => console.error(err)
73 err => console.error(err)
74 ) 74 )
75 75
76 this.paramsSub = this.route.params.subscribe(routeParams => { 76 this.paramsSub = this.route.params.subscribe(routeParams => {
@@ -102,36 +102,22 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
102 102
103 setLike () { 103 setLike () {
104 if (this.isUserLoggedIn() === false) return 104 if (this.isUserLoggedIn() === false) return
105 // Already liked this video 105 if (this.userRating === 'like') {
106 if (this.userRating === 'like') return 106 // Already liked this video
107 107 this.setRating('none')
108 this.videoService.setVideoLike(this.video.id) 108 } else {
109 .subscribe( 109 this.setRating('like')
110 () => { 110 }
111 // Update the video like attribute
112 this.updateVideoRating(this.userRating, 'like')
113 this.userRating = 'like'
114 },
115
116 err => this.notificationsService.error('Error', err.message)
117 )
118 } 111 }
119 112
120 setDislike () { 113 setDislike () {
121 if (this.isUserLoggedIn() === false) return 114 if (this.isUserLoggedIn() === false) return
122 // Already disliked this video 115 if (this.userRating === 'dislike') {
123 if (this.userRating === 'dislike') return 116 // Already disliked this video
124 117 this.setRating('none')
125 this.videoService.setVideoDislike(this.video.id) 118 } else {
126 .subscribe( 119 this.setRating('dislike')
127 () => { 120 }
128 // Update the video dislike attribute
129 this.updateVideoRating(this.userRating, 'dislike')
130 this.userRating = 'dislike'
131 },
132
133 err => this.notificationsService.error('Error', err.message)
134 )
135 } 121 }
136 122
137 blacklistVideo (event: Event) { 123 blacklistVideo (event: Event) {
@@ -303,6 +289,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
303 private onVideoFetched (video: VideoDetails) { 289 private onVideoFetched (video: VideoDetails) {
304 this.video = video 290 this.video = video
305 291
292 if (this.otherVideos.length > 0) {
293 this.otherVideosDisplayed = this.otherVideos.filter(v => v.uuid !== this.video.uuid)
294 }
295
306 let observable 296 let observable
307 if (this.video.isVideoNSFWForUser(this.user)) { 297 if (this.video.isVideoNSFWForUser(this.user)) {
308 observable = this.confirmService.confirm( 298 observable = this.confirmService.confirm(
@@ -366,6 +356,31 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
366 ) 356 )
367 } 357 }
368 358
359 private setRating (nextRating) {
360 let method
361 switch (nextRating) {
362 case 'like':
363 method = this.videoService.setVideoLike
364 break
365 case 'dislike':
366 method = this.videoService.setVideoDislike
367 break
368 case 'none':
369 method = this.videoService.unsetVideoLike
370 break
371 }
372
373 method.call(this.videoService, this.video.id)
374 .subscribe(
375 () => {
376 // Update the video like attribute
377 this.updateVideoRating(this.userRating, nextRating)
378 this.userRating = nextRating
379 },
380 err => this.notificationsService.error('Error', err.message)
381 )
382 }
383
369 private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) { 384 private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
370 let likesToIncrement = 0 385 let likesToIncrement = 0
371 let dislikesToIncrement = 0 386 let dislikesToIncrement = 0