Feat/pagination chat list#200
Open
icancodefyi wants to merge 2 commits into
Open
Conversation
- Backend: cursor pagination with (createdAt, id) compound cursor, usage aggregation via groupBy instead of loading all usageEvents - Validation: listChatsQuerySchema for limit (1-100, default 25) and cursor - Frontend: getChats accepts pagination params, returns PaginatedChats - AllChats: Load More button appends older chats, search/filter on loaded set
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR centralizes Markdown code rendering into a reusable CodeBlock component and adds cursor-based pagination to the chats listing, updating both frontend and backend to support incremental loading.
Changes:
- Extracted duplicated code highlighting/copy UI into
src/components/CodeBlock.tsxand reused it across chat pages. - Implemented cursor-based pagination for
/chat/listin the backend and updated the frontendAllChatspage to support “Load More”. - Updated the client API contract for
getChatsto return a paginated envelope (chats/hasMore/nextCursor).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/SharedChatPage.tsx | Replaces inline code highlighting UI with shared CodeBlock. |
| src/pages/ChatPage.tsx | Replaces inline code highlighting UI with shared CodeBlock. |
| src/pages/AllChats.tsx | Adds “Load More” pagination flow and state management. |
| src/lib/api.ts | Updates getChats to accept pagination params and return a paginated envelope. |
| src/components/CodeBlock.tsx | Introduces reusable highlighted code block with copy-to-clipboard UX. |
| backend/utils/validationSchemas.js | Adds query validation for chat listing pagination params. |
| backend/routers/chat.route.js | Applies new query validation to /chat/list. |
| backend/controllers/chat.controller.js | Implements cursor pagination + usage aggregation changes for chat listing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+271
to
+282
| const { limit, cursor } = req.query; | ||
|
|
||
| const where = { userId: req.user.id }; | ||
|
|
||
| if (cursor) { | ||
| const decoded = JSON.parse(Buffer.from(cursor, "base64").toString()); | ||
| const cursorDate = new Date(decoded.createdAt); | ||
| where.OR = [ | ||
| { createdAt: { lt: cursorDate } }, | ||
| { createdAt: cursorDate, id: { lt: decoded.id } }, | ||
| ]; | ||
| } |
| }); | ||
|
|
||
| const listAllChats = asyncHandler(async (req, res) => { | ||
| const { limit, cursor } = req.query; |
Comment on lines
+295
to
+296
| orderBy: [{ createdAt: "desc" }, { id: "desc" }], | ||
| take: limit + 1, |
Comment on lines
+201
to
+208
| export const getChats = (params?: { limit?: number; cursor?: string }) => { | ||
| const query = new URLSearchParams(); | ||
| if (params?.limit) query.set("limit", String(params.limit)); | ||
| if (params?.cursor) query.set("cursor", params.cursor); | ||
| const qs = query.toString(); | ||
| const path = `/chat/list${qs ? `?${qs}` : ""}`; | ||
| return apiRequest<PaginatedChats>(path, { method: "GET" }); | ||
| }; |
Comment on lines
+40
to
+49
| const highlighted = useMemo(() => { | ||
| try { | ||
| if (language && hljs.getLanguage(language)) { | ||
| return hljs.highlight(code, { language }).value; | ||
| } | ||
| return hljs.highlightAuto(code).value; | ||
| } catch { | ||
| return escapeHtml(code); | ||
| } | ||
| }, [language, code]); |
Owner
|
@icancodefyi Please resolve the merge conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #46
Summary
Paginate the chat list endpoint so heavy users don't load everything in one request. Uses cursor-based pagination for stable ordering even when new chats are created mid-pagination.
Changes
Backend — backend/controllers/chat.controller.js
Backend — backend/utils/validationSchemas.js
Backend — backend/routers/chat.route.js
Frontend — src/lib/api.ts
Frontend — src/pages/AllChats.tsx