All checks were successful
continuous-integration/drone/push Build is passing
- Remove nullable type from container.properties.parentId - Add Swal when trying to delete main container - Moved default editor state to default.ts - Moved default symbol model to default.ts
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { Dispatch, SetStateAction } from 'react';
|
|
import { IConfiguration } from '../../../Interfaces/IConfiguration';
|
|
import { fetchConfiguration } from '../../API/api';
|
|
import { IEditorState } from '../../../Interfaces/IEditorState';
|
|
import { LoadState } from './Load';
|
|
import { GetDefaultEditorState } from '../../../utils/default';
|
|
|
|
export function NewEditor(
|
|
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
|
setLoaded: Dispatch<SetStateAction<boolean>>
|
|
): void {
|
|
// Fetch the configuration from the API
|
|
fetchConfiguration()
|
|
.then((configuration: IConfiguration) => {
|
|
// Set the editor from the given properties of the API
|
|
const editorState: IEditorState = GetDefaultEditorState(configuration);
|
|
|
|
setEditorState(editorState);
|
|
setLoaded(true);
|
|
}, (error) => {
|
|
console.warn('[NewEditor] Could not fetch resource from API. Using default.', error);
|
|
setLoaded(true);
|
|
});
|
|
}
|
|
|
|
export function LoadEditor(
|
|
files: FileList | null,
|
|
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
|
setLoaded: Dispatch<SetStateAction<boolean>>
|
|
): void {
|
|
if (files === null) {
|
|
return;
|
|
}
|
|
const file = files[0];
|
|
const reader = new FileReader();
|
|
reader.addEventListener('load', () => {
|
|
const result = reader.result as string;
|
|
const editorState: IEditorState = JSON.parse(result);
|
|
|
|
LoadState(editorState, setEditorState, setLoaded);
|
|
});
|
|
reader.readAsText(file);
|
|
}
|