1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

fixed comments loader

This commit is contained in:
Fedor Katurov 2022-07-17 13:27:33 +07:00
parent 0a1d2cbf99
commit bb81bdae69
16 changed files with 80 additions and 127 deletions

View file

@ -45,9 +45,10 @@ export const useGetComments = (nodeId: number, fallbackData?: IComment[]) => {
);
const comments = useMemo(() => flatten(data || []), [data]);
const hasMore = (data?.[size - 1]?.length || 0) >= COMMENTS_DISPLAY;
const hasMore = (data?.[size - 1]?.length || 0) >= COMMENTS_DISPLAY ||
(!!data?.length && data?.length > 0 && isValidating);
const onLoadMoreComments = useCallback(() => setSize(size + 1), [setSize, size]);
return { comments, hasMore, onLoadMoreComments, isLoading: !data && isValidating, mutate, data };
return { comments, hasMore, onLoadMoreComments, isLoading: !data && isValidating, mutate, data, isLoadingMore: !!data?.length && isValidating };
};

View file

@ -6,7 +6,7 @@ import { IComment } from '~/types';
import { showErrorToast } from '~/utils/errors/showToast';
export const useNodeComments = (nodeId: number, fallbackData?: IComment[]) => {
const { comments, isLoading, onLoadMoreComments, hasMore, data, mutate } = useGetComments(
const { comments, isLoading, onLoadMoreComments, hasMore, data, mutate, isLoadingMore } = useGetComments(
nodeId,
fallbackData
);
@ -62,5 +62,5 @@ export const useNodeComments = (nodeId: number, fallbackData?: IComment[]) => {
[data, mutate, nodeId]
);
return { onLoadMoreComments, onDelete, comments, hasMore, isLoading, onEdit };
return { onLoadMoreComments, onDelete, comments, hasMore, isLoading, onEdit, isLoadingMore };
};