Skip to content

Add GitHub star count to website header#174

Merged
LittleLittleCloud merged 8 commits intomainfrom
copilot/add-stars-to-app-bar
Nov 23, 2025
Merged

Add GitHub star count to website header#174
LittleLittleCloud merged 8 commits intomainfrom
copilot/add-stars-to-app-bar

Conversation

Copy link
Contributor

Copilot AI commented Nov 23, 2025

Adding GitHub star count display to the website app bar header.

Plan:

  • Create a hook to fetch GitHub star count from GitHub API
  • Update Layout.tsx to display star count next to GitHub icon
  • Handle loading and error states appropriately
  • Ensure responsive design works on mobile
  • Test the build and visual appearance
  • Address code review feedback (abort controller, memory leak prevention)
  • Make compact version per feedback (icon + number only)
  • Improve number formatting (2k not 2.0k)
  • Add aria-label for accessibility
  • Add hover cursor effect for better UX
  • Reset stars to null on error

Implementation Details

Created src/hooks/useGitHubStars.ts:

  • Custom React hook that fetches star count from GitHub API
  • Returns stars, loading, and error states
  • Handles API errors gracefully
  • Includes AbortController to prevent memory leaks and race conditions
  • Ignores abort errors on component unmount
  • Resets stars to null on error to reflect error state correctly

Updated src/components/Layout.tsx:

  • Compact design: Shows only GitHub icon + star count (no "GitHub" text, no star icon)
  • Larger icon (w-5 h-5 instead of w-4 h-4) for better visibility
  • Smart number formatting:
    • Numbers ≥1000 display as "X.Xk" (e.g., 100.5k, 1.2k)
    • Removes unnecessary decimals (2k instead of 2.0k)
  • Accessibility: Added dynamic aria-label that includes star count when available
  • UX improvement: Pointer cursor on hover (hover:cursor-pointer) provides visual feedback for clickability
  • Uses gap-1.5 for tight spacing between icon and number
  • Desktop only (hidden on mobile navigation)
  • Conditional rendering with graceful fallback

Visual Changes

Compact Version (Current)

The new compact design shows:

  • Just icon + number: GitHub icon followed by star count
  • Smart formatting: 100.5k, 2k, 1.2k, 325 (formats numbers ≥1000 with "k" suffix, no trailing .0)
  • Minimal footprint: Takes up less space in the header
  • Hover feedback: Pointer cursor on hover indicates clickability

GitHub button with star count

Accessibility Improvements

  • Screen reader support: Dynamic aria-label announces star count
    • With stars: "GitHub - 123 stars"
    • Without stars: "View on GitHub"

Graceful Degradation

The implementation handles edge cases elegantly:

  • ✅ API failures → Shows just GitHub icon without count, resets stars to null
  • ✅ Loading state → Shows just GitHub icon until loaded
  • ✅ Rate limiting → Fails silently, shows icon only
  • ✅ Network issues → Falls back to icon-only button
  • ✅ Component unmount → Proper cleanup via AbortController

Quality Assurance

  • Build: Successfully compiles with TypeScript
  • Lint: Passes ESLint checks
  • Code Review: All feedback addressed
  • Security: CodeQL scan passed with 0 alerts
  • Browser Compatibility: Uses standard Fetch API
  • Mobile Responsive: Hidden on mobile screens
  • Accessibility: ARIA labels for screen readers
  • UX: Pointer cursor on hover for better feedback

Files Changed

  • website/src/components/Layout.tsx (compact design with aria-label and hover cursor)
  • website/src/hooks/useGitHubStars.ts (resets stars on error)

<issue_title>[Feature]: show GitHub stars on webside</issue_title>

Feature Description

As title

Problem Statement

No response

Proposed Solution

Use copilot to add star number to App bar

Alternatives Considered

No response

Additional Context

No response

Contribution

  • I'd be willing to contribute this feature
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: show GitHub stars on webside</issue_title>
<issue_description>### Feature Description

As title

Problem Statement

No response

Proposed Solution

Use copilot to add star number to App bar

Alternatives Considered

No response

Additional Context

No response

Contribution

  • I'd be willing to contribute this feature</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 23, 2025 16:30
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature to show GitHub stars on app bar Add GitHub star count to website header Nov 23, 2025
@github-actions
Copy link

github-actions bot commented Nov 23, 2025

🚀 Preview Deployment

A preview build has been generated for this PR!

