ISSUE 10: add upload file functionality
This commit is contained in:
@@ -117,10 +117,23 @@ export const DockBuilder = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uploadFile = (e) => {
|
const uploadFile = (e) => {
|
||||||
// TODO: Our own upload the file we must have downloaded previously
|
const file = e.target.files[0];
|
||||||
// TODO: extract the json from the file
|
if (!file) return;
|
||||||
// TODO: load the json to the editor
|
const reader = new FileReader();
|
||||||
// TODO: render all
|
reader.onload = function (event) {
|
||||||
|
try {
|
||||||
|
const json = JSON.parse(event.target.result);
|
||||||
|
console.log(json);
|
||||||
|
editorMemo.loadFromJSON(json, () => {
|
||||||
|
editorMemo.renderAll();
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
alert("Invalid file format. Please select a valid .dock file.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
// Reset file input to allow reupload of the same file
|
||||||
|
e.target.value = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadImage = useCallback(() => {
|
const downloadImage = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user