From 20d211990425af8d9bb5c8eba204d2b485bcd19a Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 2 Sep 2018 20:54:23 +0200 Subject: add like, dislike and subscribe button hotkeys --- .../videos/+video-watch/video-watch.component.html | 2 +- .../videos/+video-watch/video-watch.component.ts | 28 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'client/src/app/videos/+video-watch') 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 7dbc96bf4..0f2f3cf11 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html @@ -125,7 +125,7 @@ Video channel avatar - +
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 25643cfde..768a08d42 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -1,4 +1,4 @@ -import { catchError } from 'rxjs/operators' +import { catchError, subscribeOn } from 'rxjs/operators' import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { RedirectService } from '@app/core/routing/redirect.service' @@ -9,6 +9,7 @@ import { NotificationsService } from 'angular2-notifications' import { forkJoin, Subscription } from 'rxjs' import * as videojs from 'video.js' import 'videojs-hotkeys' +import { Hotkey, HotkeysService } from 'angular2-hotkeys' import * as WebTorrent from 'webtorrent' import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoRateType, VideoState } from '../../../../../shared' import '../../../assets/player/peertube-videojs-plugin' @@ -21,6 +22,7 @@ import { VideoDownloadComponent } from './modal/video-download.component' import { VideoReportComponent } from './modal/video-report.component' import { VideoShareComponent } from './modal/video-share.component' import { VideoBlacklistComponent } from './modal/video-blacklist.component' +import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component' import { addContextMenu, getVideojsOptions, loadLocaleInVideoJS } from '../../../assets/player/peertube-player' import { ServerService } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -41,6 +43,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { @ViewChild('videoReportModal') videoReportModal: VideoReportComponent @ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent + @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent player: videojs.Player playerElement: HTMLVideoElement @@ -55,6 +58,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { likesBarTooltipText = '' hasAlreadyAcceptedPrivacyConcern = false remoteServerDown = false + hotkeys: Hotkey[] private videojsLocaleLoaded = false private paramsSub: Subscription @@ -77,6 +81,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private redirectService: RedirectService, private videoCaptionService: VideoCaptionService, private i18n: I18n, + private hotkeysService: HotkeysService, @Inject(LOCALE_ID) private localeId: string ) {} @@ -115,6 +120,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy { .catch(err => this.handleError(err)) }) }) + + this.hotkeys = [ + new Hotkey('L', (event: KeyboardEvent): boolean => { + this.setLike() + return false + }, undefined, 'Like the video'), + new Hotkey('D', (event: KeyboardEvent): boolean => { + this.setDislike() + return false + }, undefined, 'Dislike the video'), + new Hotkey('S', (event: KeyboardEvent): boolean => { + this.subscribeButton.subscribed ? + this.subscribeButton.unsubscribe() : + this.subscribeButton.subscribe() + return false + }, undefined, 'Subscribe to the account') + ] + if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys) } ngOnDestroy () { @@ -122,6 +145,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { // Unsubscribe subscriptions this.paramsSub.unsubscribe() + + // Unbind hotkeys + if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys) } setLike () { -- cgit v1.2.3