From 61e6e938dc9e7efbbdb913bbfaa0d757f6c6b4cd Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 10 Jan 2026 11:46:43 -0500 Subject: [PATCH] refactor --- app/scenes/Document/components/Document.tsx | 3 +- .../Document/components/PublicReferences.tsx | 61 ------------------- app/scenes/Document/components/References.tsx | 35 ++++++++++- 3 files changed, 34 insertions(+), 65 deletions(-) delete mode 100644 app/scenes/Document/components/PublicReferences.tsx diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index 5f9aebc1fd..b9cabe470d 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -49,7 +49,6 @@ import Contents from "./Contents"; import Editor from "./Editor"; import Header from "./Header"; import Notices from "./Notices"; -import PublicReferences from "./PublicReferences"; import References from "./References"; import RevisionViewer from "./RevisionViewer"; @@ -608,7 +607,7 @@ class DocumentScene extends React.Component { > {shareId ? ( - + ) : !revision ? ( diff --git a/app/scenes/Document/components/PublicReferences.tsx b/app/scenes/Document/components/PublicReferences.tsx deleted file mode 100644 index 557bb78e2b..0000000000 --- a/app/scenes/Document/components/PublicReferences.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { observer } from "mobx-react"; -import { useMemo } from "react"; -import { useTranslation } from "react-i18next"; -import type { NavigationNode } from "@shared/types"; -import Subheading from "~/components/Subheading"; -import ReferenceListItem from "./ReferenceListItem"; -import useShare from "@shared/hooks/useShare"; - -type Props = { - documentId: string; -}; - -function PublicReferences(props: Props) { - const { t } = useTranslation(); - const { sharedTree } = useShare(); - const { documentId } = props; - - // The sharedTree is the entire document tree starting at the shared document - // we must filter down the tree to only the part with the document we're - // currently viewing - const children = useMemo(() => { - let result: NavigationNode[]; - - function findChildren(node?: NavigationNode) { - if (!node) { - return; - } - - if (node.id === documentId) { - result = node.children; - } else { - node.children.forEach((node) => { - if (result) { - return; - } - - findChildren(node); - }); - } - - return result; - } - - return findChildren(sharedTree) || []; - }, [documentId, sharedTree]); - - if (!children.length) { - return null; - } - - return ( - <> - {t("Documents")} - {children.map((node) => ( - - ))} - - ); -} - -export default observer(PublicReferences); diff --git a/app/scenes/Document/components/References.tsx b/app/scenes/Document/components/References.tsx index a2fbe5d9bf..fb88abd32b 100644 --- a/app/scenes/Document/components/References.tsx +++ b/app/scenes/Document/components/References.tsx @@ -1,5 +1,5 @@ import { observer } from "mobx-react"; -import { useEffect, useRef, Fragment } from "react"; +import { useEffect, useRef, Fragment, useMemo } from "react"; import { Trans } from "react-i18next"; import { useLocation } from "react-router-dom"; import styled from "styled-components"; @@ -12,6 +12,8 @@ import useCurrentUser from "~/hooks/useCurrentUser"; import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext"; import useStores from "~/hooks/useStores"; import ReferenceListItem from "./ReferenceListItem"; +import useShare from "@shared/hooks/useShare"; +import type { NavigationNode } from "@shared/types"; type Props = { document: Document; @@ -22,13 +24,42 @@ function References({ document }: Props) { const user = useCurrentUser(); const location = useLocation(); const locationSidebarContext = useLocationSidebarContext(); + const { sharedTree } = useShare(); useEffect(() => { void documents.fetchBacklinks(document.id); }, [documents, document.id]); + // The sharedTree is the entire document tree starting at the shared document + // we must filter down the tree to only the part with the document we're + // currently viewing + const children = useMemo(() => { + let result: NavigationNode[]; + + function findChildren(node?: NavigationNode) { + if (!node) { + return; + } + + if (node.id === document.id) { + result = node.children; + } else { + node.children.forEach((node) => { + if (result) { + return; + } + + findChildren(node); + }); + } + + return result; + } + + return sharedTree ? findChildren(sharedTree) || [] : document.children; + }, [document.id, sharedTree]); + const backlinks = document.backlinks; - const children = document.children; const showBacklinks = !!backlinks.length; const showChildDocuments = !!children.length; const shouldFade = useRef(!showBacklinks && !showChildDocuments);