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,
|
2019-01-15 17:36:04 +00:00
|
|
|
StartConversationAction,
|
2019-01-17 10:38:24 +00:00
|
|
|
SetSimulationConfigAction,
|
2019-01-15 17:36:04 +00:00
|
|
|
SetSituationBranchAction
|
2018-07-12 08:09:41 +00:00
|
|
|
} from 'Types/ActionsTypes'
|
2019-02-01 12:31:57 +00:00
|
|
|
// $FlowFixMe
|
2019-02-08 11:45:14 +00:00
|
|
|
import { reset } from 'redux-form'
|
|
|
|
import { deletePersistedSimulation } from '../storage/persistSimulation'
|
|
|
|
import type { Thunk } from 'Types/ActionsTypes'
|
2018-05-15 14:50:21 +00:00
|
|
|
|
2019-01-08 18:19:19 +00:00
|
|
|
export const resetSimulation = () => (dispatch: any => void): void => {
|
|
|
|
dispatch(
|
|
|
|
({
|
|
|
|
type: 'RESET_SIMULATION'
|
|
|
|
}: ResetSimulationAction)
|
|
|
|
)
|
2019-01-31 15:18:14 +00:00
|
|
|
dispatch(reset('conversation'))
|
2018-05-15 14:50:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 17:36:04 +00:00
|
|
|
export const setSituationBranch = (id: number): SetSituationBranchAction => ({
|
|
|
|
type: 'SET_SITUATION_BRANCH',
|
|
|
|
id
|
|
|
|
})
|
|
|
|
|
2019-02-08 11:45:14 +00:00
|
|
|
export const setSimulationConfig = (
|
|
|
|
config: Object
|
|
|
|
): Thunk<SetSimulationConfigAction> => (dispatch, _, { history }): void => {
|
2019-01-17 10:38:24 +00:00
|
|
|
const url = history.location.pathname
|
|
|
|
dispatch({
|
|
|
|
type: 'SET_SIMULATION',
|
|
|
|
url,
|
|
|
|
config
|
|
|
|
})
|
|
|
|
}
|
2019-01-17 09:47:46 +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) => (
|
2019-02-08 11:45:14 +00:00
|
|
|
dispatch: StartConversationAction => void
|
2018-10-04 13:20:57 +00:00
|
|
|
) => {
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2019-02-08 11:45:14 +00:00
|
|
|
export const goBackToSimulation = (): Thunk<any> => (
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
{ history }
|
|
|
|
) => {
|
2019-01-17 10:38:24 +00:00
|
|
|
dispatch({ type: 'SET_EXEMPLE', name: null })
|
|
|
|
history.push(getState().simulation.url)
|
2019-01-11 10:46:02 +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'
|