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 = ({