mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix(client): ensure sidebar remains visible on shared subpages (#1887)
* fix(client): ensure sidebar remains visible on shared subpages * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d2641db895
commit
4b105586a9
@@ -66,3 +66,20 @@ export function buildSharedPageTree(
|
|||||||
|
|
||||||
return sortTree(tree);
|
return sortTree(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Recursively checks if a page exists in the shared page tree.
|
||||||
|
export function isPageInTree(
|
||||||
|
tree: SharedPageTreeNode[],
|
||||||
|
pageSlugId: string,
|
||||||
|
): boolean {
|
||||||
|
for (const node of tree) {
|
||||||
|
if (node.slugId === pageSlugId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isPageInTree(node.children, pageSlugId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import ReadonlyPageEditor from "@/features/editor/readonly-page-editor.tsx";
|
|||||||
import { extractPageSlugId } from "@/lib";
|
import { extractPageSlugId } from "@/lib";
|
||||||
import { Error404 } from "@/components/ui/error-404.tsx";
|
import { Error404 } from "@/components/ui/error-404.tsx";
|
||||||
import ShareBranding from "@/features/share/components/share-branding.tsx";
|
import ShareBranding from "@/features/share/components/share-branding.tsx";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
import { sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom.ts";
|
||||||
|
import { isPageInTree } from "@/features/share/utils.ts";
|
||||||
|
|
||||||
export default function SharedPage() {
|
export default function SharedPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -19,13 +22,22 @@ export default function SharedPage() {
|
|||||||
pageId: extractPageSlugId(pageSlug),
|
pageId: extractPageSlugId(pageSlug),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sharedTreeData = useAtomValue(sharedTreeDataAtom);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shareId && data) {
|
if (shareId && data) {
|
||||||
if (data.share.key !== shareId) {
|
if (data.share.key !== shareId) {
|
||||||
navigate(`/share/${data.share.key}/p/${pageSlug}`, { replace: true });
|
|
||||||
|
// Check if the current page is part of the active sharing tree (sidebar) - If we are part of it, we will not redirect, keeping the sidebar visible.
|
||||||
|
const isPartOfTree =
|
||||||
|
sharedTreeData && isPageInTree(sharedTreeData, data.page.slugId);
|
||||||
|
|
||||||
|
if (!isPartOfTree) {
|
||||||
|
navigate(`/share/${data.share.key}/p/${pageSlug}`, { replace: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [shareId, data]);
|
}, [shareId, data, sharedTreeData]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <></>;
|
return <></>;
|
||||||
|
|||||||
Reference in New Issue
Block a user