Add the whole user configuration to the AppState

Closes #252
Fixes #219
This commit is contained in:
Farkas József
2017-02-07 23:43:34 +01:00
committed by József Farkas
parent e41a62be13
commit f1f8a8d64e
19 changed files with 374 additions and 525 deletions

View File

@@ -16,34 +16,23 @@ import { Keymap } from '../../config-serializer/config-items/Keymap';
@Injectable()
export class KeymapEffects {
@Effect({ dispatch: false }) add$: any = this.actions$
.ofType(KeymapActions.ADD)
@Effect({ dispatch: false }) addOrDuplicate$: any = this.actions$
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE)
.withLatestFrom(this.store)
.do((latest) => {
const state: AppState = latest[1];
const entities: Keymap[] = state.keymaps.entities;
this.router.navigate(['/keymap', entities[entities.length - 1].abbreviation]);
});
@Effect({ dispatch: false }) duplicate$: any = this.actions$
.ofType(KeymapActions.DUPLICATE)
.withLatestFrom(this.store)
.do((latest) => {
const state: AppState = latest[1];
const entities: Keymap[] = state.keymaps.entities;
this.router.navigate(['/keymap', entities[entities.length - 1].abbreviation]);
.map(latest => latest[1].userConfiguration.keymaps)
.do(keymaps => {
this.router.navigate(['/keymap', keymaps[keymaps.length - 1].abbreviation]);
});
@Effect({ dispatch: false }) remove$: any = this.actions$
.ofType(KeymapActions.REMOVE)
.withLatestFrom(this.store)
.do((latest) => {
const state: AppState = latest[1];
if (state.keymaps.entities.length === 0) {
.map(latest => latest[1].userConfiguration.keymaps)
.do(keymaps => {
if (keymaps.length === 0) {
this.router.navigate(['/keymap/add']);
} else {
const favourite: Keymap = state.keymaps.entities.find(keymap => keymap.isDefault);
const favourite: Keymap = keymaps.find(keymap => keymap.isDefault);
this.router.navigate(['/keymap', favourite.abbreviation]);
}
});

View File

@@ -20,25 +20,22 @@ export class MacroEffects {
.ofType(MacroActions.REMOVE)
.map(action => this.store.dispatch(KeymapActions.checkMacro(action.payload)))
.withLatestFrom(this.store)
.do((latest) => {
const state: AppState = latest[1];
const macro: Macro[] = state.macros.entities;
if (state.macros.entities.length === 0) {
.map(latest => latest[1].userConfiguration.macros)
.do(macros => {
if (macros.length === 0) {
this.router.navigate(['/macro']);
} else {
this.router.navigate(['/macro', macro[0].id]);
this.router.navigate(['/macro', macros[0].id]);
}
});
@Effect({dispatch: false}) add$: any = this.actions$
.ofType(MacroActions.ADD)
.withLatestFrom(this.store)
.do((latest) => {
const state: AppState = latest[1];
const macro: Macro = state.macros.entities[state.macros.entities.length - 1];
this.router.navigate(['/macro', macro.id, 'new']);
.map(latest => latest[1].userConfiguration.macros)
.map(macros => macros[macros.length - 1])
.do(lastMacro => {
this.router.navigate(['/macro', lastMacro.id, 'new']);
});
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) {}