]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/hotkeys/hotkeys.component.ts
Move to sass module
[github/Chocobozzz/PeerTube.git] / client / src / app / core / hotkeys / hotkeys.component.ts
1 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2 import { Subscription } from 'rxjs'
3 import { Component, Input, OnDestroy, OnInit } from '@angular/core'
4
5 @Component({
6 selector : 'my-hotkeys-cheatsheet',
7 templateUrl : './hotkeys.component.html',
8 styleUrls: [ './hotkeys.component.scss' ]
9 })
10 export class CheatSheetComponent implements OnInit, OnDestroy {
11 @Input() title = $localize`Keyboard Shortcuts:`
12 helpVisible = false
13 subscription: Subscription
14
15 hotkeys: Hotkey[]
16
17 constructor (
18 private hotkeysService: HotkeysService
19 ) {}
20
21 public ngOnInit (): void {
22 this.subscription = this.hotkeysService.cheatSheetToggle.subscribe((isOpen) => {
23 if (isOpen !== false) {
24 this.hotkeys = this.hotkeysService.hotkeys.filter(hotkey => hotkey.description)
25 }
26
27 if (isOpen === false) {
28 this.helpVisible = false
29 } else {
30 this.toggleHelpVisible()
31 }
32 })
33 }
34
35 public ngOnDestroy (): void {
36 if (this.subscription) {
37 this.subscription.unsubscribe()
38 }
39 }
40
41 public toggleCheatSheet (): void {
42 this.hotkeysService.cheatSheetToggle.next(!this.helpVisible)
43 }
44
45 public toggleHelpVisible (): void {
46 this.helpVisible = !this.helpVisible
47 }
48 }