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:
parent
0a1d2cbf99
commit
bb81bdae69
16 changed files with 80 additions and 127 deletions
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue