diff options
Diffstat (limited to 'client/src/app/videos')
-rw-r--r-- | client/src/app/videos/+video-watch/video-watch.component.ts | 69 |
1 files changed, 32 insertions, 37 deletions
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 55109dc32..2d13f1b58 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -6,7 +6,7 @@ import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | |||
6 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' | 6 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' |
7 | import { MetaService } from '@ngx-meta/core' | 7 | import { MetaService } from '@ngx-meta/core' |
8 | import { Notifier, ServerService } from '@app/core' | 8 | import { Notifier, ServerService } from '@app/core' |
9 | import { forkJoin, Subscription } from 'rxjs' | 9 | import { forkJoin, Observable, Subscription } from 'rxjs' |
10 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' | 10 | import { Hotkey, HotkeysService } from 'angular2-hotkeys' |
11 | import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared' | 11 | import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared' |
12 | import { AuthService, ConfirmService } from '../../core' | 12 | import { AuthService, ConfirmService } from '../../core' |
@@ -135,22 +135,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
135 | 135 | ||
136 | setLike () { | 136 | setLike () { |
137 | if (this.isUserLoggedIn() === false) return | 137 | if (this.isUserLoggedIn() === false) return |
138 | if (this.userRating === 'like') { | 138 | |
139 | // Already liked this video | 139 | // Already liked this video |
140 | this.setRating('none') | 140 | if (this.userRating === 'like') this.setRating('none') |
141 | } else { | 141 | else this.setRating('like') |
142 | this.setRating('like') | ||
143 | } | ||
144 | } | 142 | } |
145 | 143 | ||
146 | setDislike () { | 144 | setDislike () { |
147 | if (this.isUserLoggedIn() === false) return | 145 | if (this.isUserLoggedIn() === false) return |
148 | if (this.userRating === 'dislike') { | 146 | |
149 | // Already disliked this video | 147 | // Already disliked this video |
150 | this.setRating('none') | 148 | if (this.userRating === 'dislike') this.setRating('none') |
151 | } else { | 149 | else this.setRating('dislike') |
152 | this.setRating('dislike') | ||
153 | } | ||
154 | } | 150 | } |
155 | 151 | ||
156 | showMoreDescription () { | 152 | showMoreDescription () { |
@@ -249,12 +245,15 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
249 | ) | 245 | ) |
250 | .subscribe(([ video, captionsResult ]) => { | 246 | .subscribe(([ video, captionsResult ]) => { |
251 | const queryParams = this.route.snapshot.queryParams | 247 | const queryParams = this.route.snapshot.queryParams |
252 | const startTime = queryParams.start | ||
253 | const stopTime = queryParams.stop | ||
254 | const subtitle = queryParams.subtitle | ||
255 | const playerMode = queryParams.mode | ||
256 | 248 | ||
257 | this.onVideoFetched(video, captionsResult.data, { startTime, stopTime, subtitle, playerMode }) | 249 | const urlOptions = { |
250 | startTime: queryParams.start, | ||
251 | stopTime: queryParams.stop, | ||
252 | subtitle: queryParams.subtitle, | ||
253 | playerMode: queryParams.mode | ||
254 | } | ||
255 | |||
256 | this.onVideoFetched(video, captionsResult.data, urlOptions) | ||
258 | .catch(err => this.handleError(err)) | 257 | .catch(err => this.handleError(err)) |
259 | }) | 258 | }) |
260 | } | 259 | } |
@@ -279,6 +278,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
279 | private updateVideoDescription (description: string) { | 278 | private updateVideoDescription (description: string) { |
280 | this.video.description = description | 279 | this.video.description = description |
281 | this.setVideoDescriptionHTML() | 280 | this.setVideoDescriptionHTML() |
281 | .catch(err => console.error(err)) | ||
282 | } | 282 | } |
283 | 283 | ||
284 | private async setVideoDescriptionHTML () { | 284 | private async setVideoDescriptionHTML () { |
@@ -385,7 +385,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
385 | captions: videoCaptions.length !== 0, | 385 | captions: videoCaptions.length !== 0, |
386 | peertubeLink: false, | 386 | peertubeLink: false, |
387 | 387 | ||
388 | videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE ? this.videoService.getVideoViewUrl(this.video.uuid) : null, | 388 | videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE |
389 | ? this.videoService.getVideoViewUrl(this.video.uuid) | ||
390 | : null, | ||
389 | embedUrl: this.video.embedUrl, | 391 | embedUrl: this.video.embedUrl, |
390 | 392 | ||
391 | language: this.localeId, | 393 | language: this.localeId, |
@@ -466,20 +468,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
466 | } | 468 | } |
467 | 469 | ||
468 | private setRating (nextRating: UserVideoRateType) { | 470 | private setRating (nextRating: UserVideoRateType) { |
469 | let method | 471 | const ratingMethods: { [id in UserVideoRateType]: (id: number) => Observable<any> } = { |
470 | switch (nextRating) { | 472 | like: this.videoService.setVideoLike, |
471 | case 'like': | 473 | dislike: this.videoService.setVideoDislike, |
472 | method = this.videoService.setVideoLike | 474 | none: this.videoService.unsetVideoLike |
473 | break | ||
474 | case 'dislike': | ||
475 | method = this.videoService.setVideoDislike | ||
476 | break | ||
477 | case 'none': | ||
478 | method = this.videoService.unsetVideoLike | ||
479 | break | ||
480 | } | 475 | } |
481 | 476 | ||
482 | method.call(this.videoService, this.video.id) | 477 | ratingMethods[nextRating].call(this.videoService, this.video.id) |
483 | .subscribe( | 478 | .subscribe( |
484 | () => { | 479 | () => { |
485 | // Update the video like attribute | 480 | // Update the video like attribute |
@@ -556,18 +551,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
556 | 551 | ||
557 | private initHotkeys () { | 552 | private initHotkeys () { |
558 | this.hotkeys = [ | 553 | this.hotkeys = [ |
559 | new Hotkey('shift+l', (event: KeyboardEvent): boolean => { | 554 | new Hotkey('shift+l', () => { |
560 | this.setLike() | 555 | this.setLike() |
561 | return false | 556 | return false |
562 | }, undefined, this.i18n('Like the video')), | 557 | }, undefined, this.i18n('Like the video')), |
563 | new Hotkey('shift+d', (event: KeyboardEvent): boolean => { | 558 | |
559 | new Hotkey('shift+d', () => { | ||
564 | this.setDislike() | 560 | this.setDislike() |
565 | return false | 561 | return false |
566 | }, undefined, this.i18n('Dislike the video')), | 562 | }, undefined, this.i18n('Dislike the video')), |
567 | new Hotkey('shift+s', (event: KeyboardEvent): boolean => { | 563 | |
568 | this.subscribeButton.subscribed ? | 564 | new Hotkey('shift+s', () => { |
569 | this.subscribeButton.unsubscribe() : | 565 | this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe() |
570 | this.subscribeButton.subscribe() | ||
571 | return false | 566 | return false |
572 | }, undefined, this.i18n('Subscribe to the account')) | 567 | }, undefined, this.i18n('Subscribe to the account')) |
573 | ] | 568 | ] |