From e7162baa77a851d73037c63b75fac6a5c07f9b61 Mon Sep 17 00:00:00 2001
From: eleanor-park <eleanor_park@brown.edu>
Date: Sat, 14 Dec 2024 14:13:59 -0500
Subject: replaced await in loop, added a componentWillUnmount to reset sticker
 palette

---
 src/client/views/smartdraw/StickerPalette.tsx | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

(limited to 'src/client/views/smartdraw/StickerPalette.tsx')

diff --git a/src/client/views/smartdraw/StickerPalette.tsx b/src/client/views/smartdraw/StickerPalette.tsx
index 468d0fd13..d56878f10 100644
--- a/src/client/views/smartdraw/StickerPalette.tsx
+++ b/src/client/views/smartdraw/StickerPalette.tsx
@@ -56,6 +56,10 @@ export class StickerPalette extends ObservableReactComponent<StickerPaletteProps
         makeObservable(this);
     }
 
+    componentWillUnmount() {
+        this.resetPalette(true);
+    }
+
     public static LayoutString(fieldKey: string) {
         return FieldView.LayoutString(StickerPalette, fieldKey);
     }
@@ -145,19 +149,15 @@ export class StickerPalette extends ObservableReactComponent<StickerPaletteProps
     generateDrawings = action(async () => {
         this._isLoading = true;
         this._props.Document[DocData].data = undefined;
-        for (let i = 0; i < 3; i++) {
-            try {
-                SmartDrawHandler.Instance.AddDrawing = this.addDrawing;
-                this._canInteract = false;
-                if (this._showRegenerate) {
-                    await SmartDrawHandler.Instance.regenerate(this._opts, this._gptRes[i], this._userInput);
-                } else {
-                    await SmartDrawHandler.Instance.drawWithGPT({ X: 0, Y: 0 }, this._userInput, this._opts.complexity, this._opts.size, this._opts.autoColor);
-                }
-            } catch (e) {
-                console.log('Error generating drawing', e);
-            }
-        }
+        SmartDrawHandler.Instance.AddDrawing = this.addDrawing;
+        this._canInteract = false;
+        await Promise.all(
+            Array.from({ length: 3 }).map((_, i) => {
+                return this._showRegenerate
+                    ? SmartDrawHandler.Instance.regenerate(this._opts, this._gptRes[i], this._userInput)
+                    : SmartDrawHandler.Instance.drawWithGPT({ X: 0, Y: 0 }, this._userInput, this._opts.complexity, this._opts.size, this._opts.autoColor);
+            })
+        );
         this._opts.text !== '' ? (this._opts.text = `${this._opts.text} ~~~ ${this._userInput}`) : (this._opts.text = this._userInput);
         this._userInput = '';
         this._isLoading = false;
-- 
cgit v1.2.3-70-g09d2

