Conversation
… ui-fixes Merge into main
… ui-fixes Merge into main
… ui-fixes Merge into main
… ui-fixes Merge into main
… ui-fixes Merge into main
… ui-fixes Merge into main
… ui-fixes Merge into main
|
@Benjtalkshow is attempting to deploy a commit to the Threadflow Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe changes refactor pagination logic by introducing dynamic page size state in the participants page and unifying pagination object extraction from API responses in the hackathons hook to enable flexible, consistent pagination handling across features. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx (1)
238-255:⚠️ Potential issue | 🟡 MinorDrive the rows-per-page control from
pageSize, notparticipantsPagination.itemsPerPage.
DataTablePaginationreads the select value fromtable.getState().pagination.pageSize, but this table is still controlled byparticipantsPagination.itemsPerPage. After a user picks a new size, the control can bounce back to the old value until the fetch finishes because the server pagination hasn't updated yet. Use the localpageSizestate as the source of truth here.As per coding guidelines, "Prefer readability over performance in React and Next.js development".Suggested adjustment
state: { pagination: { pageIndex: participantsPagination.currentPage - 1, - pageSize: participantsPagination.itemsPerPage, + pageSize, }, }, onPaginationChange: updater => { if (typeof updater === 'function') { const newState = updater({ pageIndex: participantsPagination.currentPage - 1, - pageSize: participantsPagination.itemsPerPage, + pageSize, }); - if (newState.pageSize !== participantsPagination.itemsPerPage) { + if (newState.pageSize !== pageSize) { setPageSize(newState.pageSize); handlePageChange(1, newState.pageSize); } else { handlePageChange(newState.pageIndex + 1); } } },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/`(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx around lines 238 - 255, The pagination control is currently driven by participantsPagination.itemsPerPage which causes the rows-per-page select to revert while the server fetch runs; update DataTablePagination to drive pageSize from the local pageSize state instead of participantsPagination.itemsPerPage. In the onPaginationChange handler of the table (where updater is applied) use the local pageSize value as the source of truth: call setPageSize(newState.pageSize) immediately when the user selects a new size, call handlePageChange(1, newState.pageSize) to fetch page 1 with the new size, and ensure the table initial state uses pageSize (pageIndex: participantsPagination.currentPage - 1, pageSize: pageSize) so table.getState().pagination.pageSize reflects the local pageSize.
🧹 Nitpick comments (1)
hooks/use-hackathons.ts (1)
231-243: Replace the newas anypagination casts with a typed normalizer.These casts remove type checking where the response shape varies. The pagination is already defined in your API types (
HackathonsData.paginationandParticipantsData.pagination), so this should remain typed instead of falling back toany.Typed approach
+type PaginationShape = { + page?: number; + limit?: number; + total?: number; + totalPages?: number; + hasNext?: boolean; + hasPrev?: boolean; +}; + +const getPagination = (response: { + data?: unknown; + meta?: { pagination?: PaginationShape }; +}): PaginationShape | undefined => { + if ( + response.data && + typeof response.data === 'object' && + 'pagination' in response.data + ) { + return (response.data as { pagination?: PaginationShape }).pagination; + } + + return response.meta?.pagination; +}; ... - const pagination = (response.data?.pagination || - response.meta?.pagination) as any; + const pagination = getPagination(response); ... - const pagination = (response.data?.pagination || - response.meta?.pagination) as any; + const pagination = getPagination(response);Applies to lines 231–243 and 580–591. Per coding guidelines: "Do not use 'any' type; always search for proper Trustless Work entity types."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@hooks/use-hackathons.ts` around lines 231 - 243, Replace the unsafe "as any" cast on the pagination object with a typed normalizer that maps the possible response shapes to the known pagination type (use the API types HackathonsData.pagination or ParticipantsData.pagination), e.g. create a small helper (normalizePagination) that accepts response.data?.pagination || response.meta?.pagination, narrows/validates fields (page, totalPages, total, limit, hasNext, hasPrev) and returns a strongly typed pagination object; then use that helper when calling setHackathonsPagination and when updating hackathonsPageRef.current and repeat the same replacement for the other occurrence that handles ParticipantsData pagination so no "any" remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@app/`(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx:
- Around line 238-255: The pagination control is currently driven by
participantsPagination.itemsPerPage which causes the rows-per-page select to
revert while the server fetch runs; update DataTablePagination to drive pageSize
from the local pageSize state instead of participantsPagination.itemsPerPage. In
the onPaginationChange handler of the table (where updater is applied) use the
local pageSize value as the source of truth: call setPageSize(newState.pageSize)
immediately when the user selects a new size, call handlePageChange(1,
newState.pageSize) to fetch page 1 with the new size, and ensure the table
initial state uses pageSize (pageIndex: participantsPagination.currentPage - 1,
pageSize: pageSize) so table.getState().pagination.pageSize reflects the local
pageSize.
---
Nitpick comments:
In `@hooks/use-hackathons.ts`:
- Around line 231-243: Replace the unsafe "as any" cast on the pagination object
with a typed normalizer that maps the possible response shapes to the known
pagination type (use the API types HackathonsData.pagination or
ParticipantsData.pagination), e.g. create a small helper (normalizePagination)
that accepts response.data?.pagination || response.meta?.pagination,
narrows/validates fields (page, totalPages, total, limit, hasNext, hasPrev) and
returns a strongly typed pagination object; then use that helper when calling
setHackathonsPagination and when updating hackathonsPageRef.current and repeat
the same replacement for the other occurrence that handles ParticipantsData
pagination so no "any" remains.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4701950d-0723-4839-aff4-2d1bcc5b8b89
📒 Files selected for processing (2)
app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsxhooks/use-hackathons.ts
Summary by CodeRabbit