Skip to content

FIXING THE CONTRIBUTE CAD #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

rishyym0927
Copy link
Contributor

Resolves #(put the issue number here)

Add the PR description here.

Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

Summary by CodeRabbit

  • New Features

    • Cards now display clickable labels and programming languages, allowing users to filter by these attributes.
    • Cards support expanding and collapsing lists of labels and languages when more than three are present.
  • Bug Fixes

    • Search bar now displays only after the component is fully loaded, correcting previous loading behavior.
  • Enhancements

    • Improved card button and icon handling for better clarity and usability.
    • Added new icons for enhanced visual cues on labels.
  • Type Updates

    • Card and skeleton component types updated to support new features and improve consistency.

Walkthrough

The changes introduce support for displaying clickable labels and programming languages in the Card component, update type definitions to accommodate these new features, and adjust internal logic for search and loading states. Several props and types are restructured, and icon support is expanded to include label icons.

Changes

File(s) Change Summary
frontend/src/app/contribute/page.tsx Enhanced the Card rendering logic to pass new labels and languages props, updated the SubmitButton to include a url, and transformed the icons prop to a boolean record.
frontend/src/components/Card.tsx Added support for displaying and toggling lists of clickable labels and programming languages, introduced new props for these, updated type safety, and included navigation on button clicks.
frontend/src/components/Search.tsx Inverted the logic controlling when the search bar and its skeleton are rendered, so the search bar appears only after loading completes.
frontend/src/components/SearchPageLayout.tsx Changed the boolean logic for the isLoaded prop passed to SearchBar to reflect the correct load state.
frontend/src/hooks/useSearchPage.ts Removed the pageTitle parameter, simplified URL-to-state synchronization, and streamlined effect dependencies for fetching and syncing search state.
frontend/src/types/card.ts Restructured CardProps type: updated button, icons, level, and social fields, and added new optional labels and languages properties.
frontend/src/types/skeleton.ts Added optional showLabels and showLanguages boolean properties to CardSkeletonProps.
frontend/src/utils/data.ts Added the FontAwesome faTag icon to the icon library.

Suggested reviewers

  • kasya
  • arkid15r
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch contricard
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rishyym0927 rishyym0927 marked this pull request as draft June 14, 2025 14:30
Copy link

Copy link
Contributor

@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: 4

🔭 Outside diff range comments (1)
frontend/src/hooks/useSearchPage.ts (1)

66-71: ⚠️ Potential issue

sortBy[0] !== 'default' is a logic bug – compare the full string

Indexing the first character (sortBy[0]) and comparing it with 'default' always evaluates to true, so the guard is ineffective. Simplify with startsWith:

