mirror of
https://github.com/docmost/docmost.git
synced 2026-09-11 07:56:54 +08:00
* feat: subpages list node * disable user-select * support subpages node list in public pages
30 lines
920 B
TypeScript
30 lines
920 B
TypeScript
import { useMemo } from "react";
|
|
import { useAtomValue } from "jotai";
|
|
import { sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom";
|
|
import { SharedPageTreeNode } from "@/features/share/utils";
|
|
|
|
export function useSharedPageSubpages(pageId: string | undefined) {
|
|
const treeData = useAtomValue(sharedTreeDataAtom);
|
|
|
|
return useMemo(() => {
|
|
if (!treeData || !pageId) return [];
|
|
|
|
function findSubpages(nodes: SharedPageTreeNode[]): SharedPageTreeNode[] {
|
|
for (const node of nodes) {
|
|
if (node.value === pageId || node.slugId === pageId) {
|
|
return node.children || [];
|
|
}
|
|
if (node.children && node.children.length > 0) {
|
|
const subpages = findSubpages(node.children);
|
|
if (subpages.length > 0) {
|
|
return subpages;
|
|
}
|
|
}
|
|
}
|
|
return [];
|
|
}
|
|
|
|
return findSubpages(treeData);
|
|
}, [treeData, pageId]);
|
|
}
|