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