mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-12 15:52:32 +10:00
fix tree state
This commit is contained in:
@ -88,6 +88,8 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
|
||||
if (pagesData?.pages && !hasNextPage) {
|
||||
const allItems = pagesData.pages.flatMap((page) => page.items);
|
||||
const treeData = buildTree(allItems);
|
||||
console.log("tree data init");
|
||||
console.log("items", treeData);
|
||||
if (data.length < 1 || data?.[0].spaceId !== spaceId) {
|
||||
//Thoughts
|
||||
// don't reset if there is data in state
|
||||
@ -106,7 +108,7 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
|
||||
const fetchData = async () => {
|
||||
if (isDataLoaded.current && currentPage) {
|
||||
// check if pageId node is present in the tree
|
||||
const node = dfs(treeApiRef.current.root, currentPage.id);
|
||||
const node = dfs(treeApiRef.current?.root, currentPage.id);
|
||||
if (node) {
|
||||
// if node is found, no need to traverse its ancestors
|
||||
return;
|
||||
|
||||
@ -52,6 +52,8 @@ export function useTreeMutation<T>(spaceId: string) {
|
||||
slugId: createdPage.slugId,
|
||||
name: "",
|
||||
position: createdPage.position,
|
||||
spaceId: createdPage.spaceId,
|
||||
parentPageId: createdPage.parentPageId,
|
||||
children: [],
|
||||
} as any;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user