fix: sidebar list when changing workspace (#1150)

* init

* navigate in overview if current page is in deleted node

* fix: implement pagination in sidebar-pages queries

* fix: appendNodeChildren()

Preserve deeper children if they exist and remove node if deleted
This commit is contained in:
fuscodev
2025-06-08 04:27:09 +02:00
committed by GitHub
parent 69447fc375
commit ce1503af85
9 changed files with 326 additions and 59 deletions

View File

@ -1,4 +1,5 @@
import { SpaceTreeNode } from "@/features/page/tree/types.ts";
import { IPage } from "@/features/page/types/page.types";
export type InvalidateEvent = {
operation: "invalidate";
@ -17,7 +18,7 @@ export type UpdateEvent = {
spaceId: string;
entity: Array<string>;
id: string;
payload: Partial<any>;
payload: Partial<IPage>;
};
export type DeleteEvent = {
@ -25,7 +26,7 @@ export type DeleteEvent = {
spaceId: string;
entity: Array<string>;
id: string;
payload?: Partial<any>;
payload?: Partial<IPage>;
};
export type AddTreeNodeEvent = {

View File

@ -1,8 +1,11 @@
import React from "react";
import { socketAtom } from "@/features/websocket/atoms/socket-atom.ts";
import { useAtom } from "jotai";
import { useQueryClient } from "@tanstack/react-query";
import { InfiniteData, useQueryClient } from "@tanstack/react-query";
import { WebSocketEvent } from "@/features/websocket/types";
import { IPage } from "../page/types/page.types";
import { IPagination } from "@/lib/types";
import { invalidateOnCreatePage, invalidateOnDeletePage, invalidateOnMovePage, invalidateOnUpdatePage } from "../page/queries/page-query";
import { RQ_KEY } from "../comment/queries/comment-query";
export const useQuerySubscription = () => {
@ -27,6 +30,16 @@ export const useQuerySubscription = () => {
queryKey: RQ_KEY(data.pageId),
});
break;
case "addTreeNode":
invalidateOnCreatePage(data.payload.data);
break;
case "moveTreeNode":
invalidateOnMovePage();
break;
case "deleteTreeNode":
const pageId = data.payload.node.id;
invalidateOnDeletePage(pageId);
break;
case "updateOne":
entity = data.entity[0];
if (entity === "pages") {
@ -43,7 +56,11 @@ export const useQuerySubscription = () => {
...data.payload,
});
}
if (entity === "pages") {
invalidateOnUpdatePage(data.spaceId, data.payload.parentPageId, data.id, data.payload.title, data.payload.icon);
}
/*
queryClient.setQueriesData(
{ queryKey: [data.entity, data.id] },
@ -55,7 +72,7 @@ export const useQuerySubscription = () => {
: update(oldData as Record<string, unknown>);
},
);
*/
*/
break;
}
});