mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
refactor(base): append remote row creates to cache instead of invalidating
This commit is contained in:
@@ -123,7 +123,22 @@ export function useBaseSocket(baseId: string | undefined): void {
|
|||||||
|
|
||||||
switch (event.operation) {
|
switch (event.operation) {
|
||||||
case "base:row:created": {
|
case "base:row:created": {
|
||||||
queryClient.invalidateQueries({ queryKey: ["base-rows", baseId] });
|
const e = event as BaseRowCreated;
|
||||||
|
queryClient.setQueriesData<InfiniteData<IPagination<IBaseRow>>>(
|
||||||
|
{ queryKey: ["base-rows", baseId] },
|
||||||
|
(old) => {
|
||||||
|
if (!old) return old;
|
||||||
|
const lastPageIndex = old.pages.length - 1;
|
||||||
|
return {
|
||||||
|
...old,
|
||||||
|
pages: old.pages.map((page, index) =>
|
||||||
|
index === lastPageIndex
|
||||||
|
? { ...page, items: [...page.items, e.row] }
|
||||||
|
: page,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "base:row:updated": {
|
case "base:row:updated": {
|
||||||
|
|||||||
Reference in New Issue
Block a user