Add macro
This commit is contained in:
@@ -9,12 +9,19 @@ export namespace MacroActions {
|
||||
export const DUPLICATE = MacroActions.PREFIX + 'Duplicate macro';
|
||||
export const EDIT_NAME = MacroActions.PREFIX + 'Edit macro title';
|
||||
export const REMOVE = MacroActions.PREFIX + 'Remove macro';
|
||||
export const ADD = MacroActions.PREFIX + 'Add macro';
|
||||
|
||||
export const ADD_ACTION = MacroActions.PREFIX + 'Add macro action';
|
||||
export const SAVE_ACTION = MacroActions.PREFIX + 'Save macro action';
|
||||
export const DELETE_ACTION = MacroActions.PREFIX + 'Delete macro action';
|
||||
export const REORDER_ACTION = MacroActions.PREFIX + 'Reorder macro action';
|
||||
|
||||
export function addMacro(): Action {
|
||||
return {
|
||||
type: MacroActions.ADD
|
||||
};
|
||||
}
|
||||
|
||||
export function removeMacro(id: number): Action {
|
||||
return {
|
||||
type: MacroActions.REMOVE,
|
||||
|
||||
@@ -26,5 +26,15 @@ export class MacroEffects {
|
||||
}
|
||||
});
|
||||
|
||||
@Effect({dispatch: false}) add$: any = this.actions$
|
||||
.ofType(MacroActions.ADD)
|
||||
.withLatestFrom(this.store)
|
||||
.do((latest) => {
|
||||
let state: AppState = latest[1];
|
||||
let id: number = state.macros.entities.length - 1;
|
||||
|
||||
this.router.navigate(['/macro', id, 'new']);
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions, private router: Router, private store: Store<AppState>) {}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,18 @@ export default function(state = initialState, action: Action): MacroState {
|
||||
let newState: Macro[];
|
||||
|
||||
switch (action.type) {
|
||||
case MacroActions.ADD:
|
||||
newMacro = new Macro();
|
||||
newMacro.id = generateId(state.entities);
|
||||
newMacro.name = generateName(state.entities, 'New macro');
|
||||
newMacro.isLooped = false;
|
||||
newMacro.isPrivate = true;
|
||||
newMacro.macroActions = [];
|
||||
|
||||
return {
|
||||
entities: [...state.entities, newMacro]
|
||||
};
|
||||
|
||||
case MacroActions.DUPLICATE:
|
||||
|
||||
newMacro = new Macro(action.payload);
|
||||
|
||||
Reference in New Issue
Block a user