Skip to content

feat: add favorites tab to knowledge center per id 694#1179

Open
carddev81 wants to merge 1 commit into
mainfrom
carddev81/ticket_id694_favoritestab
Open

feat: add favorites tab to knowledge center per id 694#1179
carddev81 wants to merge 1 commit into
mainfrom
carddev81/ticket_id694_favoritestab

Conversation

@carddev81

Copy link
Copy Markdown
Contributor

Pre-Submission PR Checklist

  • No debug/console/fmt.Println statements
  • Unnecessary development comments removed
  • All acceptance criteria verified
  • Functions according to ticket specifications
  • Tested manually where applicable
  • Branch rebased with latest main
  • No business logic exists within the database layer

Description of the change

Added the favorites tab to the knowledge center in resident facing side of app along with the favorites accordion on the dashboard.

NOTE: We should add the favorting of the specific section of a library. Create a new ticket for this.

REVIEWERS NOTE: Should we remove the icon from the tab for favorites?

Screenshot(s)

image image

@carddev81 carddev81 requested a review from a team as a code owner June 17, 2026 21:09
@carddev81 carddev81 requested review from CK-7vn and removed request for a team June 17, 2026 21:09
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a dedicated Favorites tab in the Knowledge Center to access all your favorited content in one place, including libraries, videos, and helpful links.
    • Reorganized favorites display in the home sidebar into expandable accordion groups organized by content type, providing improved navigation and management of your favorite resources.

Walkthrough

The PR adds a Favorites tab to the Knowledge Center page backed by a new SWR fetch, maps server favorites into the page's unified content shape, and routes filtered content through that list when the tab is active. Separately, the Resident Home sidebar favorites list is replaced with a grouped accordion component that organizes items by content type.

Changes

Favorites UI Enhancements

Layer / File(s) Summary
Knowledge Center Favorites tab: data, filtering, and UI
frontend/src/pages/knowledge-center/ResidentKnowledgeCenter.tsx
Adds OpenContentItem import; introduces SWR fetch for /api/open-content/favorites producing favData and mutateFavorites; maps the response into ContentItem objects with favorited: true and per-type thumbnail selection; short-circuits filteredContent to return favoritesContent when the Favorites tab is active; calls mutateFavorites() after a successful toggle; renders the Favorites tab button with filled/outlined star icon and live count; shows a context-sensitive empty-state message.
Resident Home grouped favorites accordion
frontend/src/pages/student/ResidentHome.tsx
Adds useState import and updated lucide-react icon set; defines FavoriteGroup interface and FavoritesAccordion component that groups favorites by content_type, filters empty groups, and animates expand/collapse per group via activeKey state; replaces the flat favoriteItems.map(...) in the sidebar with <FavoritesAccordion items={favoriteItems} />.
🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a favorites tab to the knowledge center, and references the ticket ID (694).
Description check ✅ Passed The description is directly related to the changeset, detailing the favorites tab implementation, checklist completion, and includes screenshots demonstrating the feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/pages/knowledge-center/ResidentKnowledgeCenter.tsx`:
- Around line 111-117: The useSWR hook fetching `/api/open-content/favorites`
uses a hard-coded per_page=500 limit, which causes the favorites count to be
incorrect for users with more than 500 favorites since the count is derived from
the returned data.length. Modify the implementation to use the total count
metadata from the ServerResponseMany response object instead of relying on the
length of the returned items array, ensuring the favorites tab displays the
accurate total count regardless of the pagination limit. Additionally, ensure
that any client-side rendering or count calculations throughout the component
use this metadata-based total rather than the truncated data length.

In `@frontend/src/pages/student/ResidentHome.tsx`:
- Line 173: The accordion container has overflow-hidden applied which clips
items when the content exceeds the max-h-[800px] height constraint, making
excess favorites unreachable. Remove the overflow-hidden class from the
className attribute on the container element (around line 173) and replace it
with overflow-y-auto to allow scrolling within the constrained height, making
all items accessible. Apply the same fix to the other similar accordion
container around lines 195-199.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d832655b-5b06-4cf7-afd7-0cdd6708f7d4

📥 Commits

Reviewing files that changed from the base of the PR and between 76550ac and 7151679.

📒 Files selected for processing (2)
  • frontend/src/pages/knowledge-center/ResidentKnowledgeCenter.tsx
  • frontend/src/pages/student/ResidentHome.tsx

Comment on lines +111 to +117
const { data: favData, mutate: mutateFavorites } = useSWR<
ServerResponseMany<OpenContentItem>
>(
// Always fetched (like the other tabs) so the Favorites count shows
// even when the tab isn't active.
`/api/open-content/favorites?page=1&per_page=500&search=${searchQuery}`
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Favorites count/list can silently truncate due fixed per_page=500 + data.length counting.

The endpoint is paginated, but this request hard-limits to 500 items and the tab count is derived from only the returned page size. Users with more than 500 favorites will see an incorrect count and won’t be able to access the remainder.

Suggested direction
-const { data: favData, mutate: mutateFavorites } = useSWR<ServerResponseMany<OpenContentItem>>(
-  `/api/open-content/favorites?page=1&per_page=500&search=${searchQuery}`
-);
+const { data: favData, mutate: mutateFavorites } = useSWR<ServerResponseMany<OpenContentItem>>(
+  `/api/open-content/favorites?page=${currentPage}&per_page=${itemsPerPage}&search=${searchQuery}`
+);

- Favorites ({favData?.data.length ?? 0})
+ Favorites ({favData?.meta?.total ?? 0})

If you paginate server-side for favorites, also avoid client-side re-slicing that same list.

Also applies to: 579-579

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/knowledge-center/ResidentKnowledgeCenter.tsx` around lines
111 - 117, The useSWR hook fetching `/api/open-content/favorites` uses a
hard-coded per_page=500 limit, which causes the favorites count to be incorrect
for users with more than 500 favorites since the count is derived from the
returned data.length. Modify the implementation to use the total count metadata
from the ServerResponseMany response object instead of relying on the length of
the returned items array, ensuring the favorites tab displays the accurate total
count regardless of the pagination limit. Additionally, ensure that any
client-side rendering or count calculations throughout the component use this
metadata-based total rather than the truncated data length.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct but definitely not as severe as stated, Id argue against fixing in this PR.

return (
<div
key={title}
className="rounded-lg border border-border overflow-hidden"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Accordion can cut off favorites when a group grows beyond 800px.

With overflow-hidden on the container and max-h-[800px] when open, excess items are clipped and cannot be reached.

Suggested fix
-<div
-  className={`transition-[max-height] duration-300 ${
-    open
-      ? 'max-h-[800px]'
-      : 'max-h-0 overflow-hidden'
-  }`}
->
+<div
+  className={`transition-[max-height] duration-300 ${
+    open
+      ? 'max-h-[70vh] overflow-y-auto'
+      : 'max-h-0 overflow-hidden'
+  }`}
+>

Also applies to: 195-199

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/student/ResidentHome.tsx` at line 173, The accordion
container has overflow-hidden applied which clips items when the content exceeds
the max-h-[800px] height constraint, making excess favorites unreachable. Remove
the overflow-hidden class from the className attribute on the container element
(around line 173) and replace it with overflow-y-auto to allow scrolling within
the constrained height, making all items accessible. Apply the same fix to the
other similar accordion container around lines 195-199.

@CK-7vn CK-7vn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving, just gotta fix that null check, after I fixed it, everything worked great.

Comment on lines +111 to +117
const { data: favData, mutate: mutateFavorites } = useSWR<
ServerResponseMany<OpenContentItem>
>(
// Always fetched (like the other tabs) so the Favorites count shows
// even when the tab isn't active.
`/api/open-content/favorites?page=1&per_page=500&search=${searchQuery}`
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct but definitely not as severe as stated, Id argue against fixing in this PR.

: 'fill-brand-gold text-brand-gold'
}`}
/>
Favorites ({favData?.data.length ?? 0})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This caused an error for me when I didn't have any favorites. Should be able to replace it with the memoized value above. so favData?.data.length ?? 0 goes to favoritesContent.length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants