mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix shared page mention view for non-logged in users (#2008)
This commit is contained in:
@@ -3,6 +3,7 @@ import { ActionIcon, Anchor, Text } from "@mantine/core";
|
|||||||
import { IconFileDescription } from "@tabler/icons-react";
|
import { IconFileDescription } from "@tabler/icons-react";
|
||||||
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
import { usePageQuery } from "@/features/page/queries/page-query.ts";
|
import { usePageQuery } from "@/features/page/queries/page-query.ts";
|
||||||
|
import { useSharePageQuery } from "@/features/share/queries/share-query.ts";
|
||||||
import {
|
import {
|
||||||
buildPageUrl,
|
buildPageUrl,
|
||||||
buildSharedPageUrl,
|
buildSharedPageUrl,
|
||||||
@@ -13,17 +14,23 @@ import classes from "./mention.module.css";
|
|||||||
export default function MentionView(props: NodeViewProps) {
|
export default function MentionView(props: NodeViewProps) {
|
||||||
const { node } = props;
|
const { node } = props;
|
||||||
const { label, entityType, entityId, slugId, anchorId } = node.attrs;
|
const { label, entityType, entityId, slugId, anchorId } = node.attrs;
|
||||||
|
const isPageMention = entityType === "page";
|
||||||
const { spaceSlug, pageSlug } = useParams();
|
const { spaceSlug, pageSlug } = useParams();
|
||||||
const { shareId } = useParams();
|
const { shareId } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const isShareRoute = location.pathname.startsWith("/share");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: page,
|
data: page,
|
||||||
isLoading,
|
isLoading,
|
||||||
isError,
|
isError,
|
||||||
} = usePageQuery({ pageId: entityType === "page" ? slugId : null });
|
} = usePageQuery({ pageId: isPageMention && !isShareRoute ? slugId : null });
|
||||||
|
|
||||||
const location = useLocation();
|
const { data: sharedPage } = useSharePageQuery({
|
||||||
const isShareRoute = location.pathname.startsWith("/share");
|
pageId: isPageMention && isShareRoute ? slugId : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
const currentPageSlugId = extractPageSlugId(pageSlug);
|
const currentPageSlugId = extractPageSlugId(pageSlug);
|
||||||
const isSamePage = currentPageSlugId === slugId;
|
const isSamePage = currentPageSlugId === slugId;
|
||||||
@@ -39,10 +46,12 @@ export default function MentionView(props: NodeViewProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sharePageTitle = sharedPage?.page?.title || label;
|
||||||
|
|
||||||
const shareSlugUrl = buildSharedPageUrl({
|
const shareSlugUrl = buildSharedPageUrl({
|
||||||
shareId,
|
shareId,
|
||||||
pageSlugId: slugId,
|
pageSlugId: slugId,
|
||||||
pageTitle: label,
|
pageTitle: sharePageTitle,
|
||||||
anchorId,
|
anchorId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,21 +63,59 @@ export default function MentionView(props: NodeViewProps) {
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{entityType === "page" && isError && (
|
{isPageMention && isShareRoute && (
|
||||||
<Text component="span" c="dimmed" size="sm">
|
|
||||||
{label}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{entityType === "page" && !isError && (
|
|
||||||
<Anchor
|
<Anchor
|
||||||
component={Link}
|
component={Link}
|
||||||
fw={500}
|
fw={500}
|
||||||
to={
|
to={shareSlugUrl}
|
||||||
isShareRoute
|
onClick={handleClick}
|
||||||
? shareSlugUrl
|
underline="never"
|
||||||
: buildPageUrl(page?.space?.slug || spaceSlug, slugId, page?.title || label, anchorId)
|
className={classes.pageMentionLink}
|
||||||
}
|
>
|
||||||
|
<ActionIcon
|
||||||
|
variant="transparent"
|
||||||
|
color="gray"
|
||||||
|
component="span"
|
||||||
|
size={18}
|
||||||
|
style={{ verticalAlign: "text-bottom" }}
|
||||||
|
>
|
||||||
|
<IconFileDescription size={18} />
|
||||||
|
</ActionIcon>
|
||||||
|
<span className={classes.pageMentionText}>
|
||||||
|
{sharePageTitle}
|
||||||
|
</span>
|
||||||
|
</Anchor>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isPageMention && !isShareRoute && isError && (
|
||||||
|
<Anchor
|
||||||
|
component={Link}
|
||||||
|
fw={500}
|
||||||
|
to={buildPageUrl(spaceSlug, slugId, label, anchorId)}
|
||||||
|
onClick={handleClick}
|
||||||
|
underline="never"
|
||||||
|
className={classes.pageMentionLink}
|
||||||
|
>
|
||||||
|
<ActionIcon
|
||||||
|
variant="transparent"
|
||||||
|
color="gray"
|
||||||
|
component="span"
|
||||||
|
size={18}
|
||||||
|
style={{ verticalAlign: "text-bottom" }}
|
||||||
|
>
|
||||||
|
<IconFileDescription size={18} />
|
||||||
|
</ActionIcon>
|
||||||
|
<span className={classes.pageMentionText}>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
</Anchor>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isPageMention && !isShareRoute && !isError && (
|
||||||
|
<Anchor
|
||||||
|
component={Link}
|
||||||
|
fw={500}
|
||||||
|
to={buildPageUrl(page?.space?.slug || spaceSlug, slugId, page?.title || label, anchorId)}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
underline="never"
|
underline="never"
|
||||||
className={classes.pageMentionLink}
|
className={classes.pageMentionLink}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ export default function SubpagesView(props: NodeViewProps) {
|
|||||||
// Get subpages from shared tree if we're in a shared context
|
// Get subpages from shared tree if we're in a shared context
|
||||||
const sharedSubpages = useSharedPageSubpages(currentPageId);
|
const sharedSubpages = useSharedPageSubpages(currentPageId);
|
||||||
|
|
||||||
const { data, isLoading, error } = useGetSidebarPagesQuery({
|
const { data, isLoading, error } = useGetSidebarPagesQuery(
|
||||||
pageId: currentPageId,
|
shareId ? null : { pageId: currentPageId },
|
||||||
});
|
);
|
||||||
|
|
||||||
const subpages = useMemo(() => {
|
const subpages = useMemo(() => {
|
||||||
// If we're in a shared context, use the shared subpages
|
// If we're in a shared context, use the shared subpages
|
||||||
|
|||||||
Reference in New Issue
Block a user