Skip to content

Staging #31

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

Merged
merged 2 commits into from
Jun 2, 2025
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
4 changes: 4 additions & 0 deletions apps/web/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APP_URL=https://react-wheel-picker.chanhdai.com

# https://github.com/settings/tokens
GITHUB_API_TOKEN=
17 changes: 17 additions & 0 deletions apps/web/src/app/api/stargazers_count/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function GET() {
const data = await fetch(
"https://api.github.com/repos/ncdai/react-wheel-picker",
{
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.GITHUB_API_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
next: { revalidate: 86400 }, // Cache for 1 day (86400 seconds)
},
);
const json = await data.json();
return Response.json({
stargazers_count: json?.stargazers_count ?? -1,
});
}
12 changes: 6 additions & 6 deletions apps/web/src/components/stars-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import React from "react";
import useSWR from "swr";

const fetcher = (url: string) =>
fetch(url, { next: { revalidate: 86400 } }).then((r) => r.json()); // Cache for 1 day (86400 seconds)
const fetcher = (url: string) => fetch(url).then((r) => r.json());

type StarsCountResponse = {
stargazers_count: number;
};

export function StarsCount() {
const { data } = useSWR<StarsCountResponse>(
`https://api.github.com/repos/ncdai/react-wheel-picker`,
fetcher,
);
const { data } = useSWR<StarsCountResponse>(`/api/stargazers_count`, fetcher);

if (!data) {
return <span className="h-3 w-6 rounded-full bg-muted" />;
}

if (data.stargazers_count < 0) {
return <span className="h-3 w-6 rounded-full bg-muted" />;
}

return (
<span className="mt-px w-6 text-center font-mono text-xs/none font-medium text-muted-foreground tabular-nums">
{data.stargazers_count.toLocaleString()}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@changesets/cli": "^2.29.4",
"prettier": "3.5.3",
"turbo": "^2.5.3",
"turbo": "^2.5.4",
"typescript": "^5.8.3"
}
}
64 changes: 32 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.