@ -1,12 +1,10 @@
import _ from 'lodash' ;
import { createAction } from 'redux-actions' ;
import { batchActions } from 'redux-batched-actions' ;
import { messageTypes } from 'Helpers/Props' ;
import { createThunk , handleThunks } from 'Store/thunks' ;
import { isSameCommand } from 'Utilities/Command' ;
import createAjaxRequest from 'Utilities/createAjaxRequest' ;
import { hideMessage , showMessage } from './appActions' ;
import { updateItem } from './baseActions' ;
import { removeItem, updateItem } from './baseActions' ;
import createFetchHandler from './Creators/createFetchHandler' ;
import createHandleActions from './Creators/createHandleActions' ;
import createRemoveItemHandler from './Creators/createRemoveItemHandler' ;
@ -37,9 +35,9 @@ export const defaultState = {
export const FETCH _COMMANDS = 'commands/fetchCommands' ;
export const EXECUTE _COMMAND = 'commands/executeCommand' ;
export const CANCEL _COMMAND = 'commands/cancelCommand' ;
export const ADD _COMMAND = 'commands/ update Command';
export const UPDATE _COMMAND = 'commands/ finish Command';
export const FINISH _COMMAND = 'commands/ add Command';
export const ADD _COMMAND = 'commands/ add Command';
export const UPDATE _COMMAND = 'commands/ update Command';
export const FINISH _COMMAND = 'commands/ finish Command';
export const REMOVE _COMMAND = 'commands/removeCommand' ;
//
@ -48,10 +46,10 @@ export const REMOVE_COMMAND = 'commands/removeCommand';
export const fetchCommands = createThunk ( FETCH _COMMANDS ) ;
export const executeCommand = createThunk ( EXECUTE _COMMAND ) ;
export const cancelCommand = createThunk ( CANCEL _COMMAND ) ;
export const addCommand = createThunk ( ADD _COMMAND ) ;
export const updateCommand = createThunk ( UPDATE _COMMAND ) ;
export const finishCommand = createThunk ( FINISH _COMMAND ) ;
export const addCommand = createAction ( ADD _COMMAND ) ;
export const removeCommand = createAction ( REMOVE _COMMAND ) ;
export const removeCommand = createThunk ( REMOVE _COMMAND ) ;
//
// Helpers
@ -161,6 +159,10 @@ export const actionHandlers = handleThunks({
[ CANCEL _COMMAND ] : createRemoveItemHandler ( section , '/command' ) ,
[ ADD _COMMAND ] : function ( getState , payload , dispatch ) {
dispatch ( updateItem ( { section : 'commands' , ... payload } ) ) ;
} ,
[ UPDATE _COMMAND ] : function ( getState , payload , dispatch ) {
dispatch ( updateItem ( { section : 'commands' , ... payload } ) ) ;
@ -183,6 +185,10 @@ export const actionHandlers = handleThunks({
dispatch ( updateItem ( { section : 'commands' , ... payload } ) ) ;
scheduleRemoveCommand ( payload , dispatch ) ;
showCommandMessage ( payload , dispatch ) ;
} ,
[ ADD _COMMAND ] : function ( getState , payload , dispatch ) {
dispatch ( removeItem ( { section : 'commands' , ... payload } ) ) ;
}
} ) ;
@ -190,26 +196,4 @@ export const actionHandlers = handleThunks({
//
// Reducers
export const reducers = createHandleActions ( {
[ ADD _COMMAND ] : ( state , { payload } ) => {
const newState = Object . assign ( { } , state ) ;
newState . items = [ ... state . items , payload ] ;
return newState ;
} ,
[ REMOVE _COMMAND ] : ( state , { payload } ) => {
const newState = Object . assign ( { } , state ) ;
newState . items = [ ... state . items ] ;
const index = _ . findIndex ( newState . items , { id : payload . id } ) ;
if ( index > - 1 ) {
newState . items . splice ( index , 1 ) ;
}
return newState ;
}
} , defaultState , section ) ;
export const reducers = createHandleActions ( { } , defaultState , section ) ;