Fix comment pagination and change show limit to 8 items

This commit is contained in:
marzban-dev
2026-05-16 19:28:43 +03:30
parent b07336f9f1
commit 1a4fce3e13
4 changed files with 27 additions and 10 deletions
@@ -1,28 +1,35 @@
// imports
import { useQuery } from "@tanstack/vue-query";
import { useAppParams } from "~/composables/global/useAppParams";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetCommentsResponse = ApiPaginated<UserComment>;
const useGetComments = (id: string | number | undefined, page: Ref<number>) => {
const useGetComments = (id: string | number | undefined) => {
// state
const { $axios: axios } = useNuxtApp();
const { page } = useAppParams();
// methods
const handleGetComments = async () => {
const { data } = await axios.get<GetCommentsResponse>(`${API_ENDPOINTS.product.comments}/${id}`);
const { data } = await axios.get<GetCommentsResponse>(`${API_ENDPOINTS.product.comments}/${id}`, {
params: {
offset: Number(page.value) * 8 - 8,
limit: 8,
},
});
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.comments, id, page],
queryFn: () => handleGetComments()
queryFn: () => handleGetComments(),
});
};