From 0523a76dd66fce71e49caea25aa3981de7a955ec Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Thu, 6 Jul 2023 03:09:11 -0400 Subject: blind, need to test --- .../views/nodes/generativeFill/GenerativeFill.tsx | 40 +++++++++++++--------- .../nodes/generativeFill/GenerativeFillButtons.tsx | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/generativeFill/GenerativeFill.tsx b/src/client/views/nodes/generativeFill/GenerativeFill.tsx index 5e7b4fdca..0ebf370c0 100644 --- a/src/client/views/nodes/generativeFill/GenerativeFill.tsx +++ b/src/client/views/nodes/generativeFill/GenerativeFill.tsx @@ -77,6 +77,9 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD // early stage properly, likely will get rid of const freeformPosition = useRef([0, 0]); + // which urls were already saved to canvas + const savedSrcs = useRef([]); + // references to keep track of tree structure const newCollectionRef = useRef(null); const parentDoc = useRef(null); @@ -243,16 +246,18 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD const ctx = ImageUtility.getCanvasContext(canvasRef); if (!ctx) return; setLoading(true); + // need to adjust later try { const maskBlob = await ImageUtility.canvasToBlob(canvas); const imgBlob = await ImageUtility.canvasToBlob(ImageUtility.getCanvasImg(img)); - const res = await ImageUtility.getEdit(imgBlob, maskBlob, input !== '' ? input + ' in the same style' : 'Fill in the image in the same style', 2); // const res = await ImageUtility.mockGetEdit(img.src); + parentDoc.current = childrenDocs.current[childrenDocs.current.length - 1]; + childrenDocs.current = []; + originalImg.current = currImg.current; const { urls } = res as APISuccess; const image = new Image(); image.src = urls[0]; - setLoading(false); setEdits(urls); ImageUtility.drawImgToCanvas(image, canvasRef); currImg.current = image; @@ -261,6 +266,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD } catch (err) { console.log(err); } + setLoading(false); }; // adjusts all the img positions to be aligned @@ -301,31 +307,34 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD }); childrenDocs.current.push(newImg); - adjustImgPositions(); + if (!firstDoc) { + DocUtils.MakeLink(parentDoc.current, newImg, { link_relationship: 'Image Edit', link_displayLine: true }); + adjustImgPositions(); + } Doc.AddDocToList(newCollectionRef.current, undefined, newImg); - DocUtils.MakeLink(parentDoc.current, newImg, { link_relationship: 'Image Edit' }); return newImg; }; + // need to maybe call on every img click, not just when the save btn is clicked const onSave = async () => { + setLoading(true); if (!currImg.current || !originalImg.current || !imageRootDoc) return; try { if (!newCollectionRef.current) { // create new collection and add it to the view newCollectionRef.current = Docs.Create.FreeformDocument([], { x: NumCast(imageRootDoc.x) + NumCast(imageRootDoc._width) + 20, y: NumCast(imageRootDoc.y), _width: 1000, _height: 1000 }); addDoc?.(newCollectionRef.current); - const originalSrc = originalImg.current.src; await createNewImgDoc(originalImg.current, true); } - CollectionDockingView.AddSplit(Doc.MakeCopy(DocCast(Doc.UserDoc().emptyPane)), OpenWhereMod.right); + await createNewImgDoc(currImg.current, false); + // CollectionDockingView.AddSplit(Doc.MakeCopy(DocCast(Doc.UserDoc().emptyPane)), OpenWhereMod.right); // CollectionDockingView.AddSplit(newCollection,OpenWhere.inParent) - // mindmapping + // mind mapping // this.props.addDocTab(); - - // Create link between prompt and image } catch (err) { console.log(err); } + setLoading(false); }; return ( @@ -336,6 +345,9 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD { + if (newCollectionRef.current) { + CollectionDockingView.AddSplit(newCollectionRef.current, OpenWhereMod.right); + } MainView.Instance.setImageEditorOpen(false); MainView.Instance.setImageEditorSource(''); setEdits([]); @@ -381,12 +393,6 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD }}> - {/* { - setBrushStyle(BrushStyle.SUBTRACT); - }}> - - */} {/* Undo and Redo */} { @@ -409,7 +415,7 @@ const GenerativeFill = ({ imageEditorOpen, imageEditorSource, imageRootDoc, addD - {/* Edits box */} + {/* Edits thumbnails*/}
{edits.map((edit, i) => ( ))} + {/* Original img thumbnail */} {edits.length > 0 && (