fix tree state

This commit is contained in:
Philipinho
2024-07-05 00:30:56 +01:00
parent cc93abfb7e
commit a4d53468c3
2 changed files with 5 additions and 1 deletions

View File

@ -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;