2018-05-15 14:50:21 +00:00
|
|
|
/* @flow */
|
2018-05-23 16:03:26 +00:00
|
|
|
import type {
|
|
|
|
ResetSimulationAction,
|
2018-06-18 16:03:52 +00:00
|
|
|
LoadPreviousSimulationAction,
|
2018-07-23 14:26:11 +00:00
|
|
|
DeletePreviousSimulationAction,
|
|
|
|
StartConversationAction
|
2018-07-12 08:09:41 +00:00
|
|
|
} from 'Types/ActionsTypes'
|
2019-01-08 18:19:19 +00:00
|
|
|
import { reset } from 'redux-form'
|
2018-10-03 09:28:18 +00:00
|
|
|
import { deletePersistedSimulation } from '../storage/persistSimulation'
|
2018-10-04 13:20:57 +00:00
|
|
|
import { normalizeBasePath } from '../utils'
|
|
|
|
|
|
|
|
import type { RouterHistory } from 'react-router-dom'
|
2018-05-15 14:50:21 +00:00
|
|
|
|
2019-01-08 18:19:19 +00:00
|
|
|
export const resetSimulation = () => (dispatch: any => void): void => {
|
|
|
|
dispatch(reset('conversation'))
|
|
|
|
dispatch(
|
|
|
|
({
|
|
|
|
type: 'RESET_SIMULATION'
|
|
|
|
}: ResetSimulationAction)
|
|
|
|
)
|
2018-05-15 14:50:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 09:28:18 +00:00
|
|
|
export const deletePreviousSimulation = () => (
|
|
|
|
dispatch: DeletePreviousSimulationAction => void
|
|
|
|
) => {
|
|
|
|
dispatch({
|
2018-06-18 16:03:52 +00:00
|
|
|
type: 'DELETE_PREVIOUS_SIMULATION'
|
2018-10-03 09:28:18 +00:00
|
|
|
})
|
|
|
|
deletePersistedSimulation()
|
2018-06-18 16:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 13:20:57 +00:00
|
|
|
export const startConversation = (priorityNamespace: ?string) => (
|
|
|
|
dispatch: StartConversationAction => void,
|
|
|
|
_: any,
|
|
|
|
history: RouterHistory
|
|
|
|
) => {
|
|
|
|
dispatch({
|
2018-07-23 14:26:11 +00:00
|
|
|
type: 'START_CONVERSATION',
|
2018-09-13 12:29:50 +00:00
|
|
|
...(priorityNamespace ? { priorityNamespace } : {})
|
2018-10-04 13:20:57 +00:00
|
|
|
})
|
2018-10-09 09:22:08 +00:00
|
|
|
const currentPath = normalizeBasePath(history.location.pathname)
|
|
|
|
if (currentPath.endsWith('/simulation/')) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
history.push(currentPath + 'simulation')
|
2018-07-23 14:26:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:50:21 +00:00
|
|
|
// $FlowFixMe
|
2018-06-13 08:26:27 +00:00
|
|
|
export function setExample(name, situation, dottedName) {
|
|
|
|
return { type: 'SET_EXAMPLE', name, situation, dottedName }
|
2018-02-22 16:23:47 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 16:03:26 +00:00
|
|
|
export function loadPreviousSimulation(): LoadPreviousSimulationAction {
|
|
|
|
return {
|
|
|
|
type: 'LOAD_PREVIOUS_SIMULATION'
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 16:50:22 +00:00
|
|
|
|
2018-10-02 16:14:01 +00:00
|
|
|
export function hideControl(id: string) {
|
|
|
|
return { type: 'HIDE_CONTROL', id }
|
|
|
|
}
|
|
|
|
|
2017-02-09 17:15:25 +00:00
|
|
|
export const EXPLAIN_VARIABLE = 'EXPLAIN_VARIABLE'
|