fix(keymap): Save keymap user configuration after changed (#313)
* fix(keymap): Save keymap user configuration after changed fix #308 issue * fix(keymap): remove unused imports * fix(keymap): change switchMap to map
This commit is contained in:
committed by
László Monda
parent
609fcb9a4a
commit
438aab5c71
@@ -8,7 +8,8 @@ const PREFIX = '[user-config] ';
|
||||
// tslint:disable-next-line:variable-name
|
||||
export const ActionTypes = {
|
||||
LOAD_USER_CONFIG: type(PREFIX + 'Load User Config'),
|
||||
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success')
|
||||
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'),
|
||||
SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save User Config Success')
|
||||
};
|
||||
|
||||
export class LoadUserConfigAction implements Action {
|
||||
@@ -23,6 +24,11 @@ export class LoadUserConfigSuccessAction implements Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class SaveUserConfigSuccessAction implements Action {
|
||||
type = ActionTypes.SAVE_USER_CONFIG_SUCCESS;
|
||||
}
|
||||
|
||||
export type Actions
|
||||
= LoadUserConfigAction
|
||||
| LoadUserConfigSuccessAction;
|
||||
| LoadUserConfigSuccessAction
|
||||
| SaveUserConfigSuccessAction;
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { Effect, Actions } from '@ngrx/effects';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { Actions, Effect } from '@ngrx/effects';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Action } from '@ngrx/store';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/startWith';
|
||||
import 'rxjs/add/operator/withLatestFrom';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { ActionTypes, LoadUserConfigAction, LoadUserConfigSuccessAction } from '../actions/user-config';
|
||||
import {
|
||||
ActionTypes,
|
||||
LoadUserConfigAction,
|
||||
LoadUserConfigSuccessAction,
|
||||
SaveUserConfigSuccessAction
|
||||
} from '../actions/user-config';
|
||||
|
||||
import { UserConfiguration } from '../../config-serializer/config-items/UserConfiguration';
|
||||
import { DataStorageRepositoryService, DATA_STORAGE_REPOSITORY } from '../../services/datastorage-repository.service';
|
||||
import { DATA_STORAGE_REPOSITORY, DataStorageRepositoryService } from '../../services/datastorage-repository.service';
|
||||
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
|
||||
import { AppState, getUserConfiguration } from '../index';
|
||||
import { KeymapActions } from '../actions/keymap';
|
||||
import { MacroActions } from '../actions/macro';
|
||||
|
||||
@Injectable()
|
||||
export class UserConfigEffects {
|
||||
@@ -26,7 +37,20 @@ export class UserConfigEffects {
|
||||
return Observable.of(new LoadUserConfigSuccessAction(config));
|
||||
});
|
||||
|
||||
@Effect() saveUserConfig$: Observable<Action> = this.actions$
|
||||
.ofType(KeymapActions.ADD, KeymapActions.DUPLICATE, KeymapActions.EDIT_NAME, KeymapActions.EDIT_ABBR,
|
||||
KeymapActions.SET_DEFAULT, KeymapActions.REMOVE, KeymapActions.SAVE_KEY, KeymapActions.CHECK_MACRO,
|
||||
MacroActions.ADD, MacroActions.DUPLICATE, MacroActions.EDIT_NAME, MacroActions.REMOVE, MacroActions.ADD_ACTION,
|
||||
MacroActions.SAVE_ACTION, MacroActions.DELETE_ACTION, MacroActions.REORDER_ACTION)
|
||||
.withLatestFrom(this.store.select(getUserConfiguration))
|
||||
.map(([action, config]) => {
|
||||
this.dataStorageRepository.saveConfig(config);
|
||||
return new SaveUserConfigSuccessAction();
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions,
|
||||
@Inject(DATA_STORAGE_REPOSITORY)private dataStorageRepository: DataStorageRepositoryService,
|
||||
private defaultUserConfigurationService: DefaultUserConfigurationService) { }
|
||||
@Inject(DATA_STORAGE_REPOSITORY) private dataStorageRepository: DataStorageRepositoryService,
|
||||
private store: Store<AppState>,
|
||||
private defaultUserConfigurationService: DefaultUserConfigurationService) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,3 +6,5 @@ export interface AppState {
|
||||
userConfiguration: UserConfiguration;
|
||||
presetKeymaps: Keymap[];
|
||||
}
|
||||
|
||||
export const getUserConfiguration = (state: AppState) => state.userConfiguration;
|
||||
|
||||
Reference in New Issue
Block a user