diff --git a/apps/client/src/features/editor/components/mention/mention-view.tsx b/apps/client/src/features/editor/components/mention/mention-view.tsx index a874cdf4..561f3e0f 100644 --- a/apps/client/src/features/editor/components/mention/mention-view.tsx +++ b/apps/client/src/features/editor/components/mention/mention-view.tsx @@ -3,6 +3,7 @@ import { ActionIcon, Anchor, Text } from "@mantine/core"; import { IconFileDescription } from "@tabler/icons-react"; import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; import { usePageQuery } from "@/features/page/queries/page-query.ts"; +import { useSharePageQuery } from "@/features/share/queries/share-query.ts"; import { buildPageUrl, buildSharedPageUrl, @@ -13,17 +14,23 @@ import classes from "./mention.module.css"; export default function MentionView(props: NodeViewProps) { const { node } = props; const { label, entityType, entityId, slugId, anchorId } = node.attrs; + const isPageMention = entityType === "page"; const { spaceSlug, pageSlug } = useParams(); const { shareId } = useParams(); const navigate = useNavigate(); + + const location = useLocation(); + const isShareRoute = location.pathname.startsWith("/share"); + const { data: page, isLoading, isError, - } = usePageQuery({ pageId: entityType === "page" ? slugId : null }); + } = usePageQuery({ pageId: isPageMention && !isShareRoute ? slugId : null }); - const location = useLocation(); - const isShareRoute = location.pathname.startsWith("/share"); + const { data: sharedPage } = useSharePageQuery({ + pageId: isPageMention && isShareRoute ? slugId : undefined, + }); const currentPageSlugId = extractPageSlugId(pageSlug); const isSamePage = currentPageSlugId === slugId; @@ -39,10 +46,12 @@ export default function MentionView(props: NodeViewProps) { } }; + const sharePageTitle = sharedPage?.page?.title || label; + const shareSlugUrl = buildSharedPageUrl({ shareId, pageSlugId: slugId, - pageTitle: label, + pageTitle: sharePageTitle, anchorId, }); @@ -54,21 +63,59 @@ export default function MentionView(props: NodeViewProps) { )} - {entityType === "page" && isError && ( - - {label} - - )} - - {entityType === "page" && !isError && ( + {isPageMention && isShareRoute && ( + + + + + {sharePageTitle} + + + )} + + {isPageMention && !isShareRoute && isError && ( + + + + + + {label} + + + )} + + {isPageMention && !isShareRoute && !isError && ( + { // If we're in a shared context, use the shared subpages