fix: set loadingWatch state when the loading begins

This commit is contained in:
jialin
2026-01-16 11:37:47 +08:00
parent 9de4054851
commit 3e359a69c7
5 changed files with 35 additions and 27 deletions
@@ -8,7 +8,6 @@ export default function useAddWorkerMessage() {
const chunkRequestRef = useRef<any>(null);
const newItemsRef = useRef<any[]>([]);
const [addedCount, setAddedCount] = useState(0);
const startWatchRef = useRef(false);
const timerRef = useRef<any>(null);
const showAddWorkerMessage = () => {
@@ -18,12 +17,12 @@ export default function useAddWorkerMessage() {
}
};
const { setChunkRequest } = useSetChunkRequest();
const { setChunkRequest, startLoadingRef } = useSetChunkRequest();
const { updateChunkedList } = useUpdateChunkedList({
events: ['CREATE', 'INSERT'],
dataList: [],
onCreate: (newItems: any) => {
if (startWatchRef.current) {
if (startLoadingRef.current) {
newItemsRef.current = newItemsRef.current.concat(newItems);
showAddWorkerMessage();
}
@@ -39,7 +38,6 @@ export default function useAddWorkerMessage() {
const resetAddedCount = () => {
setAddedCount(0);
newItemsRef.current = [];
startWatchRef.current = false;
clearTimeout(timerRef.current);
};
@@ -51,9 +49,6 @@ export default function useAddWorkerMessage() {
url: WORKERS_API,
handler: updateHandler
});
timerRef.current = setTimeout(() => {
startWatchRef.current = true;
}, 5000);
} catch (error) {
// ignore
}
@@ -62,7 +57,6 @@ export default function useAddWorkerMessage() {
useEffect(() => {
return () => {
chunkRequestRef.current?.current?.cancel?.();
startWatchRef.current = false;
newItemsRef.current = [];
clearTimeout(timerRef.current);
};
+6 -2
View File
@@ -54,10 +54,14 @@ export async function queryWorkersList<T extends Record<string, any>>(
});
}
export async function queryGpuDevicesList(params: Global.SearchParams) {
export async function queryGpuDevicesList(
params: Global.SearchParams,
options?: { token: any }
) {
return request<Global.PageResponse<GPUDeviceItem>>(`${GPU_DEVICES_API}`, {
method: 'GET',
params
params,
cancelToken: options?.token
});
}