Allow to start from scratch with a default config

This commit is contained in:
Siklos 2022-08-07 15:20:17 +02:00
parent a73757d849
commit 4efbc33893

View file

@ -100,8 +100,39 @@ export class App extends React.Component<IAppProps> {
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<Configuration> {
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'
}
}
}