feat: add real-time polling and creator badges for Q&A (#650) - #1033
feat: add real-time polling and creator badges for Q&A (#650)#1033Richiey1 wants to merge 3 commits into
Conversation
Add fr and pt locales to routing configuration. Create translation files for French and Portuguese (copied from en as base). LanguageSwitcher automatically detects new locales from routing config. Closes Iris-IV#680
… routes (Iris-IV#670) - Add pagination (page/pageSize), status filtering, and sparse field selection to GET /api/reports - Add pagination (page/pageSize), adminAddress/action filtering, and sparse field selection to GET /api/admin-audit-log - Update client-side getAdminAuditLog to request paginated pages instead of fetching the full dataset - Return { items, total, page, pageSize, hasMore } envelope from both endpoints - Add unit tests covering pagination, filtering, sparse fieldsets, and pageSize clamping
…ges (Iris-IV#650) - Add refetchInterval: 15s to useCampaignComments query for real-time updates - Set refetchIntervalInBackground: false to avoid polling when tab is hidden - Set staleTime: 0 to ensure fresh data on each poll - Add creatorAddress prop to CommentItem and CommentsList - Show a blue "Creator" badge on comments from the campaign creator - Pass campaign.creator as creatorAddress from CommentsSection
|
Auto-review failed (API error). Leaving PR for human review. |
|
@Richiey1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
| @@ -0,0 +1,132 @@ | |||
| import { NextResponse } from "next/server"; | |||
| @@ -0,0 +1,112 @@ | |||
| import { NextResponse } from "next/server"; | |||
| if (apiEntries.length > 0) { | ||
| writeAllEntries(apiEntries); | ||
| return apiEntries.sort((a, b) => b.timestamp - a.timestamp).slice(0, Math.max(0, limit)); | ||
| const { entries, total, hasMore } = await readApiEntries(normalizedAddress, page, pageSize); |
davidmaronio
left a comment
There was a problem hiding this comment.
the actual feature here is small and sensible: refetchInterval with refetchIntervalInBackground disabled is the right way to poll with react-query, and threading creatorAddress down to CommentItem for a creator badge is a clean prop chain with a case-insensitive compare.
blockers:
- this PR is stacked on top of #1032 (reports/admin-audit-log routes, adminLog, tests) and also carries #1028's untranslated fr/pt files and routing.ts. the q&a change itself is about 6 files of the 12 in the diff. please rebase so the PR contains only the polling and badge work, otherwise it cannot be reviewed or merged independently.
- src/hooks/useCampaignComments.ts:50 the new block is mis-indented (the const declarations moved to column 0 inside the hook). it still parses, but prettier will fail the lint job. run
npm run format. - src/hooks/useCampaignComments.ts:57
staleTime: 0combined with a 15s refetchInterval means every remount also refetches immediately. that may be intended, but if not, keep the default staleTime and let the interval do the work. - src/components/CommentItem.tsx:129 the badge text "Creator" and the title "Campaign Creator" are hardcoded english in an i18n app. add translation keys next to the existing "Verified" handling.
- only the currently viewed page is polled since page is part of the queryKey. fine for a first pass, but new comments on page 1 will not surface while the user reads page 2. a note in the PR description or a total-count check would help.
CI red beyond prettier looks like the stale base (parse errors in files this PR does not touch), the rebase should clear it.
|
checking back in: no new commits since the review. the branch still stacks #1032's pagination files and #1028's fr/pt files, so the polling and badge work still cannot be reviewed or merged on its own. please rebase onto main so only the q&a changes remain, plus the indent and hardcoded-string fixes from the review. |
Closes #650
Summary
Added real-time polling and creator identification to the campaign Q&A section so donors can see fresh answers without manually refreshing.
What changed
Real-time updates (
src/hooks/useCampaignComments.ts):refetchInterval: 15_000to the comments query so new questions and answers appear automaticallyrefetchIntervalInBackground: falseto avoid unnecessary polling when the tab is hiddenstaleTime: 0so each poll always fetches fresh data from the serverCreator badge (
src/components/CommentItem.tsx,CommentsList.tsx,CommentsSection.tsx):creatorAddressprop toCommentItemandCommentsListcampaign.creatorfromCommentsSectiondown through the component treeTesting / Local Verification
npm run lint— no new warnings or errorsnpm run typecheck— no new type errors in modified filesnpm run test -- --testPathPatterns="src/__tests__/app/api"— existing pagination tests still passHey @FinesseStudioLab/maintainer, this closes #650. Let me know if you'd like any adjustments to the polling interval or the badge styling.