-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,35 +26,14 @@ const SaveCanvasButton: FC = () => { | |
throw new Error( | ||
"Cannot export canvas: no references found. This is a bug." | ||
); | ||
let sizeBytes = 0; | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const fileId = urlParams.get("f"); | ||
|
||
if (!fileId) { | ||
throw new Error("No file ID found in the URL. This is a bug."); | ||
Check failure on line 34 in components/SaveCanvasButton/SaveCanvasButton.tsx
|
||
} | ||
|
||
// const elements = Array.from(document.getElementsByClassName("element")); | ||
// references.current.forEach((canvas, index) => { | ||
// if (canvas === null) { | ||
// remove(index); | ||
// return; | ||
// } | ||
// canvas.toBlob(async (blob) => { | ||
// if (!blob) { | ||
// throw new Error( | ||
// `Failed to save canvas with id: ${canvas.id} and name: ${canvas.getAttribute("data-name")}.` | ||
// ); | ||
// } | ||
|
||
// await set("layers", fileId, { | ||
// [canvas.id]: { | ||
// name: canvas.getAttribute("data-name"), | ||
// image: blob, | ||
// position: index | ||
// } | ||
// }); | ||
// }); | ||
// }); | ||
const canvasAsJSON = references.current.map((canvas, index) => { | ||
if (canvas === null) { | ||
remove(index); | ||
|
@@ -69,6 +48,8 @@ const SaveCanvasButton: FC = () => { | |
); | ||
} | ||
|
||
sizeBytes += blob.size; | ||
|
||
resolve({ | ||
name: canvas.getAttribute("data-name"), | ||
image: blob, | ||
|
@@ -79,10 +60,6 @@ const SaveCanvasButton: FC = () => { | |
}); | ||
}); | ||
|
||
const layers = await Promise.all(canvasAsJSON); | ||
|
||
await set("layers", fileId, layers); | ||
|
||
const allUnfocused = elements.current.map<Omit<CanvasElement, "focused">>( | ||
(element) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
|
@@ -92,6 +69,10 @@ const SaveCanvasButton: FC = () => { | |
} | ||
); | ||
|
||
const layers = await Promise.all(canvasAsJSON); | ||
|
||
await set("fileSizes", fileId, sizeBytes); | ||
await set("layers", fileId, layers); | ||
await set("elements", fileId, allUnfocused); | ||
|
||
// Update the UI to indicate that the canvas has been saved | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters