Skip to content

Commit 0c3e564

Browse files
authored
[UI] Add Spot policy configuration option to the fleet wizard #3513 (#3520)
1 parent c46205b commit 0c3e564

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

frontend/src/hooks/useInfiniteScroll.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
4141
const [getItems, { isLoading, isFetching }] = useLazyQuery({ ...args } as Args);
4242

4343
const getDataRequest = (params: Args) => {
44-
if (isEqual(params, lastRequestParams.current)) {
45-
return Promise.reject();
46-
}
47-
4844
const request = getItems({
4945
limit,
5046
...params,
@@ -90,36 +86,40 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
9086
return;
9187
}
9288

93-
try {
94-
isLoadingRef.current = true;
95-
96-
const result = await getDataRequest({
97-
...argsProp,
98-
...getPaginationParams(data[data.length - 1]),
99-
} as Args);
100-
101-
let listResponse: ListResponse<DataItem>;
89+
const requestParams = {
90+
...argsProp,
91+
...getPaginationParams(data[data.length - 1]),
92+
};
10293

103-
if ('data' in result) {
104-
listResponse = result.data;
105-
setTotalCount(result.total_count);
106-
} else {
107-
listResponse = result;
108-
setTotalCount();
94+
if (!isEqual(requestParams, lastRequestParams.current)) {
95+
try {
96+
isLoadingRef.current = true;
97+
98+
const result = await getDataRequest(requestParams as Args);
99+
100+
let listResponse: ListResponse<DataItem>;
101+
102+
if ('data' in result) {
103+
listResponse = result.data;
104+
setTotalCount(result.total_count);
105+
} else {
106+
listResponse = result;
107+
setTotalCount();
108+
}
109+
110+
if (listResponse.length > 0) {
111+
setData((prev) => [...prev, ...listResponse]);
112+
} else {
113+
isDisabledMoreRef.current = true;
114+
}
115+
} catch (e) {
116+
console.log(e);
109117
}
110118

111-
if (listResponse.length > 0) {
112-
setData((prev) => [...prev, ...listResponse]);
113-
} else {
114-
isDisabledMoreRef.current = true;
115-
}
116-
} catch (e) {
117-
console.log(e);
119+
setTimeout(() => {
120+
isLoadingRef.current = false;
121+
}, 50);
118122
}
119-
120-
setTimeout(() => {
121-
isLoadingRef.current = false;
122-
}, 50);
123123
};
124124

125125
useLayoutEffect(() => {

0 commit comments

Comments
 (0)