-
Notifications
You must be signed in to change notification settings - Fork 1
[Fix] Docs navbar shows the wrong GitHub and VS Code counts #3
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
Changes from all commits
5a35b0f
9056e95
ee3e42d
5db3afb
b83fad3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,33 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import { RxGithubLogo } from "react-icons/rx"; | ||
| import { VscVscode } from "react-icons/vsc"; | ||
| import { GITHUB_MAIN_REPO_URL, SIGN_IN_URL, SIGN_UP_URL, VSCODE_MARKETPLACE_URL } from '@site/src/constants'; | ||
| import { | ||
| GITHUB_MAIN_REPO_SLUG, | ||
| GITHUB_MAIN_REPO_URL, | ||
| VSCODE_MARKETPLACE_EXTENSION_ID, | ||
| VSCODE_MARKETPLACE_URL, | ||
| } from '@site/src/constants'; | ||
| import styles from './styles.module.css'; | ||
|
|
||
| // Number formatting function | ||
| function formatNumber(num: number): string { | ||
| if (num < 10000) { | ||
| return num.toLocaleString(); | ||
| } | ||
|
|
||
| if (num >= 1000000) { | ||
| const truncated = Math.floor((num / 1000000) * 10) / 10; | ||
| return truncated.toFixed(1) + "M"; | ||
| } | ||
|
|
||
| const truncated = Math.floor((num / 1000) * 10) / 10; | ||
| return truncated.toFixed(1) + "k"; | ||
| } | ||
|
|
||
| // GitHub Stars API | ||
| async function getGitHubStars() { | ||
| try { | ||
| const res = await fetch("https://api.github.com/repos/RooCodeInc/Roo-Code"); | ||
| const res = await fetch(`https://api.github.com/repos/${GITHUB_MAIN_REPO_SLUG}`); | ||
| const data = await res.json(); | ||
|
|
||
| if (typeof data.stargazers_count !== "number") { | ||
|
|
@@ -47,7 +57,7 @@ async function getVSCodeDownloads() { | |
| criteria: [ | ||
| { | ||
| filterType: 7, | ||
| value: "RooVeterinaryInc.roo-cline", | ||
| value: VSCODE_MARKETPLACE_EXTENSION_ID, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
@@ -70,16 +80,16 @@ async function getVSCodeDownloads() { | |
| return null; | ||
| } | ||
|
|
||
| return formatNumber(installStat.value); | ||
| return installStat.value; | ||
| } catch (error) { | ||
| console.error("Error fetching VSCode downloads:", error); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export default function GitHubInstallButtons(): React.JSX.Element { | ||
| const [stars, setStars] = useState<string | null>("15.4k"); | ||
| const [downloads, setDownloads] = useState<string | null>("574.1k"); | ||
| const [stars, setStars] = useState<string | null>(null); | ||
| const [downloads, setDownloads] = useState<string | null>(null); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the fallback also leaves the install CTA rendered as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you could use a loading skeleton or something, but I’m ok with an empty string or even |
||
|
|
||
| useEffect(() => { | ||
| // Fetch live data | ||
|
|
@@ -88,7 +98,7 @@ export default function GitHubInstallButtons(): React.JSX.Element { | |
| }); | ||
|
|
||
| getVSCodeDownloads().then(count => { | ||
| if (count) setDownloads(count); | ||
| if (count) setDownloads(formatNumber(count)); | ||
| }); | ||
| }, []); | ||
|
|
||
|
|
@@ -122,4 +132,4 @@ export default function GitHubInstallButtons(): React.JSX.Element { | |
| </a> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.