Allow LoadEditor through external resource
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4127a9a6eb
commit
893876ddaa
1 changed files with 28 additions and 8 deletions
36
src/App.tsx
36
src/App.tsx
|
@ -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 (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue