From 12bd4313d188c5da1a68c1c7dbc3f7a3d01ff0d0 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Thu, 19 Dec 2024 05:40:21 -0500
Subject: simplified suggestedTemplates field by removing unecessary caching of
 rendered doc

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 23 +++++++---------------
 1 file changed, 7 insertions(+), 16 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 08583f594..505b7bd46 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -68,7 +68,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     @observable _savedLayouts: DataVizTemplateLayout[] = [];
     @observable _expandedPreview: Doc | undefined = undefined;
 
-    @observable _suggestedTemplatePreviews: {doc: Doc, template: Template}[] = [];
+    @observable _suggestedTemplates: Template[] = [];
     @observable _GPTOpt: boolean = false;
     @observable _callCount: number = 0;
     @observable _GPTLoading: boolean = false;
@@ -108,7 +108,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         this._selectedTemplate = undefined;
         this._renderedDocCollection = undefined;
         this._fullyRenderedDocs = [];
-        this._suggestedTemplatePreviews = [];
+        this._suggestedTemplates = [];
         this._userCreatedFields = [];
     };
     @action addUserTemplate = (template: Template) => {
@@ -117,14 +117,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     @action removeUserTemplate = (template: Template) => {
         this._userTemplates = this._userTemplates.filter(info => info.template !== template);
     }
-    @action updateTemplatePreview = (template: Template) => {
-        //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
-    };
     @action setSuggestedTemplates = (templates: Template[]) => {
-        this._suggestedTemplatePreviews = templates.map(template => {return {template: template, doc: template.getRenderedDoc()}}); //prettier-ignore
+        this._suggestedTemplates = templates; //prettier-ignore
     };
 
     @computed get docsToRender() {
@@ -397,7 +391,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
     testTemplate = async () => {
 
-        this._suggestedTemplatePreviews = this.templateManager.templates.map(template => {return {template: template, doc: template.getRenderedDoc()}}); //prettier-ignore
+        this._suggestedTemplates = this.templateManager.templates; //prettier-ignore
 
         //console.log(this.templateManager.templates)
 
@@ -822,10 +816,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                     <button className="docCreatorMenu-menu-button section-reveal-options top-right" onPointerDown={e => this.setUpButtonClick(e, () => {
                         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" />
@@ -839,7 +831,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     }
 
     get templatesPreviewContents() {
-        const renderedTemplates: Doc[] = [];
 
         const GPTOptions = <div></div>;
 
@@ -889,8 +880,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                         <ReactLoading type="spin" color={StrCast(Doc.UserDoc().userVariantColor)} height={30} width={30} />
                                     </div>
                                 ) : (
-                                    this._suggestedTemplatePreviews
-                                        .map(({doc, template}) => (
+                                    this._suggestedTemplates
+                                        .map(template => (
                                             <div
                                                 className="docCreatorMenu-preview-window"
                                                 style={{
@@ -910,7 +901,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                                 <button className="option-button right" onPointerDown={e => this.setUpButtonClick(e, () => this.addUserTemplate(template))}>
                                                     <FontAwesomeIcon icon="plus" color="white" />
                                                 </button>
-                                                {previewDoc(doc, template)}
+                                                {previewDoc(template.getRenderedDoc(), template)}
                                             </div>
                                         ))
                                 )}
-- 
cgit v1.2.3-70-g09d2

