aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/smartdraw/StickerPalette.tsx
diff options
context:
space:
mode:
authoreleanor-park <eleanor_park@brown.edu>2024-12-14 14:13:59 -0500
committereleanor-park <eleanor_park@brown.edu>2024-12-14 14:13:59 -0500
commite7162baa77a851d73037c63b75fac6a5c07f9b61 (patch)
treedaa0ed49a471f67ad7641a90aea6d1aebbfaadfa /src/client/views/smartdraw/StickerPalette.tsx
parente6a4b7c05899ee6d6a821666b72023856081d5ca (diff)
replaced await in loop, added a componentWillUnmount to reset sticker palette
Diffstat (limited to 'src/client/views/smartdraw/StickerPalette.tsx')
-rw-r--r--src/client/views/smartdraw/StickerPalette.tsx26
1 files changed, 13 insertions, 13 deletions
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;