From fc564cfc1aa3d18d230f9c056a58b8a138d2dba9 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 8 Jan 2022 16:04:50 -0800 Subject: [PATCH] fix: Templates menu does not appear in collab editing (#2915) * fix: Templates menu does not appear in collab editing * Improved logic for display templates menu --- app/scenes/Document/components/Document.tsx | 6 ++++++ app/scenes/Document/components/Header.tsx | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index 038bd1df9..02d23b40d 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -161,9 +161,15 @@ class DocumentScene extends React.Component { this.props.document.templateId = template.id; } + this.title = template.title; this.props.document.title = template.title; this.props.document.text = template.text; this.updateIsDirty(); + this.onSave({ + autosave: true, + publish: false, + done: false, + }); }; onSynced = async () => { diff --git a/app/scenes/Document/components/Header.tsx b/app/scenes/Document/components/Header.tsx index d073828f9..6a310cc38 100644 --- a/app/scenes/Document/components/Header.tsx +++ b/app/scenes/Document/components/Header.tsx @@ -78,6 +78,11 @@ function DocumentHeader({ const { team } = auth; const isMobile = useMobile(); + // We cache this value for as long as the component is mounted so that if you + // apply a template there is still the option to replace it until the user + // navigates away from the doc + const [isNew] = React.useState(document.isPersistedOnce); + const handleSave = React.useCallback(() => { onSave({ done: true, @@ -91,7 +96,6 @@ function DocumentHeader({ }); }, [onSave]); - const isNew = document.isPersistedOnce; const isTemplate = document.isTemplate; const can = policies.abilities(document.id); const canToggleEmbeds = team?.documentEmbeds; @@ -205,7 +209,7 @@ function DocumentHeader({ {t("Saving")}… )} - {isEditing && !isTemplate && isNew && ( + {(isEditing || team?.collaborativeEditing) && !isTemplate && isNew && (