Skip to content

feat: show live GitHub star count in navbar - #372

Open
bilal-rauf-dev wants to merge 1 commit into
anoopcodehack:mainfrom
bilal-rauf-dev:main
Open

feat: show live GitHub star count in navbar#372
bilal-rauf-dev wants to merge 1 commit into
anoopcodehack:mainfrom
bilal-rauf-dev:main

Conversation

@bilal-rauf-dev

Copy link
Copy Markdown

Closes #370

What this does

Replaces the dead "⭐ Star on GitHub" button in the navbar (it had no
href/onClick) with a real link to the repo that also shows the current
star count.

Before: static text, not clickable
After: clickable link β†’ "⭐ 123 Star on GitHub" (formatted as "1.2k" for β‰₯1000)

Note: the count is fetched once on page load, not polled β€” "live" here
means "current as of this page load," not continuously updating.

Implementation

Followed the existing pattern in useSuggestTags.jsx of keeping fetch
logic in a dedicated hook rather than inline in the component.

New β€” src/hooks/useGithubStars.js

  • Takes an optional repo param (default "anoopcodehack/DevBoard")
  • Fetches stargazers_count via axios + async/await on mount
  • Swallows errors (including GitHub's unauthenticated 403 rate limit) β€”
    logs a console.warn, leaves stars as null, never throws

Modified β€” src/pages/Dashboard.jsx

  • Uses useGithubStars(), adds a small formatStars helper
  • Swaps the <button> for an <a> (target="_blank" rel="noopener noreferrer")
  • Falls back to plain "⭐ Star on GitHub" while loading or on fetch failure β€”
    no layout shift
  • Reuses the existing Tailwind classes from the sibling "πŸ—‘οΈ Clear Done"
    button β€” no new styles

Testing done

  • npm run dev in client/, confirmed the link renders immediately and
    updates once the count loads
  • Confirmed it's clickable and opens the repo in a new tab
  • Blocked api.github.com in devtools to simulate a rate limit / offline
    case β€” button correctly falls back to plain text, no console errors,
    no crash

Checklist

  • My code follows the project's style guidelines
  • I tested my changes locally
  • I updated the README (not needed β€” no setup/usage change)
  • My commit messages are clear and follow the conventional commit format

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.

Show live GitHub star count in navbar ⭐

1 participant