Skip to content

Commit

Permalink
fix reply pagination bug
Browse files Browse the repository at this point in the history
  • Loading branch information
djyde committed Apr 27, 2021
1 parent f11e24b commit 1d204d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pages/dashboard/project/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ function CommentComponent(props: {
return (
<Box key={comment.id} pl={!props.isRoot ? 4 : 0}>
<HStack spacing={2}>
<Tooltip label={comment.page.slug}>
{props.isRoot && <Tooltip label={comment.page.slug}>
<Link color="gray.500" href={comment.page.url}>{comment.page.title}</Link>
</Tooltip>
</Tooltip> }
<Spacer />

{comment.moderatorId && <Tag colorScheme="cyan" size="sm">MOD</Tag>}
Expand Down
18 changes: 13 additions & 5 deletions service/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ export class CommentService extends RequestScopeService {
select?: Prisma.CommentSelect
pageSlug?: string | Prisma.StringFilter
onlyOwn?: boolean
approved?: boolean
approved?: boolean,
pageSize?: number
},
): Promise<CommentWrapper> {
const pageSize = 10
const pageSize = options?.pageSize || 10

const select = {
id: true,
createdAt: true,
content: true,
...options?.select,
page: true,
moderatorId: true
moderatorId: true,
} as Prisma.CommentSelect

const where = {
Expand All @@ -64,7 +65,7 @@ export class CommentService extends RequestScopeService {
projectId,
project: {
deletedAt: {
equals: null
equals: null,
},
ownerId: options?.onlyOwn
? await (await this.getSession()).uid
Expand Down Expand Up @@ -100,10 +101,18 @@ export class CommentService extends RequestScopeService {
// get replies
const replies = await this.getComments(projectId, {
...options,
page: 1,
// hard code 100 because we havent implement pagination in nested comment
pageSize: 100,
parentId: comment.id,
pageSlug: options?.pageSlug,
select,
})

if (comment.id === '5189938357') {
console.log(replies)
console.log(options)
}
const parsedCreatedAt = dayjs(comment.createdAt).format(
'YYYY-MM-DD HH:mm',
)
Expand Down Expand Up @@ -159,7 +168,6 @@ export class CommentService extends RequestScopeService {
},
parentId?: string,
) {

// touch page
const page = await this.pageService.upsertPage(pageSlug, projectId, {
pageTitle: body.pageTitle,
Expand Down

1 comment on commit 1d204d5

@vercel
Copy link

@vercel vercel bot commented on 1d204d5 Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.