Download the artifact:
website-preview-pr-174

To view the preview locally:

  1. Download the artifact from the workflow run
  2. Extract the ZIP file
  3. Serve the files with a local web server
    (e.g., npx serve dist)

Live Preview URL: https://0f2c01a3.razorconsole.pages.dev

The live preview will be automatically updated when you push new
commits to this PR.

@LittleLittleCloud
Copy link
Member

@copilot use a more tiny version, like below

image

Copilot AI and others added 2 commits November 23, 2025 17:25
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
…f 2.0k)

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 23, 2025

@copilot use a more tiny version, like below

image

...

Updated to compact version matching your reference. Changes in commit c095020:

  • Removed "GitHub" text label
  • Shows only icon + star count
  • Larger icon for better visibility
  • Smart number formatting (100.5k, 2k, 325)

Compact Version

@LittleLittleCloud LittleLittleCloud marked this pull request as ready for review November 23, 2025 17:37
Copilot AI review requested due to automatic review settings November 23, 2025 17:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a GitHub star count display to the website header by introducing a new React hook that fetches repository data from the GitHub API and integrating it into the navigation bar. The star count appears next to the GitHub icon with smart formatting (e.g., "2k" for 2000 stars).

Key changes:

  • New custom hook useGitHubStars for fetching and managing star count state
  • Updated Layout component to display formatted star count in the header button
  • Desktop-only display with graceful fallback when stars aren't loaded

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
website/src/hooks/useGitHubStars.ts New hook that fetches GitHub repository star count with proper cleanup using AbortController
website/src/components/Layout.tsx Integrates the star count hook and displays formatted stars next to the GitHub icon in the header


export default function Layout() {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
const { stars } = useGitHubStars('LittleLittleCloud', 'RazorConsole')
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The loading and error values returned from the useGitHubStars hook are destructured but never used in the component. Consider using these values to provide better user feedback:

  • Show a loading indicator while fetching
  • Display an error message or fallback UI when the fetch fails
  • Alternatively, if these states are intentionally ignored, remove them from the destructured return value to make the intent clearer.

Copilot uses AI. Check for mistakes.
Comment on lines 56 to 65
<Button variant="ghost" size="sm" className="gap-1.5">
<Github className="w-5 h-5" />
{stars !== null && (
<span className="text-sm font-medium">
{stars >= 1000
? `${(stars / 1000).toFixed(1).replace(/\.0$/, '')}k`
: stars.toLocaleString()}
</span>
)}
</Button>
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The button lacks an accessible label for screen readers. When the star count is not loaded (null), the button only contains the GitHub icon without any text, making it unclear to screen reader users what the button represents. Consider adding an aria-label attribute (e.g., aria-label="View on GitHub" or dynamically aria-label={stars !== null ? GitHub - ${stars} stars : "View on GitHub"}) to improve accessibility.

Copilot uses AI. Check for mistakes.
// Ignore abort errors
if (err instanceof Error && err.name === 'AbortError') {
return
}
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

When an error occurs, the stars state is not reset. This means if the hook successfully fetched stars previously, it will continue to display the old star count even when an error occurs on subsequent fetches. Consider adding setStars(null) in the error handling block to ensure the UI reflects the error state correctly.

Suggested change
}
}
setStars(null)

Copilot uses AI. Check for mistakes.
<Button variant="ghost" size="sm">
<Github className="w-4 h-4 mr-2" />
GitHub
<Button variant="ghost" size="sm" className="gap-1.5">
Copy link
Member

Choose a reason for hiding this comment

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

@copilot cursor should not be pointer style when hover on this button

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 9852552. Added cursor-default to the button className.

Cursor behavior fix

…r, reset stars on error

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
<Button
variant="ghost"
size="sm"
className="gap-1.5 cursor-default"
Copy link
Member

Choose a reason for hiding this comment

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

@copilot add on-hover effect for cursor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added pointer cursor on hover in commit f298757. Changed from cursor-default to hover:cursor-pointer.

Hover effect

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
@LittleLittleCloud LittleLittleCloud merged commit f7294b7 into main Nov 23, 2025
12 checks passed
@LittleLittleCloud LittleLittleCloud deleted the copilot/add-stars-to-app-bar branch November 23, 2025 19:06
@github-actions github-actions bot added this to the v0.2.0 milestone Nov 23, 2025
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.

[Feature]: show GitHub stars on webside

3 participants