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