From f02559f86c339d069743590bcac0c6d5407ecba8 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Thu, 19 Dec 2024 04:19:29 -0500
Subject: previewcollection updates automatically on closing editing window of
 selected template; removed redundant field updating now that everything is
 static; lots of comments to remove

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 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 69c896ccf..08583f594 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -118,7 +118,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         this._userTemplates = this._userTemplates.filter(info => info.template !== template);
     }
     @action updateTemplatePreview = (template: Template) => {
-        template.renderUpdates();
+        //template.renderUpdates();
         const preview = {template: template, doc: template.getRenderedDoc()};
         this._suggestedTemplatePreviews = this._suggestedTemplatePreviews.map(t => { return t.template === preview.template ? preview : t }); //prettier-ignore
         this._userTemplates = this._userTemplates.map(t => { return t.template === preview.template ? preview : t }); //prettier-ignore
@@ -361,15 +361,19 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         return undefined;
     }
 
+    @action updateRenderedPreviewCollection = async (template: Template) => {
+        this._fullyRenderedDocs = await this.createDocsFromTemplate(template) ?? [];
+        this.updateRenderedDocCollection();
+    }
+
     @action updateSelectedTemplate = async (template: Template) => {
         if (this._selectedTemplate === template) {
             this._selectedTemplate = undefined;
             return;
         } else {
             this._selectedTemplate = template;
-            template.renderUpdates();
-            this._fullyRenderedDocs = await this.createDocsFromTemplate(template) ?? [];
-            this.updateRenderedDocCollection();
+            //template.renderUpdates();
+            this.updateRenderedPreviewCollection(template);
         }
     };
 
@@ -759,6 +763,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
         return renderedDocs;
     }
+
+    
     
 
     addRenderedCollectionToMainview = () => {
@@ -814,9 +820,14 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                 {rendered}
                 <div className="right-buttons-panel">
                     <button className="docCreatorMenu-menu-button section-reveal-options top-right" onPointerDown={e => this.setUpButtonClick(e, () => {
-                        this._currEditingTemplate && this.updateTemplatePreview(this._currEditingTemplate); 
-                        this.setExpandedView(undefined)}
-                        )}>
+                        if (!this._currEditingTemplate) return; 
+                        if (this._currEditingTemplate === this._selectedTemplate) {
+                            this.updateTemplatePreview(this._currEditingTemplate);
+                            this.updateRenderedPreviewCollection(this._currEditingTemplate);
+                        }
+                        this.updateRenderedPreviewCollection(this._currEditingTemplate);
+                        this.setExpandedView(undefined);
+                        })}>
                         <FontAwesomeIcon icon="minimize" />
                     </button>
                     <button className="docCreatorMenu-menu-button section-reveal-options top-right-lower" onPointerDown={e => this.setUpButtonClick(e, () => {this._currEditingTemplate?.resetToBase(); this.setExpandedView(this._currEditingTemplate);})}>
@@ -1061,6 +1072,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     @type the type of collection the docs should render to (ie. freeform, carousel, card)
      */
     updateRenderedDocCollection = () => {
+        console.log('called');
         if (!this._fullyRenderedDocs) return;
 
         const { horizontalSpan, verticalSpan } = this.previewInfo;
@@ -1094,6 +1106,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         this.applyLayout(collection, this._fullyRenderedDocs);
 
         this._renderedDocCollection = collection;
+
+        console.log('changed');
     }
 
     layoutPreviewContents = (id?: number) => {
-- 
cgit v1.2.3-70-g09d2

