]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
keyboard shortcuts and key map view (#974)
authorRigel Kent <par@rigelk.eu>
Tue, 28 Aug 2018 07:32:03 +0000 (09:32 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 28 Aug 2018 07:32:03 +0000 (09:32 +0200)
client/package.json
client/src/app/app.component.html
client/src/app/app.component.ts
client/src/app/app.module.ts
client/yarn.lock

index 281fd0e950af9bc793ffd95ce3528ce532e6a538..4b24d5e31c5c5b5fc1d45b445675ed705d5efaa5 100644 (file)
@@ -62,6 +62,7 @@
     "@types/sanitize-html": "^1.14.0",
     "@types/video.js": "6.2.7",
     "@types/webtorrent": "^0.98.4",
+    "angular2-hotkeys": "^2.1.2",
     "angular2-notifications": "^1.0.2",
     "awesome-typescript-loader": "5.2.0",
     "bootstrap": "^4.1.3",
index 09b2c15be7225cbf9fae9ae6964a5ffe39ff7f24..697abec8e78847fdf79f5129ed15442ae338e7de 100644 (file)
@@ -1,5 +1,7 @@
 <div *ngIf="customCSS" [innerHTML]="customCSS"></div>
 
+<hotkeys-cheatsheet></hotkeys-cheatsheet>
+
 <div [ngClass]="{ 'user-logged-in': isUserLoggedIn(), 'user-not-logged-in': !isUserLoggedIn() }">
   <div class="header">
 
index 2149768a232accf60c28978cb10d24dcd1864907..a69f419be973cb01e0e43ae5d0c76f463bced168 100644 (file)
@@ -5,6 +5,7 @@ import { AuthService, RedirectService, ServerService } from '@app/core'
 import { is18nPath } from '../../../shared/models/i18n'
 import { ScreenService } from '@app/shared/misc/screen.service'
 import { skip } from 'rxjs/operators'
+import { HotkeysService, Hotkey } from 'angular2-hotkeys'
 
 @Component({
   selector: 'my-app',
@@ -35,7 +36,8 @@ export class AppComponent implements OnInit {
     private serverService: ServerService,
     private domSanitizer: DomSanitizer,
     private redirectService: RedirectService,
-    private screenService: ScreenService
+    private screenService: ScreenService,
+    private hotkeysService: HotkeysService
   ) { }
 
   get serverVersion () {
@@ -120,6 +122,33 @@ export class AppComponent implements OnInit {
             this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
           }
         })
+
+    this.hotkeysService.add([
+      new Hotkey('/', (event: KeyboardEvent): boolean => {
+        document.getElementById('search-video').focus()
+        return false // Prevent bubbling
+      }, undefined, 'Focus the search bar'),
+      new Hotkey('g+s', (event: KeyboardEvent): boolean => {
+        this.router.navigate([ '/videos/subscriptions' ])
+        return false
+      }, undefined, 'Go to the subscriptions videos page'),
+      new Hotkey('g+t', (event: KeyboardEvent): boolean => {
+        this.router.navigate([ '/videos/trending' ])
+        return false
+      }, undefined, 'Go to the trending videos page'),
+      new Hotkey('g+r', (event: KeyboardEvent): boolean => {
+        this.router.navigate([ '/videos/recently-added' ])
+        return false
+      }, undefined, 'Go to the recently added videos page'),
+      new Hotkey('g+l', (event: KeyboardEvent): boolean => {
+        this.router.navigate([ '/videos/local' ])
+        return false
+      }, undefined, 'Go to the local videos page'),
+      new Hotkey('g+u', (event: KeyboardEvent): boolean => {
+        this.router.navigate([ '/videos/upload' ])
+        return false
+      }, undefined, 'Go to the videos upload page')
+    ])
   }
 
   isUserLoggedIn () {
index 118831ed3ce34f5b1a6d62e91da109a96a0bac8a..b484a89e8a422d072c4bfd79909cad6b57993c94 100644 (file)
@@ -5,6 +5,7 @@ import { ResetPasswordModule } from '@app/reset-password'
 
 import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
 import { ClipboardModule } from 'ngx-clipboard'
+import { HotkeyModule, IHotkeyOptions } from 'angular2-hotkeys'
 
 import { AppRoutingModule } from './app-routing.module'
 import { AppComponent } from './app.component'
@@ -45,6 +46,9 @@ export function metaFactory (serverService: ServerService): MetaLoader {
     BrowserModule,
     // FIXME: https://github.com/maxisam/ngx-clipboard/issues/133
     ClipboardModule,
+    HotkeyModule.forRoot({
+      cheatSheetCloseEsc: true
+    } as IHotkeyOptions),
 
     CoreModule,
     SharedModule,
index 5d7ad7522cbed112d800c20fa5a54bc4e12a4104..c79ec3c2747afa706984c0bb3d8f81138e9e9d26 100644 (file)
   version "0.0.5"
   resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-0.0.5.tgz#5cdcbe08e81075d5dbf15466b311359b02a30c2b"
 
+"@types/mousetrap@^1.6.0":
+  version "1.6.0"
+  resolved "https://registry.yarnpkg.com/@types/mousetrap/-/mousetrap-1.6.0.tgz#c3951ab98b88ff6093cd0b1e4f8591af439141b8"
+
 "@types/node@*":
   version "10.5.4"
   resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.4.tgz#6eccc158504357d1da91434d75e86acde94bb10b"
@@ -766,6 +770,13 @@ amdefine@>=0.0.4:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
 
+angular2-hotkeys@^2.1.2:
+  version "2.1.2"
+  resolved "https://registry.yarnpkg.com/angular2-hotkeys/-/angular2-hotkeys-2.1.2.tgz#6693ecc2fbbf6f3874fb6715804e88ba6a584c0a"
+  dependencies:
+    "@types/mousetrap" "^1.6.0"
+    mousetrap "^1.6.0"
+
 angular2-notifications@^1.0.2:
   version "1.0.2"
   resolved "https://registry.yarnpkg.com/angular2-notifications/-/angular2-notifications-1.0.2.tgz#93b6c6838dc582c3838d46d03a21adc333056059"
@@ -4958,6 +4969,10 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
   dependencies:
     minimist "0.0.8"
 
+mousetrap@^1.6.0:
+  version "1.6.2"
+  resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.2.tgz#caadd9cf886db0986fb2fee59a82f6bd37527587"
+
 move-concurrently@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"