Reverted to screenshot confirmation flow, fixed layout bug, updated language to Save
This commit is contained in:
@@ -72,22 +72,39 @@ const IdeCascadeStudio = ({ part, saveCode, loading }) => {
|
|||||||
image: part?.user?.image,
|
image: part?.user?.image,
|
||||||
}}
|
}}
|
||||||
onCapture={ async () => {
|
onCapture={ async () => {
|
||||||
|
const config = {
|
||||||
|
currImage: part?.mainImage,
|
||||||
|
callback: uploadAndUpdateImage,
|
||||||
|
cloudinaryImgURL: '',
|
||||||
|
updated: false,
|
||||||
|
}
|
||||||
// Get the canvas image as a Data URL
|
// Get the canvas image as a Data URL
|
||||||
const imgBlob = await CascadeController.capture(threejsViewport.environment)
|
config.image = await CascadeController.capture(threejsViewport.environment)
|
||||||
|
config.imageObjectURL = window.URL.createObjectURL(config.image)
|
||||||
|
|
||||||
// Upload the image to Cloudinary
|
async function uploadAndUpdateImage(){
|
||||||
const cloudinaryImg = await uploadToCloudinary(imgBlob)
|
// Upload the image to Cloudinary
|
||||||
|
const cloudinaryImgURL = await uploadToCloudinary(config.image)
|
||||||
|
|
||||||
// Save the screenshot as the mainImage
|
// Save the screenshot as the mainImage
|
||||||
saveCode({
|
saveCode({
|
||||||
input: {
|
input: {
|
||||||
mainImage: cloudinaryImg.public_id,
|
mainImage: cloudinaryImgURL.public_id,
|
||||||
},
|
},
|
||||||
id: part?.id,
|
id: part?.id,
|
||||||
isFork: !canEdit,
|
isFork: !canEdit,
|
||||||
})
|
})
|
||||||
|
|
||||||
return { imgBlob, cloudinaryImg }
|
return cloudinaryImgURL
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there isn't a screenshot saved yet, just go ahead and save right away
|
||||||
|
if (!part || !part.mainImage) {
|
||||||
|
config.cloudinaryImgURL = await uploadAndUpdateImage().public_id
|
||||||
|
config.updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const Success = ({ part, refetch }) => {
|
|||||||
const { user } = useUser()
|
const { user } = useUser()
|
||||||
const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
|
const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
|
||||||
onCompleted: () => {
|
onCompleted: () => {
|
||||||
addMessage('Part updated.', { classes: 'rw-flash-success' })
|
addMessage('Part updated.', { classes: 'rw-flash-success fixed w-screen z-10' })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const [forkPart] = useMutation(FORK_PART_MUTATION, {
|
const [forkPart] = useMutation(FORK_PART_MUTATION, {
|
||||||
|
|||||||
@@ -106,10 +106,9 @@ const IdeToolbar = ({
|
|||||||
setIsLoginModalOpen(true)
|
setIsLoginModalOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDownload = (imgBlob) => {
|
const handleDownload = (url) => {
|
||||||
const aTag = document.createElement('a')
|
const aTag = document.createElement('a')
|
||||||
document.body.appendChild(aTag)
|
document.body.appendChild(aTag)
|
||||||
const url = URL.createObjectURL(imgBlob)
|
|
||||||
aTag.href= url
|
aTag.href= url
|
||||||
aTag.style.display = 'none'
|
aTag.style.display = 'none'
|
||||||
aTag.download = `CadHub_${ Date.now() }.jpg`
|
aTag.download = `CadHub_${ Date.now() }.jpg`
|
||||||
@@ -241,7 +240,7 @@ const IdeToolbar = ({
|
|||||||
}}
|
}}
|
||||||
className="text-indigo-300 flex items-center pr-6"
|
className="text-indigo-300 flex items-center pr-6"
|
||||||
>
|
>
|
||||||
Set Part Image <Svg name="camera" className="pl-2 w-8" />
|
Save Part Image <Svg name="camera" className="pl-2 w-8" />
|
||||||
</button>
|
</button>
|
||||||
<Popover
|
<Popover
|
||||||
id={id}
|
id={id}
|
||||||
@@ -257,17 +256,26 @@ const IdeToolbar = ({
|
|||||||
? 'Loading...'
|
? 'Loading...'
|
||||||
: <div className="grid grid-cols-2">
|
: <div className="grid grid-cols-2">
|
||||||
<div className="rounded m-auto" style={{width: 'fit-content', overflow: 'hidden'}}>
|
<div className="rounded m-auto" style={{width: 'fit-content', overflow: 'hidden'}}>
|
||||||
<img src={ window.URL.createObjectURL(captureState.imgBlob) } className="w-32" />
|
<img src={ captureState.imageObjectURL } className="w-32" />
|
||||||
</div>
|
</div>
|
||||||
<div className="p-2 text-indigo-800">
|
<div className="p-2 text-indigo-800">
|
||||||
<div className="flex justify-center mb-4">
|
{ (captureState.currImage && !captureState.updated)
|
||||||
<Svg name="checkmark" className="mr-2 w-6 text-indigo-600"/> Part Image Set
|
? <button className="flex justify-center mb-4"
|
||||||
</div>
|
onClick={ async () => {
|
||||||
|
const cloudinaryImg = await captureState.callback()
|
||||||
|
setCaptureState({...captureState, currImage: cloudinaryImg.public_id, updated: true })
|
||||||
|
}}>
|
||||||
|
<Svg name="refresh" className="mr-2 w-4 text-indigo-600"/> Update Part Image
|
||||||
|
</button>
|
||||||
|
: <div className="flex justify-center mb-4">
|
||||||
|
<Svg name="checkmark" className="mr-2 w-6 text-indigo-600"/> Part Image Updated
|
||||||
|
</div>
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
iconName="save"
|
iconName="save"
|
||||||
className="shadow-md hover:shadow-lg border-indigo-600 border-2 border-opacity-0 hover:border-opacity-100 bg-indigo-800 text-indigo-100 text-opacity-100 bg-opacity-100"
|
className="shadow-md hover:shadow-lg border-indigo-600 border-2 border-opacity-0 hover:border-opacity-100 bg-indigo-800 text-indigo-100 text-opacity-100 bg-opacity-80"
|
||||||
shouldAnimateHover
|
shouldAnimateHover
|
||||||
onClick={() => handleDownload(captureState.imgBlob)}>
|
onClick={() => handleDownload(captureState.imageObjectURL)}>
|
||||||
Download
|
Download
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class CascadeController {
|
|||||||
onInit()
|
onInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
capture(environment) {
|
capture(environment, width = 512, height = 384) {
|
||||||
let width = 512, height = 384; // These can be adjusted to the best size for the Part Profile.
|
|
||||||
environment.camera.aspect = width / height;
|
environment.camera.aspect = width / height;
|
||||||
environment.camera.updateProjectionMatrix();
|
environment.camera.updateProjectionMatrix();
|
||||||
environment.renderer.setSize(width, height);
|
environment.renderer.setSize(width, height);
|
||||||
|
|||||||
Reference in New Issue
Block a user