diff --git a/apps/client/public/locales/de-DE/translation.json b/apps/client/public/locales/de-DE/translation.json index 4b81d2970a..b978e0b140 100644 --- a/apps/client/public/locales/de-DE/translation.json +++ b/apps/client/public/locales/de-DE/translation.json @@ -801,5 +801,6 @@ "Google Drive": "Google Drive", "Embed Google Drive content": "Google Drive-Inhalte einbetten", "Google Sheets": "Google Sheets", - "Embed Google Sheets content": "Google Sheets-Inhalte einbetten" + "Embed Google Sheets content": "Google Sheets-Inhalte einbetten", + "Not available": "Nicht verfügbar" } diff --git a/apps/client/public/locales/en-US/translation.json b/apps/client/public/locales/en-US/translation.json index f2535e65f2..2d464e18b8 100644 --- a/apps/client/public/locales/en-US/translation.json +++ b/apps/client/public/locales/en-US/translation.json @@ -816,5 +816,6 @@ "Google Drive": "Google Drive", "Embed Google Drive content": "Embed Google Drive content", "Google Sheets": "Google Sheets", - "Embed Google Sheets content": "Embed Google Sheets content" + "Embed Google Sheets content": "Embed Google Sheets content", + "Not available": "Not available" } 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 6953a37d2e..e2a6dfc245 100644 --- a/apps/client/src/features/editor/components/mention/mention-view.tsx +++ b/apps/client/src/features/editor/components/mention/mention-view.tsx @@ -1,8 +1,12 @@ import { NodeViewProps, NodeViewWrapper } from "@tiptap/react"; -import { ActionIcon, Anchor, Text } from "@mantine/core"; +import { ActionIcon, Anchor, Text, Tooltip } from "@mantine/core"; +import { useTranslation } from "react-i18next"; 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 { useAtomValue } from "jotai"; +import { sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom"; +import { isPageInTree } from "@/features/share/utils"; import { buildPageUrl, buildSharedPageUrl, @@ -17,18 +21,28 @@ const truncateText = (text: string, maxLength: number = 30): string => { export default function MentionView(props: NodeViewProps) { const { node } = props; - const { label, entityType, entityId, slugId, anchorSlug, anchorText } = node.attrs; + const { t } = useTranslation(); + const { label, entityType, slugId, anchorSlug, anchorText } = node.attrs; const { spaceSlug, pageSlug } = useParams(); const { shareId } = useParams(); const navigate = useNavigate(); + const sharedTreeData = useAtomValue(sharedTreeDataAtom); + + const location = useLocation(); + const isShareRoute = location.pathname.startsWith("/share"); + const { data: page, - isLoading, isError, - } = usePageQuery({ pageId: entityType === "page" ? slugId : null }); + } = usePageQuery({ + pageId: entityType === "page" && !isShareRoute ? slugId : null, + }); - const location = useLocation(); - const isShareRoute = location.pathname.startsWith("/share"); + const isPageAvailableInShareTree = + isShareRoute && + !!sharedTreeData && + entityType === "page" && + isPageInTree(sharedTreeData, slugId); const currentPageSlugId = extractPageSlugId(pageSlug); const isSamePage = currentPageSlugId === slugId; @@ -51,7 +65,9 @@ export default function MentionView(props: NodeViewProps) { anchorId: anchorSlug, }); - const pageUrl = buildPageUrl(spaceSlug, slugId, label, anchorSlug); + const canNavigateToPageMention = + entityType === "page" && + (isShareRoute ? isPageAvailableInShareTree : !isError); return ( @@ -61,13 +77,15 @@ export default function MentionView(props: NodeViewProps) { )} - {entityType === "page" && isError && ( - - {label} - + {entityType === "page" && !canNavigateToPageMention && ( + + + {label} + + )} - {entityType === "page" && !isError && ( + {entityType === "page" && canNavigateToPageMention && (