fix: show worker added message

This commit is contained in:
jialin
2026-06-05 10:20:55 +08:00
committed by jialin
parent faf6246fe6
commit 907187d53a
8 changed files with 118 additions and 28 deletions
+10 -18
View File
@@ -14,7 +14,6 @@ type EventsType = 'CREATE' | 'UPDATE' | 'DELETE' | 'INSERT';
export function useUpdateChunkedList(options: {
events?: EventsType[];
dataList?: any[];
triggerAt?: React.MutableRefObject<number>;
limit?: number;
onCreate?: (args: any) => void;
onUpdate?: (args: any) => void;
@@ -24,9 +23,9 @@ export function useUpdateChunkedList(options: {
filterFun?: (args: any) => boolean;
mapFun?: (args: any) => any;
computedID?: (d: object) => string;
isNewItem?: (item: any) => boolean;
}) {
const { events = ['CREATE', 'DELETE', 'UPDATE', 'INSERT'], triggerAt } =
options;
const { events = ['CREATE', 'DELETE', 'UPDATE', 'INSERT'] } = options;
const deletedIdsRef = useRef<Set<number | string>>(new Set());
const cacheDataListRef = useRef<any[]>(options.dataList || []);
const timerRef = useRef<any>(null);
@@ -71,17 +70,14 @@ export function useUpdateChunkedList(options: {
(sItem: any) => sItem.id === item.id
);
const updateItem = { ...item };
if (updateIndex === -1 && !triggerAt?.current) {
if (updateIndex === -1) {
acc.push(updateItem);
} else if (!triggerAt?.current) {
} else {
cacheDataListRef.current[updateIndex] = updateItem;
}
// only push items created after the watch started
// TODO only push items created after triggerAt
if (
triggerAt?.current &&
Date.parse(item.created_at) >= triggerAt.current
) {
if (options.isNewItem?.(item)) {
latestCreateList.push(updateItem);
}
@@ -103,10 +99,8 @@ export function useUpdateChunkedList(options: {
cacheDataListRef.current = cacheDataListRef.current?.filter(
(item: any) => {
// collect deleted items
if (triggerAt?.current) {
if (ids?.includes(item.id)) {
deletedList.push(item);
}
if (ids?.includes(item.id) && !options.isNewItem?.(item)) {
deletedList.push(item);
}
return !ids?.includes(item.id);
}
@@ -133,10 +127,8 @@ export function useUpdateChunkedList(options: {
updateItem,
...cacheDataListRef.current.slice(0, limit - 1)
];
if (options.onUpdate && triggerAt?.current) {
if (Date.parse(item.created_at) >= triggerAt.current) {
options.onUpdate?.([updateItem]);
}
if (options.onUpdate && options.isNewItem?.(item)) {
options.onUpdate?.([updateItem]);
}
}
});