1
0
Fork 0

add like, dislike and subscribe button hotkeys

This commit is contained in:
Rigel Kent 2018-09-02 20:54:23 +02:00 committed by Chocobozzz
parent 9a2f7ea799
commit 20d2119904
5 changed files with 55 additions and 11 deletions

View File

@ -9,7 +9,7 @@
<div class="actor-display-name">{{ videoChannel.displayName }}</div> <div class="actor-display-name">{{ videoChannel.displayName }}</div>
<div class="actor-name">{{ videoChannel.nameWithHost }}</div> <div class="actor-name">{{ videoChannel.nameWithHost }}</div>
<my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="videoChannel"></my-subscribe-button> <my-subscribe-button #subscribeButton *ngIf="isUserLoggedIn()" [videoChannel]="videoChannel"></my-subscribe-button>
</div> </div>
<div i18n class="actor-followers">{{ videoChannel.followersCount }} subscribers</div> <div i18n class="actor-followers">{{ videoChannel.followersCount }} subscribers</div>

View File

@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute } from '@angular/router' import { ActivatedRoute } from '@angular/router'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
@ -6,13 +6,18 @@ import { RestExtractor } from '@app/shared'
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators' import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
import { Subscription } from 'rxjs' import { Subscription } from 'rxjs'
import { AuthService } from '@app/core' import { AuthService } from '@app/core'
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
@Component({ @Component({
templateUrl: './video-channels.component.html', templateUrl: './video-channels.component.html',
styleUrls: [ './video-channels.component.scss' ] styleUrls: [ './video-channels.component.scss' ]
}) })
export class VideoChannelsComponent implements OnInit, OnDestroy { export class VideoChannelsComponent implements OnInit, OnDestroy {
@ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
videoChannel: VideoChannel videoChannel: VideoChannel
hotkeys: Hotkey[]
private routeSub: Subscription private routeSub: Subscription
@ -20,7 +25,8 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
private route: ActivatedRoute, private route: ActivatedRoute,
private authService: AuthService, private authService: AuthService,
private videoChannelService: VideoChannelService, private videoChannelService: VideoChannelService,
private restExtractor: RestExtractor private restExtractor: RestExtractor,
private hotkeysService: HotkeysService
) { } ) { }
ngOnInit () { ngOnInit () {
@ -33,10 +39,22 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
) )
.subscribe(videoChannel => this.videoChannel = videoChannel) .subscribe(videoChannel => this.videoChannel = videoChannel)
this.hotkeys = [
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 () { ngOnDestroy () {
if (this.routeSub) this.routeSub.unsubscribe() if (this.routeSub) this.routeSub.unsubscribe()
// Unbind hotkeys
if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
} }
isUserLoggedIn () { isUserLoggedIn () {

View File

@ -128,27 +128,27 @@ export class AppComponent implements OnInit {
document.getElementById('search-video').focus() document.getElementById('search-video').focus()
return false // Prevent bubbling return false // Prevent bubbling
}, undefined, 'Focus the search bar'), }, undefined, 'Focus the search bar'),
new Hotkey('g+s', (event: KeyboardEvent): boolean => { new Hotkey('g s', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/subscriptions' ]) this.router.navigate([ '/videos/subscriptions' ])
return false return false
}, undefined, 'Go to the subscriptions videos page'), }, undefined, 'Go to the subscriptions videos page'),
new Hotkey('g+o', (event: KeyboardEvent): boolean => { new Hotkey('g o', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/overview' ]) this.router.navigate([ '/videos/overview' ])
return false return false
}, undefined, 'Go to the videos overview page'), }, undefined, 'Go to the videos overview page'),
new Hotkey('g+t', (event: KeyboardEvent): boolean => { new Hotkey('g t', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/trending' ]) this.router.navigate([ '/videos/trending' ])
return false return false
}, undefined, 'Go to the trending videos page'), }, undefined, 'Go to the trending videos page'),
new Hotkey('g+r', (event: KeyboardEvent): boolean => { new Hotkey('g r', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/recently-added' ]) this.router.navigate([ '/videos/recently-added' ])
return false return false
}, undefined, 'Go to the recently added videos page'), }, undefined, 'Go to the recently added videos page'),
new Hotkey('g+l', (event: KeyboardEvent): boolean => { new Hotkey('g l', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/local' ]) this.router.navigate([ '/videos/local' ])
return false return false
}, undefined, 'Go to the local videos page'), }, undefined, 'Go to the local videos page'),
new Hotkey('g+u', (event: KeyboardEvent): boolean => { new Hotkey('g u', (event: KeyboardEvent): boolean => {
this.router.navigate([ '/videos/upload' ]) this.router.navigate([ '/videos/upload' ])
return false return false
}, undefined, 'Go to the videos upload page') }, undefined, 'Go to the videos upload page')

View File

@ -125,7 +125,7 @@
<img [src]="video.videoChannelAvatarUrl" alt="Video channel avatar" /> <img [src]="video.videoChannelAvatarUrl" alt="Video channel avatar" />
</a> </a>
<my-subscribe-button *ngIf="isUserLoggedIn()" [videoChannel]="video.channel" size="small"></my-subscribe-button> <my-subscribe-button #subscribeButton *ngIf="isUserLoggedIn()" [videoChannel]="video.channel" size="small"></my-subscribe-button>
</div> </div>
<div class="video-info-by"> <div class="video-info-by">

View File

@ -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 { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router' import { ActivatedRoute, Router } from '@angular/router'
import { RedirectService } from '@app/core/routing/redirect.service' import { RedirectService } from '@app/core/routing/redirect.service'
@ -9,6 +9,7 @@ import { NotificationsService } from 'angular2-notifications'
import { forkJoin, Subscription } from 'rxjs' import { forkJoin, Subscription } from 'rxjs'
import * as videojs from 'video.js' import * as videojs from 'video.js'
import 'videojs-hotkeys' import 'videojs-hotkeys'
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
import * as WebTorrent from 'webtorrent' import * as WebTorrent from 'webtorrent'
import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoRateType, VideoState } from '../../../../../shared' import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoRateType, VideoState } from '../../../../../shared'
import '../../../assets/player/peertube-videojs-plugin' 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 { VideoReportComponent } from './modal/video-report.component'
import { VideoShareComponent } from './modal/video-share.component' import { VideoShareComponent } from './modal/video-share.component'
import { VideoBlacklistComponent } from './modal/video-blacklist.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 { addContextMenu, getVideojsOptions, loadLocaleInVideoJS } from '../../../assets/player/peertube-player'
import { ServerService } from '@app/core' import { ServerService } from '@app/core'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
@ -41,6 +43,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
@ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent @ViewChild('videoSupportModal') videoSupportModal: VideoSupportComponent
@ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent
@ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
player: videojs.Player player: videojs.Player
playerElement: HTMLVideoElement playerElement: HTMLVideoElement
@ -55,6 +58,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
likesBarTooltipText = '' likesBarTooltipText = ''
hasAlreadyAcceptedPrivacyConcern = false hasAlreadyAcceptedPrivacyConcern = false
remoteServerDown = false remoteServerDown = false
hotkeys: Hotkey[]
private videojsLocaleLoaded = false private videojsLocaleLoaded = false
private paramsSub: Subscription private paramsSub: Subscription
@ -77,6 +81,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
private redirectService: RedirectService, private redirectService: RedirectService,
private videoCaptionService: VideoCaptionService, private videoCaptionService: VideoCaptionService,
private i18n: I18n, private i18n: I18n,
private hotkeysService: HotkeysService,
@Inject(LOCALE_ID) private localeId: string @Inject(LOCALE_ID) private localeId: string
) {} ) {}
@ -115,6 +120,24 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
.catch(err => this.handleError(err)) .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 () { ngOnDestroy () {
@ -122,6 +145,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
// Unsubscribe subscriptions // Unsubscribe subscriptions
this.paramsSub.unsubscribe() this.paramsSub.unsubscribe()
// Unbind hotkeys
if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
} }
setLike () { setLike () {