added column selection hotkeys

This commit is contained in:
Nicolas Constant 2019-09-28 00:32:55 -04:00
parent 68367a783a
commit 28ca6d7fa0
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 72 additions and 8 deletions

21
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "sengi", "name": "sengi",
"version": "0.15.0", "version": "0.16.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -857,6 +857,11 @@
"@types/jasmine": "*" "@types/jasmine": "*"
} }
}, },
"@types/mousetrap": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/@types/mousetrap/-/mousetrap-1.6.3.tgz",
"integrity": "sha512-13gmo3M2qVvjQrWNseqM3+cR6S2Ss3grbR2NZltgMq94wOwqJYQdgn8qzwDshzgXqMlSUtyPZjysImmktu22ew=="
},
"@types/node": { "@types/node": {
"version": "8.9.5", "version": "8.9.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.5.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.5.tgz",
@ -1189,6 +1194,15 @@
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
"dev": true "dev": true
}, },
"angular2-hotkeys": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/angular2-hotkeys/-/angular2-hotkeys-2.1.5.tgz",
"integrity": "sha512-HiAnK1pW7lns5LpxtRsdkRRb5iVa7fv8Cf69Jye6l9gI6/IyvaVDptRtsWmdIG7VAr2Ngz6Yeehkym39O/LdgA==",
"requires": {
"@types/mousetrap": "^1.6.0",
"mousetrap": "^1.6.0"
}
},
"ansi-align": { "ansi-align": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-2.0.0.tgz",
@ -8105,6 +8119,11 @@
} }
} }
}, },
"mousetrap": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.3.tgz",
"integrity": "sha512-bd+nzwhhs9ifsUrC2tWaSgm24/oo2c83zaRyZQF06hYA6sANfsXHtnZ19AbbbDXCDzeH5nZBSQ4NvCjgD62tJA=="
},
"move-concurrently": { "move-concurrently": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",

View File

@ -45,6 +45,7 @@
"@fortawesome/free-solid-svg-icons": "^5.7.0", "@fortawesome/free-solid-svg-icons": "^5.7.0",
"@ngxs/storage-plugin": "^3.2.0", "@ngxs/storage-plugin": "^3.2.0",
"@ngxs/store": "^3.2.0", "@ngxs/store": "^3.2.0",
"angular2-hotkeys": "^2.1.5",
"bootstrap": "^4.1.3", "bootstrap": "^4.1.3",
"core-js": "^2.5.4", "core-js": "^2.5.4",
"emojione": "~4.5.0", "emojione": "~4.5.0",

View File

@ -16,6 +16,7 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { ContextMenuModule } from 'ngx-contextmenu'; import { ContextMenuModule } from 'ngx-contextmenu';
import { PickerModule } from '@ctrl/ngx-emoji-mart'; import { PickerModule } from '@ctrl/ngx-emoji-mart';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime'; import { OwlDateTimeModule, OwlNativeDateTimeModule } from 'ng-pick-datetime';
import { HotkeyModule } from 'angular2-hotkeys';
import { AppComponent } from "./app.component"; import { AppComponent } from "./app.component";
import { LeftSideBarComponent } from "./components/left-side-bar/left-side-bar.component"; import { LeftSideBarComponent } from "./components/left-side-bar/left-side-bar.component";
@ -159,7 +160,8 @@ const routes: Routes = [
SettingsState SettingsState
]), ]),
NgxsStoragePluginModule.forRoot(), NgxsStoragePluginModule.forRoot(),
ContextMenuModule.forRoot() ContextMenuModule.forRoot(),
HotkeyModule.forRoot()
], ],
providers: [AuthService, NavigationService, NotificationService, MastodonService, StreamingService], providers: [AuthService, NavigationService, NotificationService, MastodonService, StreamingService],
bootstrap: [AppComponent], bootstrap: [AppComponent],

View File

@ -1,5 +1,7 @@
<div class="streams-selection-footer"> <div class="streams-selection-footer">
<a class="stream-selection" *ngFor="let str of streams; let i=index" href (click)="onColumnSelection(i)" title="open {{getDisplayableName(str)}}"> <a class="stream-selection" *ngFor="let str of streams; let i=index" href (click)="onColumnSelection(i)"
<span class="stream-selection__column-reprensentation" [class.stream-selection__column-reprensentation--selected]="str.isSelected"></span> title="open {{getDisplayableName(str.stream)}}">
</a> <span class="stream-selection__column-reprensentation"
[class.stream-selection__column-reprensentation--selected]="str.isSelected"></span>
</a>
</div> </div>

View File

@ -1,7 +1,9 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { StreamElement, StreamTypeEnum } from '../../states/streams.state';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { HotkeysService, Hotkey } from 'angular2-hotkeys';
import { StreamElement, StreamTypeEnum } from '../../states/streams.state';
import { NavigationService } from '../../services/navigation.service'; import { NavigationService } from '../../services/navigation.service';
@Component({ @Component({
@ -14,9 +16,20 @@ export class StreamsSelectionFooterComponent implements OnInit {
private streams$: Observable<StreamElement[]>; private streams$: Observable<StreamElement[]>;
constructor( constructor(
private readonly hotkeysService: HotkeysService,
private readonly navigationService: NavigationService, private readonly navigationService: NavigationService,
private readonly store: Store) { private readonly store: Store) {
this.streams$ = this.store.select(state => state.streamsstatemodel.streams); this.streams$ = this.store.select(state => state.streamsstatemodel.streams);
this.hotkeysService.add(new Hotkey('ctrl+right', (event: KeyboardEvent): boolean => {
this.nextColumnSelected();
return false;
}));
this.hotkeysService.add(new Hotkey('ctrl+left', (event: KeyboardEvent): boolean => {
this.previousColumnSelected();
return false;
}));
} }
ngOnInit() { ngOnInit() {
@ -25,6 +38,33 @@ export class StreamsSelectionFooterComponent implements OnInit {
}); });
} }
private nextColumnSelected() {
const nbStreams = this.streams.length;
const selectedElement = this.streams.find(x => x.isSelected);
let currentSelectionIndex = 0;
if (selectedElement) {
currentSelectionIndex = this.streams.indexOf(selectedElement);
}
if(currentSelectionIndex < nbStreams - 1){
this.onColumnSelection(currentSelectionIndex + 1);
}
}
private previousColumnSelected() {
const selectedElement = this.streams.find(x => x.isSelected);
let currentSelectionIndex = 0;
if (selectedElement) {
currentSelectionIndex = this.streams.indexOf(selectedElement);
}
if(currentSelectionIndex > 0){
this.onColumnSelection(currentSelectionIndex - 1);
} else {
this.onColumnSelection(0);
}
}
onColumnSelection(index: number): boolean { onColumnSelection(index: number): boolean {
this.streams.forEach(x => x.isSelected = false); this.streams.forEach(x => x.isSelected = false);
@ -59,7 +99,7 @@ export class StreamsSelectionFooterComponent implements OnInit {
} }
class SelectableStream { class SelectableStream {
constructor(public readonly stream: StreamElement){ constructor(public readonly stream: StreamElement) {
} }
isSelected: boolean; isSelected: boolean;