Allow LoadEditor through external resource
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Siklos 2022-08-05 13:49:22 +02:00
parent 4127a9a6eb
commit 893876ddaa

View file

@ -40,6 +40,22 @@ export class App extends React.Component<IAppProps> {
}; };
} }
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() { public NewEditor() {
// Fetch the configuration from the API // Fetch the configuration from the API
fetchConfiguration().then((configuration: Configuration) => { fetchConfiguration().then((configuration: Configuration) => {
@ -86,18 +102,22 @@ export class App extends React.Component<IAppProps> {
const result = reader.result as string; const result = reader.result as string;
const editorState: IEditorState = JSON.parse(result); const editorState: IEditorState = JSON.parse(result);
Revive(editorState); this.LoadState(editorState);
this.setState({
configuration: editorState.configuration,
history: editorState.history,
historyCurrentStep: editorState.historyCurrentStep,
isLoaded: true
} as IAppState);
}); });
reader.readAsText(file); 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() { public render() {
if (this.state.isLoaded) { if (this.state.isLoaded) {
return ( return (