mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
preloading node comments
This commit is contained in:
parent
95166a427f
commit
66a32ae3cb
4 changed files with 25 additions and 13 deletions
|
@ -27,19 +27,20 @@ const extractKey = (key: string) => {
|
|||
return parseInt(match[1], 10) || 0;
|
||||
};
|
||||
|
||||
export const useGetComments = (nodeId: number) => {
|
||||
// TODO: const postedCommentsLength = Math.min(0, data[data.length - 1] - COMMENTS_DISPLAY);
|
||||
|
||||
export const useGetComments = (nodeId: number, fallbackData?: IComment[]) => {
|
||||
const { data, isValidating, setSize, size, mutate } = useSWRInfinite(
|
||||
getKey(nodeId),
|
||||
async (key: string) => {
|
||||
const result = await apiGetNodeComments({
|
||||
id: nodeId,
|
||||
take: COMMENTS_DISPLAY,
|
||||
skip: extractKey(key) * COMMENTS_DISPLAY, // TODO: - postedCommentsLength,
|
||||
skip: extractKey(key) * COMMENTS_DISPLAY,
|
||||
});
|
||||
|
||||
return result.comments;
|
||||
},
|
||||
{
|
||||
fallbackData: fallbackData && [fallbackData],
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -5,8 +5,11 @@ import { useGetComments } from '~/hooks/comments/useGetComments';
|
|||
import { IComment } from '~/types';
|
||||
import { showErrorToast } from '~/utils/errors/showToast';
|
||||
|
||||
export const useNodeComments = (nodeId: number) => {
|
||||
const { comments, isLoading, onLoadMoreComments, hasMore, data, mutate } = useGetComments(nodeId);
|
||||
export const useNodeComments = (nodeId: number, fallbackData?: IComment[]) => {
|
||||
const { comments, isLoading, onLoadMoreComments, hasMore, data, mutate } = useGetComments(
|
||||
nodeId,
|
||||
fallbackData
|
||||
);
|
||||
|
||||
const onDelete = useCallback(
|
||||
async (id: IComment['id'], isLocked: boolean) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue