Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/components/GitHubInstallButtons/index.tsx
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") {
Expand Down Expand Up @@ -47,7 +57,7 @@ async function getVSCodeDownloads() {
criteria: [
{
filterType: 7,
value: "RooVeterinaryInc.roo-cline",
value: VSCODE_MARKETPLACE_EXTENSION_ID,
},
],
},
Expand All @@ -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);
Comment thread
navedmerchant marked this conversation as resolved.
const [downloads, setDownloads] = useState<string | null>(null);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removing the fallback also leaves the install CTA rendered as Install · until the marketplace request resolves, and permanently if it fails. If the count is intentionally live-only, the separator still needs to stay conditional so the label does not ship in this broken state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Expand All @@ -88,7 +98,7 @@ export default function GitHubInstallButtons(): React.JSX.Element {
});

getVSCodeDownloads().then(count => {
if (count) setDownloads(count);
if (count) setDownloads(formatNumber(count));
});
}, []);

Expand Down Expand Up @@ -122,4 +132,4 @@ export default function GitHubInstallButtons(): React.JSX.Element {
</a>
</div>
);
}
}
7 changes: 5 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*/

// GitHub repository information
export const GITHUB_REPO_URL = 'https://github.com/Zoo-Code-Org/Zoo-Code-Docs';
export const GITHUB_REPO_SLUG = 'Zoo-Code-Org/Zoo-Code-Docs';
export const GITHUB_REPO_URL = `https://github.com/${GITHUB_REPO_SLUG}`;
export const GITHUB_ISSUES_URL = `${GITHUB_REPO_URL}/issues`;
export const GITHUB_NEW_ISSUE_URL = `${GITHUB_ISSUES_URL}/new`;

Expand All @@ -14,11 +15,13 @@ export const TWITTER_URL = 'https://x.com/ZooCodeDev';
export const LINKEDIN_URL = 'https://www.linkedin.com';

// GitHub links
export const GITHUB_MAIN_REPO_URL = 'https://github.com/Zoo-Code-Org/Zoo-Code';
export const GITHUB_MAIN_REPO_SLUG = 'Zoo-Code-Org/Zoo-Code';
export const GITHUB_MAIN_REPO_URL = `https://github.com/${GITHUB_MAIN_REPO_SLUG}`;
export const GITHUB_ISSUES_MAIN_URL = `${GITHUB_MAIN_REPO_URL}/issues`;
export const GITHUB_FEATURES_URL = `${GITHUB_MAIN_REPO_URL}/discussions/categories/feature-requests?discussions_q=is%3Aopen+category%3A%22Feature+Requests%22+sort%3Atop`;

// Download links
export const VSCODE_MARKETPLACE_EXTENSION_ID = 'ZooCodeOrganization.zoo-code';
export const VSCODE_MARKETPLACE_URL = 'https://marketplace.visualstudio.com/items?itemName=ZooCodeOrganization.zoo-code';
export const OPEN_VSX_URL = 'https://open-vsx.org/extension/ZooCodeOrganization.zoo-code';

Expand Down
Loading