Commit 7e79994f authored by Michael Vrána's avatar Michael Vrána

Algorithm graph is now saved to local storage

parent 47ffdc4c
Pipeline #80115 passed with stages
in 3 minutes and 59 seconds
......@@ -17,7 +17,7 @@ export const AlgorithmImportExportToolbar = (
<Paper>
<ElementButton
Icon={DownloadIcon}
label="Export"
label="Export to file"
onAction={props.onExport}
/>
<ImportButton onImport={props.onImport} />
......
......@@ -69,6 +69,32 @@ export const initialAlgorithmState: AlgorithmGraphState = {
const incompatibleTypeError = (from: AlibType, to: AlibType) =>
`Type ${from} is not castable to type ${to}`
export const localStorageAlgorithmReducer = (state?: AlgorithmGraphState, action?: any) => {
if (state === undefined) {
const savedGraph = window.localStorage.getItem('webui_graph')
if (savedGraph === null) return algorithmReducer(state, action)
const parsedGraph = JSON.parse(savedGraph)
const loadedState: AlgorithmGraphState = {
nodes: Map(parsedGraph.nodes),
edges: Map(parsedGraph.edges),
outputValues: Map(parsedGraph.outputValues),
cycleEdges: Set(parsedGraph.cycleEdges),
incompatibleEdges: Set(parsedGraph.incompatibleEdges),
errors: parsedGraph.errors
}
return algorithmReducer(loadedState, action)
}
const newState = algorithmReducer(state, action)
window.localStorage.setItem('webui_graph', JSON.stringify(newState))
return newState
}
export const algorithmReducer = (
state = initialAlgorithmState,
action: AlgorithmDataActions
......
......@@ -34,7 +34,7 @@ import {
import {
initialAlgorithmState,
algorithmDataActions,
algorithmReducer,
localStorageAlgorithmReducer as algorithmReducer,
AlgorithmGraphState
} from './algorithmData'
import {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment