From 9deb9268b57960c08279601b481df6ad6907aa37 Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:36:57 +0530 Subject: [PATCH 1/2] fix: Skip events for sourced group memberships (#8286) --- server/models/GroupMembership.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/models/GroupMembership.ts b/server/models/GroupMembership.ts index e5db285eabc8..29a17f446f32 100644 --- a/server/models/GroupMembership.ts +++ b/server/models/GroupMembership.ts @@ -344,6 +344,7 @@ class GroupMembership extends ParanoidModel< }, { transaction, + hooks: false, } ); } From 5a45b95a48cc1da009f5d30e6a81edf46533d70a Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Thu, 23 Jan 2025 18:42:34 +0530 Subject: [PATCH 2/2] fix: Render TOC only when the shared document has headings (#8264) * fix: Render TOC only when the shared document has headings * simplify condition * fix inconsistent toc button state * toc visible check * remove shareHasHeadings prop --- app/scenes/Document/Shared.tsx | 48 ++++++++++----------- app/scenes/Document/components/Document.tsx | 16 ++++--- app/scenes/Document/components/Header.tsx | 15 +++++-- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/app/scenes/Document/Shared.tsx b/app/scenes/Document/Shared.tsx index 6e9e113c2394..d28bd6829a86 100644 --- a/app/scenes/Document/Shared.tsx +++ b/app/scenes/Document/Shared.tsx @@ -217,33 +217,31 @@ function SharedDocumentScene(props: Props) { ); } -const SharedDocument = ({ - shareId, - response, -}: { - shareId?: string; - response: Response; -}) => { - const { setDocument } = useDocumentContext(); - - if (!response.document) { - return null; - } +const SharedDocument = observer( + ({ shareId, response }: { shareId?: string; response: Response }) => { + const { hasHeadings, setDocument } = useDocumentContext(); - const tocPosition = response.team?.tocPosition ?? TOCPosition.Left; - setDocument(response.document); + if (!response.document) { + return null; + } - return ( - - ); -}; + const tocPosition = hasHeadings + ? response.team?.tocPosition ?? TOCPosition.Left + : false; + setDocument(response.document); + + return ( + + ); + } +); const Content = styled(Text)` color: ${s("textSecondary")}; diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index f98a938b18e4..5e43f0b28b00 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -89,7 +89,7 @@ type Props = WithTranslation & revision?: Revision; readOnly: boolean; shareId?: string; - tocPosition?: TOCPosition; + tocPosition?: TOCPosition | false; onCreateLink?: ( params: Properties, nested?: boolean @@ -438,13 +438,15 @@ class DocumentScene extends React.Component { const embedsDisabled = (team && team.documentEmbeds === false) || document.embedsDisabled; - const showContents = - (ui.tocVisible === true && !document.isTemplate) || - (isShare && ui.tocVisible !== false); const tocPos = tocPosition ?? ((team?.getPreference(TeamPreference.TocPosition) as TOCPosition) || TOCPosition.Left); + const showContents = + tocPos && + (isShare + ? ui.tocVisible !== false + : !document.isTemplate && ui.tocVisible === true); const multiplayerEditor = !document.isArchived && !document.isDeleted && !revision && !isShare; @@ -622,7 +624,7 @@ class DocumentScene extends React.Component { type MainProps = { fullWidth: boolean; - tocPosition: TOCPosition; + tocPosition: TOCPosition | false; }; const Main = styled.div` @@ -650,7 +652,7 @@ const Main = styled.div` type ContentsContainerProps = { docFullWidth: boolean; - position: TOCPosition; + position: TOCPosition | false; }; const ContentsContainer = styled.div` @@ -668,7 +670,7 @@ const ContentsContainer = styled.div` type EditorContainerProps = { docFullWidth: boolean; showContents: boolean; - tocPosition: TOCPosition; + tocPosition: TOCPosition | false; }; const EditorContainer = styled.div` diff --git a/app/scenes/Document/components/Header.tsx b/app/scenes/Document/components/Header.tsx index f1e775c01fa3..02a841f6f0ab 100644 --- a/app/scenes/Document/components/Header.tsx +++ b/app/scenes/Document/components/Header.tsx @@ -96,6 +96,7 @@ function DocumentHeader({ const ref = React.useRef(null); const size = useComponentSize(ref); const isMobile = isMobileMedia || size.width < 700; + const isShare = !!shareId; // 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 @@ -109,8 +110,13 @@ function DocumentHeader({ }, [onSave]); const handleToggle = React.useCallback(() => { - ui.set({ tocVisible: !ui.tocVisible }); - }, [ui]); + // Public shares, by default, show ToC on load. + if (isShare && ui.tocVisible === undefined) { + ui.set({ tocVisible: false }); + } else { + ui.set({ tocVisible: !ui.tocVisible }); + } + }, [ui, isShare]); const context = useActionContext({ activeDocumentId: document?.id, @@ -120,7 +126,6 @@ function DocumentHeader({ const { isDeleted, isTemplate } = document; const isTemplateEditable = can.update && isTemplate; const canToggleEmbeds = team?.documentEmbeds; - const isShare = !!shareId; const showContents = (ui.tocVisible === true && !document.isTemplate) || (isShare && ui.tocVisible !== false); @@ -212,7 +217,9 @@ function DocumentHeader({ hasSidebar={sharedTree && sharedTree.children?.length > 0} left={ isMobile ? ( - + hasHeadings ? ( + + ) : null ) : (