From 33761fc2227458acf36a5cc4b1f08eaae6e58695 Mon Sep 17 00:00:00 2001
From: eleanor-park <eleanor_park@brown.edu>
Date: Tue, 11 Jun 2024 11:15:25 -0400
Subject: some changes

---
 .../collectionFreeForm/SmartDrawHandler.tsx        | 31 +++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx b/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
index 7e66a62d4..fc8f7a429 100644
--- a/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
+++ b/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
@@ -10,7 +10,6 @@ import { AiOutlineSend } from 'react-icons/ai';
 import { MarqueeOptionsMenu } from './MarqueeOptionsMenu';
 import './ImageLabelHandler.scss';
 import { gptAPICall, GPTCallType } from '../../../apis/gpt/GPT';
-import { InkingStroke } from '../../InkingStroke';
 import { InkData } from '../../../../fields/InkField';
 
 @observer
@@ -23,7 +22,8 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
     @observable private _yRelativeToTop: boolean = true;
     @observable private _isLoading: boolean = false;
     @observable private _userInput: string = '';
-    @observable public strokes: InkData[] = [];
+    // @observable public strokes: InkData[] = [];
+    private _addToDocFunc: (strokeList: InkData[]) => void = () => {};
 
     constructor(props: any) {
         super(props);
@@ -42,10 +42,11 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
     };
 
     @action
-    displaySmartDrawHandler = (x: number, y: number) => {
+    displaySmartDrawHandler = (x: number, y: number, addToDoc: (strokeList: InkData[]) => void) => {
         this._pageX = x;
         this._pageY = y;
         this._display = true;
+        this._addToDocFunc = addToDoc;
     };
 
     @action
@@ -54,8 +55,11 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
     };
 
     @action
-    drawWithGPT = async (startPoint: {X: number, Y: number}, input: string) => {
-        console.log("start point is", startPoint);
+    waitForCoords = async () => {};
+
+    @action
+    drawWithGPT = async (startPoint: { X: number; Y: number }, input: string) => {
+        console.log('start point is', startPoint);
         this.setIsLoading(true);
         try {
             const res = await gptAPICall(input, GPTCallType.DRAW);
@@ -63,8 +67,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
                 console.error('GPT call failed');
                 return;
             }
-            console.log("GPT response:", res);
-            try {
+            console.log('GPT response:', res);
                 // const controlPts: [number, number][][] = JSON.parse(res) as [number, number][][];
                 // console.log("Control Points", controlPts);
                 // const transformedPts: { X: number; Y: number }[][] = [];
@@ -74,15 +77,17 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
                 //     });
                 //     transformedPts.push(stroke);
                 // });
+            const simplifiedRes: string = res.replace(/[^\d\[\],]/g, '');
+            console.log(simplifiedRes)
+            try {
+                const controlPts: { X: number; Y: number }[][] = JSON.parse(simplifiedRes).map((stroke: [number, number][]) => stroke.map(([X, Y]) => ({ X: X + startPoint.X, Y: Y + startPoint.Y })));
+                console.log('transformed points', controlPts);
 
-                const controlPts: { X: number; Y: number }[][] = JSON.parse(res).map((stroke: [number, number][]) => 
-                    stroke.map(([X, Y]) => ({ X: X + startPoint.X, Y: Y + startPoint.Y })));
-                console.log("transformed points", controlPts);
-                this.strokes = controlPts;
+                // this.strokes = controlPts;
+                this._addToDocFunc(controlPts);
             } catch (err) {
                 console.error('Incompatible GPT output type');
             }
-
         } catch (err) {
             console.error('GPT call failed', err);
         }
@@ -124,7 +129,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
                             iconPlacement="right"
                             color={MarqueeOptionsMenu.Instance.userColor}
                             onClick={e => {
-                                this.drawWithGPT({X: e.clientX, Y: e.clientY}, this._userInput);
+                                this.drawWithGPT({ X: e.clientX, Y: e.clientY }, this._userInput);
                             }}
                         />
                         {/* <IconButton
-- 
cgit v1.2.3-70-g09d2

