feat: implement pagination for comments with load more functionality

This commit is contained in:
ngthanhvu
2026-07-24 04:30:37 -04:00
parent 320eed551e
commit 541cb66c33
5 changed files with 90 additions and 29 deletions
+4 -4
View File
@@ -34,14 +34,14 @@ export type Comment = {
}
export function useComments() {
async function fetchComments(source: string, slug: string, userId?: number) {
async function fetchComments(source: string, slug: string, userId?: number, limit?: number, offset?: number) {
try {
const data = await $fetch('/api/comments', {
query: { source, slug, userId },
query: { source, slug, userId, limit, offset },
})
return data.items as Comment[]
return data as { items: Comment[], total: number }
} catch {
return [] as Comment[]
return { items: [] as Comment[], total: 0 }
}
}