From 752137754b2f544ad08106934a1f5c9ce03408a2 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Wed, 30 Oct 2024 00:34:43 -0400
Subject: docs loading properly into preview

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 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 24a05fd71..ad7aa7cb9 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -114,11 +114,6 @@ 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() {
@@ -415,8 +410,10 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     };
 
     testTemplate = async () => {
-        
-        console.log(this.templateManager.templates);
+
+        console.log(this._suggestedTemplates
+            ?.map(doc => ({ icon: ImageCast(doc.icon), doc }))
+            .filter(info => info.icon && info.doc));
 
         this.forceUpdate();
 
@@ -672,6 +669,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                     );
                     brokenDownAssignments.push([template, toObj]);
                 });
+
                 return brokenDownAssignments;
             }
         } catch (err) {
@@ -691,10 +689,18 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
         const renderedTemplatePromises: Promise<Template>[] = assignments.map(([template, assignments]) => this.applyGPTContentToTemplate(template, assignments));
 
-        const renderedTemplates: Template[] = await Promise.all(renderedTemplatePromises);
+        //const renderedTemplates: Template[] = await Promise.all(renderedTemplatePromises);
+
+        const renderedTemplates: Doc[] = templates.map(template => template.mainField.renderedDoc());
+
+        const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+        
+        renderedTemplates.forEach(doc => {
+            mainCollection.addDocument(doc);
+        });
 
         setTimeout(() => {
-            this.setGSuggestedTemplates(templates.map(template => template.mainField.renderedDoc()));
+            this.setGSuggestedTemplates(renderedTemplates);
             this._GPTLoading = false;
         });
     };
-- 
cgit v1.2.3-70-g09d2

