From e222d796534a2efaed48641c8e480f1b7982811b Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Tue, 29 Oct 2024 23:53:12 -0400
Subject: templates are being generated correctly

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 62 ++--------------------
 1 file changed, 5 insertions(+), 57 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index 405b32e8a..24a05fd71 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -114,6 +114,11 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     };
     @action setGSuggestedTemplates = (docs: Doc[]) => {
         this._suggestedTemplates = docs;
+
+        const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+        docs.forEach(doc => {
+            mainCollection.addDocument(doc);
+        });
     };
 
     @computed get docsToRender() {
@@ -398,63 +403,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         return this._layout.xMargin === layout.layout.xMargin && this._layout.yMargin === layout.layout.yMargin && this._layout.type === layout.layout.type && this._layout.columns === layout.columns;
     };
 
-    @action
-    generateTemplates = async (inputText: string) => {
-        ++this._callCount;
-        const origCount = this._callCount;
-
-        let prompt: string = `(#${origCount}) Please generate for the fields:`;
-        this.selectedFields?.forEach(field => (prompt += ` ${field},`));
-        prompt += ` (-----NOT A FIELD-----) Additional prompt: ${inputText}`;
-
-        this._GPTLoading = true;
-
-        try {
-            const res = await gptAPICall(prompt, GPTCallType.TEMPLATE);
-
-            if (res && this._callCount === origCount) {
-                this._suggestedTemplates = [];
-                const templates: { template_type: string; fieldVals: { title: string; tlx: string; tly: string; brx: string; bry: string }[] }[] = JSON.parse(res);
-                this.createGeneratedTemplates(templates, 500, 500);
-            }
-        } catch (err) {
-            console.error(err);
-        }
-    };
-
-    @action
-    createGeneratedTemplates = (layouts: { template_type: string; fieldVals: { title: string; tlx: string; tly: string; brx: string; bry: string }[] }[], tempWidth: number, tempHeight: number) => {
-        const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
-        const GPTTemplates: Doc[] = [];
-
-        layouts.forEach(layout => {
-            const fields: Doc[] = layout.fieldVals.map(field => {
-                const left: number = (Number(field.tlx) * tempWidth) / 2;
-                const top: number = Number(field.tly) * tempHeight / 2; //prettier-ignore
-                const right: number = (Number(field.brx) * tempWidth) / 2;
-                const bottom: number = Number(field.bry) * tempHeight / 2; //prettier-ignore
-                const height = bottom - top;
-                const width = right - left;
-                const doc = !field.title.includes('$$')
-                    ? Docs.Create.TextDocument('', { _height: height, _width: width, title: field.title, x: left, y: top, _text_fontSize: `${height / 2}` })
-                    : Docs.Create.ImageDocument('', { _height: height, _width: width, title: field.title.replace(/\$\$/g, ''), x: left, y: top });
-                return doc;
-            });
-
-            const template = Docs.Create.FreeformDocument(fields, { _height: tempHeight, _width: tempWidth, title: layout.template_type, x: 400000, y: 400000 });
-
-            mainCollection.addDocument(template);
-
-            GPTTemplates.push(template);
-        });
-
-        setTimeout(() => {
-            this.setGSuggestedTemplates(GPTTemplates); /*GPTTemplates.forEach(template => mainCollection.removeDocument(template))*/
-        }, 100);
-
-        this.forceUpdate();
-    };
-
     editTemplate = (doc: Doc) => {
         //this.closeMenu();
         DocumentViewInternal.addDocTabFunc(doc, OpenWhere.addRight);
-- 
cgit v1.2.3-70-g09d2

