feat(popover): sort keymaps and macros alphabetically (#534)
* feat(popover): sort keymaps and macros alphabetically Closes #512 * small performance refactoring
This commit is contained in:
committed by
László Monda
parent
a44a7dc5f8
commit
02f1053d46
@@ -7,14 +7,17 @@ import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/pairwise';
|
||||
import 'rxjs/add/operator/startWith';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/withLatestFrom';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { Keymap } from 'uhk-common';
|
||||
import { findNewItem } from '../../util';
|
||||
import { KeymapActions } from '../actions';
|
||||
import { AppState } from '../index';
|
||||
import { getKeymaps } from '../reducers/user-configuration';
|
||||
|
||||
@Injectable()
|
||||
export class KeymapEffects {
|
||||
@@ -32,10 +35,10 @@ export class KeymapEffects {
|
||||
|
||||
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
|
||||
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE)
|
||||
.withLatestFrom(this.store)
|
||||
.map(latest => latest[1].userConfiguration.keymaps)
|
||||
.do(keymaps => {
|
||||
this.router.navigate(['/keymap', keymaps[keymaps.length - 1].abbreviation]);
|
||||
.withLatestFrom(this.store.let(getKeymaps()).pairwise(), (action, latest) => latest)
|
||||
.do(([prevKeymaps, newKeymaps]) => {
|
||||
const newKeymap = findNewItem(prevKeymaps, newKeymaps);
|
||||
this.router.navigate(['/keymap', newKeymap.abbreviation]);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false }) remove$: any = this.actions$
|
||||
|
||||
@@ -2,14 +2,18 @@ import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Actions, Effect } from '@ngrx/effects';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Store, Action } from '@ngrx/store';
|
||||
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/pairwise';
|
||||
import 'rxjs/add/operator/withLatestFrom';
|
||||
|
||||
import { Macro } from 'uhk-common';
|
||||
import { KeymapActions, MacroActions } from '../actions';
|
||||
import { AppState } from '../index';
|
||||
import { getMacros } from '../reducers/user-configuration';
|
||||
import { findNewItem } from '../../util';
|
||||
|
||||
@Injectable()
|
||||
export class MacroEffects {
|
||||
@@ -27,23 +31,17 @@ export class MacroEffects {
|
||||
}
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false }) add$: any = this.actions$
|
||||
.ofType(MacroActions.ADD)
|
||||
.withLatestFrom(this.store)
|
||||
.map(([action, state]) => state.userConfiguration.macros)
|
||||
.map(macros => macros[macros.length - 1])
|
||||
.do(lastMacro => {
|
||||
this.router.navigate(['/macro', lastMacro.id, 'new']);
|
||||
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
|
||||
.ofType(MacroActions.ADD, MacroActions.DUPLICATE)
|
||||
.withLatestFrom(this.store.let(getMacros()).pairwise(), (action, latest) => ([action, latest[0], latest[1]]))
|
||||
.do(([action, prevMacros, newMacros]: [Action, Macro[], Macro[]]) => {
|
||||
const newMacro = findNewItem(prevMacros, newMacros);
|
||||
const commands = ['/macro', newMacro.id];
|
||||
if (action.type === MacroActions.ADD) {
|
||||
commands.push('new');
|
||||
}
|
||||
this.router.navigate(commands);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false }) duplicate: any = this.actions$
|
||||
.ofType(MacroActions.DUPLICATE)
|
||||
.withLatestFrom(this.store)
|
||||
.map(([action, state]) => state.userConfiguration.macros)
|
||||
.map(macros => macros[macros.length - 1])
|
||||
.do(lastMacro => {
|
||||
this.router.navigate(['/macro', lastMacro.id]);
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) {}
|
||||
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user