From 4efbc33893f85ae9729c7c1d69764e6f38468d5d Mon Sep 17 00:00:00 2001 From: Siklos Date: Sun, 7 Aug 2022 15:20:17 +0200 Subject: [PATCH] Allow to start from scratch with a default config --- src/App.tsx | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 705e40d..263827b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -100,8 +100,39 @@ export class App extends React.Component { historyCurrentStep: 0, isLoaded: true }); - }, (error) => { throw new Error(error); } - ); + }, (error) => { + // TODO: Implement an alert component + console.warn('[NewEditor] Could not fetch resource from API. Returning default.', error); + const MainContainer = new ContainerModel( + null, + { + id: 'main', + parentId: 'null', + x: 0, + y: 0, + width: DEFAULT_CONFIG.MainContainer.Width, + height: DEFAULT_CONFIG.MainContainer.Height, + fillOpacity: DEFAULT_CONFIG.MainContainer.Style.fillOpacity, + stroke: DEFAULT_CONFIG.MainContainer.Style.stroke, + } + ); + + // Save the configuration and the new MainContainer + // and default the selected container to it + this.setState({ + configuration: DEFAULT_CONFIG, + history: + [ + { + MainContainer, + SelectedContainer: MainContainer, + TypeCounters: {} + } + ], + historyCurrentStep: 0, + isLoaded: true + }); + }); } public LoadEditor(files: FileList | null): void { @@ -182,3 +213,28 @@ export async function fetchConfiguration(): Promise { xhr.send(); }); } + + +const DEFAULT_CONFIG: Configuration = { + AvailableContainers: [ + { + Type: 'Container', + Width: 75, + Height: 100, + Style: { + fillOpacity: 0, + stroke: 'green' + } + } + ], + AvailableSymbols: [], + MainContainer: { + Type: 'Container', + Width: 2000, + Height: 100, + Style: { + fillOpacity: 0, + stroke: 'black' + } + } +}