Skip to content

Commit 127148d

Browse files
committed
Showed counters for Project and User List
1 parent 5c18350 commit 127148d

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

frontend/src/hooks/useInfiniteScroll.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,28 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
3333
const [totalCount, setTotalCount] = useState<number | void>();
3434
const scrollElement = useRef<HTMLElement>(document.documentElement);
3535
const isLoadingRef = useRef<boolean>(false);
36+
const isDisabledMoreRef = useRef<boolean>(false);
3637
const lastRequestParams = useRef<Args | undefined>(undefined);
37-
const [disabledMore, setDisabledMore] = useState(false);
3838
const { limit, ...argsProp } = args;
3939
const lastArgsProps = useRef<Partial<Args>>(null);
4040

4141
const [getItems, { isLoading, isFetching }] = useLazyQuery({ ...args } as Args);
4242

4343
const getDataRequest = (params: Args) => {
44-
lastRequestParams.current = params;
44+
if (isEqual(params, lastRequestParams.current)) {
45+
return Promise.reject();
46+
}
4547

46-
return getItems({
48+
const request = getItems({
4749
limit,
4850
...params,
4951
} as Args).unwrap();
52+
53+
request.then(() => {
54+
lastRequestParams.current = { ...params };
55+
});
56+
57+
return request;
5058
};
5159

5260
const getEmptyList = () => {
@@ -55,7 +63,8 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
5563
setData([]);
5664

5765
getDataRequest(argsProp as Args).then((result: LazyQueryResponse<DataItem>) => {
58-
setDisabledMore(false);
66+
// setDisabledMore(false);
67+
isDisabledMoreRef.current = false;
5968

6069
if ('data' in result) {
6170
setData(result.data as ListResponse<DataItem>);
@@ -77,7 +86,7 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
7786
}, [argsProp, lastArgsProps, skip]);
7887

7988
const getMore = async () => {
80-
if (isLoadingRef.current || disabledMore || skip) {
89+
if (isLoadingRef.current || isDisabledMoreRef.current || skip) {
8190
return;
8291
}
8392

@@ -102,15 +111,15 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
102111
if (listResponse.length > 0) {
103112
setData((prev) => [...prev, ...listResponse]);
104113
} else {
105-
setDisabledMore(true);
114+
isDisabledMoreRef.current = true;
106115
}
107116
} catch (e) {
108117
console.log(e);
109118
}
110119

111120
setTimeout(() => {
112121
isLoadingRef.current = false;
113-
}, 10);
122+
}, 50);
114123
};
115124

116125
useLayoutEffect(() => {
@@ -124,7 +133,7 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
124133
}, [data]);
125134

126135
const onScroll = useCallback(() => {
127-
if (disabledMore || isLoadingRef.current) {
136+
if (isDisabledMoreRef.current || isLoadingRef.current) {
128137
return;
129138
}
130139

@@ -135,7 +144,7 @@ export const useInfiniteScroll = <DataItem, Args extends InfinityListArgs>({
135144
if (scrollPositionFromBottom < SCROLL_POSITION_GAP) {
136145
getMore().catch(console.log);
137146
}
138-
}, [disabledMore, getMore]);
147+
}, [getMore]);
139148

140149
useEffect(() => {
141150
document.addEventListener('scroll', onScroll);

frontend/src/types/user.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare interface IUserResponseData {
1818
global_role: TUserRole;
1919
email: string | null;
2020
permissions: Record<TUserPermissionKeys, boolean>;
21+
created_at: string;
22+
active: boolean;
2123
}
2224

2325
declare interface IUser {

frontend/webpack/dev.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ module.exports = {
2626
{
2727
context: ['/api'],
2828
changeOrigin: true,
29-
// target: 'http://127.0.0.1:8000',
30-
target: 'http://127.0.0.1:3000',
31-
// target: 'https://sky.dstack.ai/', //0ab1c6ee-3f7b-4839-a259-5e5c6074a97f
32-
// target: 'https://sky-stage.dstack.ai/', //29001ee8-897c-47ea-bfec-819f56835ffe
33-
// target: 'https://cloud.dstack.ai/', //0ab1c6ee-3f7b-4839-a259-5e5c6074a97f
34-
// target: 'https://08fdfa6f0dd6.ngrok-free.app/',
29+
target: 'http://127.0.0.1:8000',
3530
logLevel: 'debug',
3631
},
3732
],

0 commit comments

Comments
 (0)