From ab2f477b7f1ec392fe80f67487092e29d94a7279 Mon Sep 17 00:00:00 2001 From: Ayobami Date: Wed, 2 Jul 2025 18:17:26 +0100 Subject: [PATCH] ISSUE 9: add download file functionality --- src/components/DockBuilder/DockBuilder.jsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/DockBuilder/DockBuilder.jsx b/src/components/DockBuilder/DockBuilder.jsx index 969f7b1..ffcb428 100644 --- a/src/components/DockBuilder/DockBuilder.jsx +++ b/src/components/DockBuilder/DockBuilder.jsx @@ -103,11 +103,17 @@ export const DockBuilder = () => { // }, [ editor ] ); const toJSON = () => { - // TODO: download the json file - // TODO: get json of editor content - // TODO: Ensure dockData is included in the json - // TODO: save the json to the local storage as dock - // TODO: name the file as paradise_dock_.dock + // Get JSON of editor content, including dockData and snapClone + const json = editorMemo.toJSON(["dockData", "snapClone"]); + const data = JSON.stringify(json, null, 2); + // Save to localStorage + localStorage.setItem("dock", data); + const blob = new Blob([data], { type: "application/json" }); + const anchor = document.createElement("a"); + const timestamp = Date.now(); + anchor.href = URL.createObjectURL(blob); + anchor.download = `paradise_dock_${timestamp}.dock`; // TODO: name the file as paradise_dock_.dock + anchor.click(); }; const uploadFile = (e) => {