From b6ed6542f911694c673b9e324d7387ea16dc7d0b Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Thu, 7 Nov 2024 23:37:49 -0500
Subject: template reset option and fixed preview not rendering on edits after
 1st

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx    | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 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 fe91254f8..48f87ebfe 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> {
     @action updateTemplatePreview = (template: Template) => {
         template.renderUpdates();
         const preview = {template: template, doc: template.getRenderedDoc()};
-        this._suggestedTemplatePreviews.map(t => { return t.template === preview.template ? preview : t }); //prettier-ignore
+        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[]) => {
@@ -740,10 +740,12 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         this.closeMenu();
     }
 
-    @action setExpandedView = (doc: Doc | undefined) => {
-        if (doc) {
-            this._expandedPreview = doc; //Docs.Create.FreeformDocument([doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''});
+    @action setExpandedView = (template: Template | undefined) => {
+        if (template) {
+            this._currEditingTemplate = template;
+            this._expandedPreview = template.mainField.renderedDoc(); //Docs.Create.FreeformDocument([doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''});
         } else {
+            this._currEditingTemplate = undefined;
             this._expandedPreview = undefined;
         }
     };
@@ -781,10 +783,13 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                 <div className="top-panel"/>
                 {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)})}>
+                    <button className="docCreatorMenu-menu-button section-reveal-options top-right" onPointerDown={e => this.setUpButtonClick(e, () => {
+                        this._currEditingTemplate && this.updateTemplatePreview(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._expandedPreview && this._currEditingTemplate && this.addUserTemplate(this._currEditingTemplate))}>
+                    <button className="docCreatorMenu-menu-button section-reveal-options top-right-lower" onPointerDown={e => this.setUpButtonClick(e, () => {this._currEditingTemplate?.resetToBase(); this.setExpandedView(this._currEditingTemplate);})}>
                         <FontAwesomeIcon icon="plus" color="white" />
                     </button>
                 </div>
@@ -832,7 +837,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                                     className="option-button left"
                                                     onPointerDown={e =>
                                                         this.setUpButtonClick(e, () => {
-                                                            this.setExpandedView(template.getRenderedDoc());
+                                                            this.setExpandedView(template);
                                                         })
                                                     }>
                                                     <FontAwesomeIcon icon="magnifying-glass" color="white" />
@@ -901,7 +906,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                                 className="option-button left"
                                                 onPointerDown={e =>
                                                     this.setUpButtonClick(e, () => {
-                                                        this.setExpandedView(template.getRenderedDoc());
+                                                        this.setExpandedView(template);
                                                     })
                                                 }>
                                                 <FontAwesomeIcon icon="magnifying-glass" color="white" />
-- 
cgit v1.2.3-70-g09d2

