From 6e6425735f68f0ff5a70158225f548f02b3319bb Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Thu, 25 Feb 2021 01:50:03 -0500 Subject: [PATCH] Began building out screenshot capture feature. --- .../IdeCascadeStudio/IdeCascadeStudio.js | 14 +++++++++ web/src/components/IdeToolbar/IdeToolbar.js | 30 +++++++++++++++++++ web/src/components/Svg/Svg.js | 23 ++++++++++++++ web/src/helpers/cascadeController.js | 23 ++++++++++++++ web/src/helpers/cloudinary.js | 23 ++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 web/src/helpers/cloudinary.js diff --git a/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js index 72cf624..f911887 100644 --- a/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js +++ b/web/src/components/IdeCascadeStudio/IdeCascadeStudio.js @@ -3,6 +3,8 @@ import CascadeController from 'src/helpers/cascadeController' import IdeToolbar from 'src/components/IdeToolbar' import { useEffect, useState } from 'react' import { threejsViewport } from 'src/cascade/js/MainPage/CascadeState' +import { element } from 'prop-types' +import { uploadToCloudinary } from 'src/helpers/cloudinary' const defaultExampleCode = `// Welcome to Cascade Studio! Here are some useful functions: // Translate(), Rotate(), Scale(), Union(), Difference(), Intersection() @@ -70,6 +72,18 @@ const IdeCascadeStudio = ({ part, saveCode, loading }) => { partTitle: part?.title, image: part?.user?.image, }} + onCapture={ async () => { + // Get the canvas image as a Data URL + const imgBlob = await CascadeController.capture(threejsViewport.environment) + const imgURL = window.URL.createObjectURL(imgBlob) + + // TODO: Upload the image to Cloudinary + // uploadToCloudinary(imgBlob) + + // TODO: Save the screenshot as the mainImage if none has been set + // If it has been set, pass along the Blob without uploading + // onSave(part?.id, { ...input, mainImage: cloudinaryPublicId }) + }} /> diff --git a/web/src/components/IdeToolbar/IdeToolbar.js b/web/src/components/IdeToolbar/IdeToolbar.js index ba5307a..73f70c1 100644 --- a/web/src/components/IdeToolbar/IdeToolbar.js +++ b/web/src/components/IdeToolbar/IdeToolbar.js @@ -23,6 +23,7 @@ const IdeToolbar = ({ userNamePart, isDraft, code, + onCapture, }) => { const [anchorEl, setAnchorEl] = useState(null) const [whichPopup, setWhichPopup] = useState(null) @@ -104,6 +105,10 @@ const IdeToolbar = ({ setIsLoginModalOpen(true) } + const captureScreenshot = async () => { + console.log({ forkPart, onCapture: onCapture() }) + } + const anchorOrigin = { vertical: 'bottom', horizontal: 'center', @@ -219,6 +224,31 @@ const IdeToolbar = ({
+ {/* Capture Screenshot link. Should only appear if part has been saved and is editable. */} + { !isDraft && canEdit &&
+ + +
+ Saving... +
+
+
}