-if (sortBy && sortBy !== 'default' && sortBy[0] !== 'default' && sortBy !== '') {
+if (sortBy && !sortBy.startsWith('default')) {

Replicate the same fix in the order check below to avoid inconsistent URL parameters.

🧹 Nitpick comments (3)
frontend/src/components/SearchPageLayout.tsx (1)

46-47: Inverting the prop solves the loading bug but may flash an empty bar

isLoaded={!isFirstLoad} means the search bar renders as not loaded for one render even when the data fetch has already completed (the render before setIsFirstLoad(false) resolves). Rare, but users on very fast connections could notice a one-frame skeleton flash.

Consider moving isFirstLoad into the data hook or computing isLoaded directly from props to eliminate the extra render.

frontend/src/components/Search.tsx (1)

68-93: Good inversion – but add accessibility label to the clear button

The conditional now shows the real input only when data is ready – nice!
Minor a11y nit: the clear-search button is unlabeled for screen readers.

-<button
+<button
+  aria-label="Clear search"
   className="absolute right-2 top-1/2 -translate-y-1/2 rounded-full p-1 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-300"
   onClick={handleClearSearch}
 >
frontend/src/utils/data.ts (1)

34-35: faTag registration is harmless but redundant

Because Card.tsx imports the faTag definition explicitly and passes it to <FontAwesomeIcon>, the icon does not need to be added to the global library.
Keeping it here is not wrong, but it bloats the bundle a little and breaks the “only-register-what-is-referenced-by-string” convention used elsewhere in this file (everything in library.add() is later referenced via string class names). Consider removing it or switching the button render to use the string class instead for consistency.

Also applies to: 64-66

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6077ba and 92b9b41.

📒 Files selected for processing (8)
  • frontend/src/app/contribute/page.tsx (2 hunks)
  • frontend/src/components/Card.tsx (4 hunks)
  • frontend/src/components/Search.tsx (1 hunks)
  • frontend/src/components/SearchPageLayout.tsx (1 hunks)
  • frontend/src/hooks/useSearchPage.ts (2 hunks)
  • frontend/src/types/card.ts (1 hunks)
  • frontend/src/types/skeleton.ts (1 hunks)
  • frontend/src/utils/data.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
frontend/src/components/Card.tsx (3)
frontend/src/types/card.ts (1)
  • CardProps (14-40)
frontend/src/utils/data.ts (1)
  • Icons (68-109)
frontend/src/components/DisplayIcon.tsx (1)
  • DisplayIcon (7-60)
frontend/src/types/card.ts (1)
frontend/src/types/contributor.ts (1)
  • Contributor (1-8)
🔇 Additional comments (4)
frontend/src/hooks/useSearchPage.ts (1)

104-104: Removed pageTitle from deps – verify callers no longer rely on it

The data-fetching effect now ignores pageTitle. Ensure all downstream callers that previously passed this prop have been updated, otherwise the hook change is silent-breaking.

frontend/src/types/skeleton.ts (1)

11-13: Good extension of the skeleton API

showLabels and showLanguages align perfectly with the new Card props. No issues spotted.

frontend/src/app/contribute/page.tsx (1)

34-39: SubmitButton now has both onclick and url – verify ActionButton behaviour

If ActionButton prioritises url, the modal may never open; if it prioritises onClick, navigation will never occur. Confirm the precedence and remove the unnecessary field to prevent double navigation or unexpected no-ops.

frontend/src/components/Card.tsx (1)

110-156: Nice UX addition – labels & languages

Implementation is clean, accessible, and uses proper encodeURIComponent. Good job handling “show more/less” toggles with state.

Comment on lines +50 to +57
const sortByParam = searchParams.get('sortBy') || defaultSortBy
const orderParam = searchParams.get('order') || defaultOrder
const pageParam = parseInt(searchParams.get('page') || '1')

setSearchQuery(searchQueryParam)
setSortBy(sortByParam)
setOrder(orderParam)
setCurrentPage(pageParam)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Specify radix & guard against NaN when parsing the page param

parseInt without an explicit radix relies on implementation defaults and may yield NaN for unexpected inputs (e.g. ?page=). A tiny defensive tweak prevents edge-case crashes:

-const pageParam = parseInt(searchParams.get('page') || '1')
+const rawPage  = searchParams.get('page') || '1'
+const pageParam = Number.isNaN(Number(rawPage)) ? 1 : parseInt(rawPage, 10)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const sortByParam = searchParams.get('sortBy') || defaultSortBy
const orderParam = searchParams.get('order') || defaultOrder
const pageParam = parseInt(searchParams.get('page') || '1')
setSearchQuery(searchQueryParam)
setSortBy(sortByParam)
setOrder(orderParam)
setCurrentPage(pageParam)
const sortByParam = searchParams.get('sortBy') || defaultSortBy
const orderParam = searchParams.get('order') || defaultOrder
const rawPage = searchParams.get('page') || '1'
const pageParam = Number.isNaN(Number(rawPage))
? 1
: parseInt(rawPage, 10)
setSearchQuery(searchQueryParam)
setSortBy(sortByParam)
setOrder(orderParam)
setCurrentPage(pageParam)
🤖 Prompt for AI Agents
In frontend/src/hooks/useSearchPage.ts around lines 50 to 57, the parseInt call
for pageParam lacks an explicit radix and does not handle NaN values. Fix this
by adding a radix of 10 to parseInt and add a check to default pageParam to 1 if
the parsed value is NaN, ensuring robust handling of empty or invalid page query
parameters.

Comment on lines +56 to 61
icons={
Object.fromEntries(
Object.entries(filteredIcons).map(([key, value]) => [key, Boolean(value)])
) as Record<string, boolean>
}
button={SubmitButton}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Boolean-casting the icon map breaks existing UI – numbers become “true” strings

getFilteredIcons() used to return the actual numeric counts (stars, forks, …).
After this cast every entry is true, and DisplayIcon still renders the value next to the icon; users will now see the literal text true.

- icons={Object.fromEntries(
-   Object.entries(filteredIcons).map(([key, value]) => [key, Boolean(value)])
- ) as Record<string, boolean>}
+ // keep original numeric values (falsy entries filtered out)
+ icons={Object.fromEntries(
+   Object.entries(filteredIcons).filter(([_, value]) => Boolean(value))
+ ) as Record<string, number>}   // adjust type accordingly

You will also need to revert the icons type change (see types/card.ts) or make DisplayIcon ignore non-numeric truthy values.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
icons={
Object.fromEntries(
Object.entries(filteredIcons).map(([key, value]) => [key, Boolean(value)])
) as Record<string, boolean>
}
button={SubmitButton}
icons={
// keep original numeric values (falsy entries filtered out)
Object.fromEntries(
Object.entries(filteredIcons).filter(([_, value]) => Boolean(value))
) as Record<string, number>
}
button={SubmitButton}
🤖 Prompt for AI Agents
In frontend/src/app/contribute/page.tsx around lines 56 to 61, the code
incorrectly casts all icon values to boolean, causing numeric counts to display
as the string "true" in the UI. To fix this, remove the Boolean cast so that the
original numeric counts from getFilteredIcons() are preserved and passed to the
icons prop. Additionally, revert any related type changes in types/card.ts to
accept numeric values again or update DisplayIcon to handle non-numeric truthy
values properly.

Comment on lines +80 to 94
{icons && Object.keys(Icons).some((key) => icons[key as keyof typeof icons]) && (
<div className="mt-3 flex flex-wrap">
{Object.keys(Icons).map((key, index) =>
icons[key] ? (
{Object.keys(Icons).map((key, index) => {
const iconKey = key as keyof typeof icons;
return icons[iconKey] ? (
<DisplayIcon
key={`${key}-${index}`}
item={key}
icons={Object.fromEntries(Object.entries(icons).filter(([_, value]) => value))}
icons={Object.fromEntries(
Object.entries(icons).filter(([_, value]) => Boolean(value))
)}
/>
) : null
)}
) : null;
})}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

icons are filtered but still passed with boolean/number ambiguity

DisplayIcon expects an object whose values are displayable (number/string).
Because we pass booleans, the component renders the literal text true. Either:

  1. Revert to the original numeric object (preferred – keeps counts visible), or
  2. Update DisplayIcon to suppress non-numeric values.

Example quick fix inside DisplayIcon:

-{typeof icons[item] === 'number'
-  ? millify(icons[item], { precision: 1 })
-  : icons[item]}
+{typeof icons[item] === 'number'
+  ? millify(icons[item], { precision: 1 })
+  : null}

Choose one path and align types/card.ts accordingly.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In frontend/src/components/Card.tsx around lines 80 to 94, the icons object is
filtered but still contains boolean values, which causes DisplayIcon to render
literal "true" text. To fix this, revert to passing the original numeric values
for icons instead of booleans, ensuring DisplayIcon receives displayable numbers
or strings. Also, update the types in types/card.ts to reflect that icons hold
numeric or string values, not booleans.

Comment on lines +18 to +39
level?: {
level: string
color: string
icon: any
}
icons?: Record<string, boolean>
topContributors?: Contributor[]
button: {
url: string
onclick?: () => void
icon?: React.ReactNode
label?: string
}
projectName?: string
projectLink?: string
social?: {
title: string
url: string
}[]
tooltipLabel?: string
labels?: string[]
languages?: string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Type drift causing runtime/UI bugs

Changing icons from Record<string, number | string> to Record<string, boolean> unintentionally removed star/fork counts and introduced the “true” rendering bug. Decide which of these two designs you need:

Counts visible → revert to the previous numeric union type.
Icons only → keep boolean but update DisplayIcon to hide the value.

Synchronise page.tsx and Card.tsx with the chosen approach to restore type safety.

🤖 Prompt for AI Agents
In frontend/src/types/card.ts between lines 18 and 39, the type of the `icons`
property was changed from `Record<string, number | string>` to `Record<string,
boolean>`, which removed star/fork counts and caused UI bugs. Decide if you want
to keep counts visible or only icons: if counts are needed, revert `icons` to
`Record<string, number | string>`; if only icons are needed, keep
`Record<string, boolean>` but update `DisplayIcon` to not render values. Also,
update `page.tsx` and `Card.tsx` accordingly to maintain type safety and
consistent rendering.

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.

1 participant