From 2277349fc4d5460e94a7a6b705b56488c0efb184 Mon Sep 17 00:00:00 2001
From: eleanor-park <eleanor_park@brown.edu>
Date: Thu, 6 Jun 2024 13:14:41 -0400
Subject: working on creating ink strokes from pts

---
 .../collectionFreeForm/SmartDrawHandler.tsx        | 27 +++++++++++++++++-----
 1 file changed, 21 insertions(+), 6 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 fc88b5cc6..7e66a62d4 100644
--- a/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
+++ b/src/client/views/collections/collectionFreeForm/SmartDrawHandler.tsx
@@ -23,7 +23,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
     @observable private _yRelativeToTop: boolean = true;
     @observable private _isLoading: boolean = false;
     @observable private _userInput: string = '';
-    @observable public coords: InkData | undefined = undefined;
+    @observable public strokes: InkData[] = [];
 
     constructor(props: any) {
         super(props);
@@ -55,6 +55,7 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
 
     @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,13 +64,27 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> {
                 return;
             }
             console.log("GPT response:", res);
-            // controlPts: {X: number, Y: number}[] = []
-            // code to extract list of coords from the string
-            // this.coords = controlPts.map(pt: {X: number, Y: number } => {pt.X + startPoint.X, pt.Y + startPoint.Y});
-           
+            try {
+                // const controlPts: [number, number][][] = JSON.parse(res) as [number, number][][];
+                // console.log("Control Points", controlPts);
+                // const transformedPts: { X: number; Y: number }[][] = [];
+                // controlPts.forEach(stroke => {
+                //     stroke.map(pt => {
+                //         pt.X += startPoint.X, pt.Y += startPoint.Y;
+                //     });
+                //     transformedPts.push(stroke);
+                // });
+
+                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;
+            } catch (err) {
+                console.error('Incompatible GPT output type');
+            }
 
         } catch (err) {
-            console.error('GPT call failed');
+            console.error('GPT call failed', err);
         }
 
         this.setIsLoading(false);
-- 
cgit v1.2.3-70-g09d2

