Skip to content

Fix profile REP categories pagination to fetch additional pages on load more#2165

Merged
ragnep merged 4 commits intomainfrom
rep-categories-results
Mar 24, 2026
Merged

Fix profile REP categories pagination to fetch additional pages on load more#2165
ragnep merged 4 commits intomainfrom
rep-categories-results

Conversation

@ragnep
Copy link
Copy Markdown
Contributor

@ragnep ragnep commented Mar 24, 2026

…ad more

Summary by CodeRabbit

  • New Features
    • Added paginated loading for reputation categories with a smarter "Load more" control that shows remaining loaded counts, displays "Loading..." when fetching, and disables appropriately.
  • Refactor
    • Lifted pagination state and handlers to higher-level components so mobile/desktop views share consistent paging and loading behavior.
  • UX
    • Improved button affordance and loading visuals for a clearer user experience.

…ad more

Signed-off-by: ragnep <ragneinfo@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

Warning

Rate limit exceeded

@ragnep has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 873277f3-65f2-47ff-91af-ff0b2844bd96

📥 Commits

Reviewing files that changed from the base of the PR and between 7ff8db3 and 7fd11c0.

📒 Files selected for processing (1)
  • components/user/rep/UserPageRep.tsx
📝 Walkthrough

Walkthrough

Replaces per-component category queries with a shared infinite-query (useRepCategories) in UserPageRep, lifts pagination state (visibleCount, onShowMore, hasNextPage, isFetchingNextPage) to the parent, and updates mobile/header components and button logic to use the new pagination flow.

Changes

Cohort / File(s) Summary
Core pagination & data fetching
components/user/rep/UserPageRep.tsx
Switched from separate useQuery calls to a single useRepCategories (infinite query). Added per-direction visibleCounts, handleShowMore, flattened pages into category arrays, and passed pagination flags/handlers to children.
Mobile content & button behavior
components/user/rep/MobileRepTabContent.tsx, components/user/rep/UserPageRepMobile.tsx
Mobile tab now accepts visibleCount, onShowMore, hasNextPage, isFetchingNextPage; "Load more" button label and disabled state now reflect hidden loaded items and infinite-query fetch state. Removed local visibleCount state from mobile wrapper.
Header: load-more & UI tweaks
components/user/rep/header/UserPageRepHeader.tsx
Header receives lifted pagination props, computes hiddenLoadedCategoryCount, shows dynamic "Load more" text (+N more / Loading... / Load more), and disables/styles the button during fetch without hidden items. Minor styling/formatting adjustments.
Wrapper / router change
components/user/rep/UserPageRepWrapper.tsx
Now derives user from params["user"] unconditionally (calls .toLowerCase()) and passes key={user} to UserPageRep to force remount on user change.

Sequence Diagram(s)

sequenceDiagram
  participant User as User (UI)
  participant Header as UserPageRepHeader / MobileRepTabContent
  participant Parent as UserPageRep
  participant Hook as useRepCategories (useInfiniteQuery)
  participant API as RepCategories API

  rect rgba(200,200,255,0.5)
  User->>Header: clicks "Load more"
  Header->>Parent: onShowMore()
  end

  rect rgba(200,255,200,0.5)
  Parent->>Hook: request fetchNextPage() if needed
  Hook->>API: GET /rep-categories?page=...
  API-->>Hook: returns next page (or next=null)
  Hook-->>Parent: new page appended (hasNextPage updated)
  end

  rect rgba(255,230,200,0.5)
  Parent->>Header: update props (visibleCount, hasNextPage, isFetchingNextPage)
  Header->>User: render updated list / button state
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • simo6529
  • prxt6529

Poem

🐇 I hopped from child up to parent sky,

Pages unfurled as I scrolled on by,
Hidden counts peek out, then disappear,
"Load more" hums softly when the next page is near.
🥕✨ Hop, fetch, and render — hooray for sync!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing pagination to fetch additional REP category pages when users click 'load more', which is the core objective across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rep-categories-results

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: ragnep <ragneinfo@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
components/user/rep/header/UserPageRepHeader.tsx (1)

48-60: Consider extracting the shared load-more presenter state. The hiddenLoadedCategoryCount / loadMoreLabel / isLoadMoreDisabled trio now exists here and in components/user/rep/MobileRepTabContent.tsx. A tiny helper would keep the desktop and mobile rules from drifting on the next pagination tweak.

Also applies to: 189-197

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/user/rep/header/UserPageRepHeader.tsx` around lines 48 - 60, The
load-more presentation logic (hiddenLoadedCategoryCount, loadMoreLabel,
isLoadMoreDisabled and related hasMore calculation) is duplicated between
UserPageRepHeader and MobileRepTabContent; extract this into a small pure helper
(e.g., computeLoadMoreState) that takes categories.length, visibleCount,
hasNextPage, and isFetchingNextPage and returns { hiddenLoadedCategoryCount,
hasMore, loadMoreLabel, isLoadMoreDisabled } and then replace the duplicated
blocks in components/user/rep/header/UserPageRepHeader.tsx (the
hiddenLoadedCategoryCount/loadMoreLabel/isLoadMoreDisabled usage) and
components/user/rep/MobileRepTabContent.tsx to call that helper so both views
share the single source of truth for load-more rules.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/user/rep/UserPageRep.tsx`:
- Around line 176-227: handleShowMore currently calls fetchNextPage() from
inside the setVisibleCounts updater which introduces a side effect in a React
state updater; compute whether you need to fetch before calling setVisibleCounts
(derive loadedCount, hasNextPage, isFetchingNextPage, and compute
shouldFetchNextPage based on repDirection and repCategories/repCategoriesGiven),
then call setVisibleCounts to update [repDirection] by
VISIBLE_CATEGORY_LOAD_STEP, and finally (outside the setter) call the
appropriate fetchNextPage from repCategoriesQuery or repCategoriesGivenQuery
only if shouldFetchNextPage is true; keep the dependencies for useCallback
updated to include the queries and lengths but remove any fetchNextPage calls
from inside the setter to keep the updater pure.

---

Nitpick comments:
In `@components/user/rep/header/UserPageRepHeader.tsx`:
- Around line 48-60: The load-more presentation logic
(hiddenLoadedCategoryCount, loadMoreLabel, isLoadMoreDisabled and related
hasMore calculation) is duplicated between UserPageRepHeader and
MobileRepTabContent; extract this into a small pure helper (e.g.,
computeLoadMoreState) that takes categories.length, visibleCount, hasNextPage,
and isFetchingNextPage and returns { hiddenLoadedCategoryCount, hasMore,
loadMoreLabel, isLoadMoreDisabled } and then replace the duplicated blocks in
components/user/rep/header/UserPageRepHeader.tsx (the
hiddenLoadedCategoryCount/loadMoreLabel/isLoadMoreDisabled usage) and
components/user/rep/MobileRepTabContent.tsx to call that helper so both views
share the single source of truth for load-more rules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65bd6995-f40d-4983-97d9-bfa0ec383780

📥 Commits

Reviewing files that changed from the base of the PR and between bcf872c and e83d692.

📒 Files selected for processing (5)
  • components/user/rep/MobileRepTabContent.tsx
  • components/user/rep/UserPageRep.tsx
  • components/user/rep/UserPageRepMobile.tsx
  • components/user/rep/UserPageRepWrapper.tsx
  • components/user/rep/header/UserPageRepHeader.tsx

Comment thread components/user/rep/UserPageRep.tsx
@sonarqubecloud
Copy link
Copy Markdown

@ragnep ragnep merged commit 31b731d into main Mar 24, 2026
8 checks passed
@ragnep ragnep deleted the rep-categories-results branch March 24, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants