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
|
// tslint:disable-next-line:variable-name
|
||||||
export const ActionTypes = {
|
export const ActionTypes = {
|
||||||
LOAD_USER_CONFIG: type(PREFIX + 'Load User Config'),
|
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 {
|
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
|
export type Actions
|
||||||
= LoadUserConfigAction
|
= LoadUserConfigAction
|
||||||
| LoadUserConfigSuccessAction;
|
| LoadUserConfigSuccessAction
|
||||||
|
| SaveUserConfigSuccessAction;
|
||||||
|
|||||||
@@ -1,16 +1,27 @@
|
|||||||
import { Injectable, Inject } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
import { Effect, Actions } from '@ngrx/effects';
|
import { Actions, Effect } from '@ngrx/effects';
|
||||||
import { Observable } from 'rxjs/Observable';
|
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/switchMap';
|
||||||
import 'rxjs/add/operator/startWith';
|
import 'rxjs/add/operator/startWith';
|
||||||
|
import 'rxjs/add/operator/withLatestFrom';
|
||||||
import 'rxjs/add/observable/of';
|
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 { 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 { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
|
||||||
|
import { AppState, getUserConfiguration } from '../index';
|
||||||
|
import { KeymapActions } from '../actions/keymap';
|
||||||
|
import { MacroActions } from '../actions/macro';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserConfigEffects {
|
export class UserConfigEffects {
|
||||||
@@ -26,7 +37,20 @@ export class UserConfigEffects {
|
|||||||
return Observable.of(new LoadUserConfigSuccessAction(config));
|
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,
|
constructor(private actions$: Actions,
|
||||||
@Inject(DATA_STORAGE_REPOSITORY)private dataStorageRepository: DataStorageRepositoryService,
|
@Inject(DATA_STORAGE_REPOSITORY) private dataStorageRepository: DataStorageRepositoryService,
|
||||||
private defaultUserConfigurationService: DefaultUserConfigurationService) { }
|
private store: Store<AppState>,
|
||||||
|
private defaultUserConfigurationService: DefaultUserConfigurationService) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ export interface AppState {
|
|||||||
userConfiguration: UserConfiguration;
|
userConfiguration: UserConfiguration;
|
||||||
presetKeymaps: Keymap[];
|
presetKeymaps: Keymap[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getUserConfiguration = (state: AppState) => state.userConfiguration;
|
||||||
|
|||||||
Reference in New Issue
Block a user