mirror of
https://github.com/docmost/docmost.git
synced 2026-09-11 07:56:54 +08:00
feat(beta): public spaces (#2473)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { useMemo } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useDocsSurface } from "@/features/public-space/components/docs/docs-surface-context.tsx";
|
||||
import { flattenTreePreorder } from "@/features/public-space/utils/docs-tree.ts";
|
||||
import { extractPageSlugId } from "@/lib";
|
||||
import { SharedPageTreeNode } from "@/features/share/utils.ts";
|
||||
|
||||
export function useDocsCurrentPage(): SharedPageTreeNode | null {
|
||||
const { pageSlug } = useParams();
|
||||
const { treeData } = useDocsSurface();
|
||||
|
||||
return useMemo(() => {
|
||||
if (!treeData?.length) return null;
|
||||
const currentSlugId = pageSlug
|
||||
? extractPageSlugId(pageSlug)
|
||||
: treeData[0]?.slugId;
|
||||
return (
|
||||
flattenTreePreorder(treeData).find(
|
||||
(node) => node.slugId === currentSlugId,
|
||||
) ?? null
|
||||
);
|
||||
}, [treeData, pageSlug]);
|
||||
}
|
||||
Reference in New Issue
Block a user