diff --git a/source/actions/actions.js b/source/actions/actions.js index 2189faf03..94f2433c8 100644 --- a/source/actions/actions.js +++ b/source/actions/actions.js @@ -5,6 +5,7 @@ import type { DeletePreviousSimulationAction, StartConversationAction } from 'Types/ActionsTypes' +import { deletePersistedSimulation } from '../storage/persistSimulation' export function resetSimulation(): ResetSimulationAction { return { @@ -12,10 +13,13 @@ export function resetSimulation(): ResetSimulationAction { } } -export function deletePreviousSimulation(): DeletePreviousSimulationAction { - return { +export const deletePreviousSimulation = () => ( + dispatch: DeletePreviousSimulationAction => void +) => { + dispatch({ type: 'DELETE_PREVIOUS_SIMULATION' - } + }) + deletePersistedSimulation() } export function startConversation(question: ?string): StartConversationAction { diff --git a/source/storage/persistSimulation.js b/source/storage/persistSimulation.js index 2766c00c7..79c521537 100644 --- a/source/storage/persistSimulation.js +++ b/source/storage/persistSimulation.js @@ -25,3 +25,7 @@ export function retrievePersistedSimulation(): ?SavedSimulation { const serializedState = window.localStorage.getItem(LOCAL_STORAGE_KEY) return serializedState ? deserialize(serializedState) : null } + +export function deletePersistedSimulation(): void { + window.localStorage.removeItem(LOCAL_STORAGE_KEY) +}