Files
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

31 lines
785 B
TypeScript
Executable File

import {Commentable} from '@common/comments/commentable';
import {Comment} from '@common/comments/comment';
import {useInfiniteData} from '@common/ui/infinite-scroll/use-infinite-data';
interface QueryParams {
perPage?: number;
}
export function commentsQueryKey(
commentable: Commentable,
params: QueryParams = {}
) {
return ['comment', `${commentable.id}-${commentable.model_type}`, params];
}
export function useComments(
commentable: Commentable,
params: QueryParams = {}
) {
return useInfiniteData<Comment>({
queryKey: commentsQueryKey(commentable, params),
endpoint: 'commentable/comments',
//paginate: 'cursor',
queryParams: {
commentable_type: commentable.model_type,
commentable_id: commentable.id,
...params,
},
});
}