diff --git a/src/App.tsx b/src/App.tsx index e6ea857..58e73c5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -40,6 +40,22 @@ export class App extends React.Component { }; } + componentDidMount() { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const state = urlParams.get('state'); + + if (state === null) { + return; + } + + fetch(state) + .then((response) => response.json()) + .then((data: IEditorState) => { + this.LoadState(data); + }); + } + public NewEditor() { // Fetch the configuration from the API fetchConfiguration().then((configuration: Configuration) => { @@ -86,18 +102,22 @@ export class App extends React.Component { const result = reader.result as string; const editorState: IEditorState = JSON.parse(result); - Revive(editorState); - - this.setState({ - configuration: editorState.configuration, - history: editorState.history, - historyCurrentStep: editorState.historyCurrentStep, - isLoaded: true - } as IAppState); + this.LoadState(editorState); }); reader.readAsText(file); } + private LoadState(editorState: IEditorState) { + Revive(editorState); + + this.setState({ + configuration: editorState.configuration, + history: editorState.history, + historyCurrentStep: editorState.historyCurrentStep, + isLoaded: true + } as IAppState); + } + public render() { if (this.state.isLoaded) { return (