Skip to content

Commit

Permalink
defer stats in loader (#134)
Browse files Browse the repository at this point in the history
also fix types for stats
  • Loading branch information
pcattori authored Nov 19, 2024
1 parent 740e01e commit 6427199
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
48 changes: 23 additions & 25 deletions app/modules/stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,32 @@ global.statCountsCache ??= new LRUCache<string, StatCounts>({
},
});

export async function getStats(): Promise<Stats[] | undefined> {
export async function getStats(): Promise<Stats[]> {
let cacheKey = "ONE_STATS_KEY_TO_RULE_THEM_ALL";
let statCounts = await statCountsCache.fetch(cacheKey);

return statCounts
? [
{
count: statCounts.npmDownloads,
label: "Downloads on npm",
svgId: "stat-download",
},
{
count: statCounts.githubContributors,
label: "Contributors on GitHub",
svgId: "stat-users",
},
{
count: statCounts.githubStars,
label: "Stars on GitHub",
svgId: "stat-star",
},
{
count: statCounts.githubDependents,
label: "Dependents on GitHub",
svgId: "stat-box",
},
]
: undefined;
return [
{
count: statCounts.npmDownloads,
label: "Downloads on npm",
svgId: "stat-download",
},
{
count: statCounts.githubContributors,
label: "Contributors on GitHub",
svgId: "stat-users",
},
{
count: statCounts.githubStars,
label: "Stars on GitHub",
svgId: "stat-star",
},
{
count: statCounts.githubDependents,
label: "Dependents on GitHub",
svgId: "stat-box",
},
];
}

/**
Expand Down
7 changes: 1 addition & 6 deletions app/pages/splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { getStats } from "~/modules/stats";
import { getRootMatchData } from "~/ui/meta";

export let loader = async () => {
const stats = await getStats();
// replace with something better, just fixing types
if (!stats) {
throw new Error("Failed to load stats");
}
const stats = getStats();
return { stats };
};

Expand Down Expand Up @@ -153,7 +149,6 @@ export default function Home() {
<Await resolve={stats} errorElement={null}>
{(stats) => (
<ul className="mt-8 grid grid-cols-1 gap-8 md:grid md:grid-cols-2">
{/* @ts-expect-error -- these types didn't make it into RR7, this needs to be fixed */}
{stats.map(({ svgId, count, label }) => (

Check failure on line 152 in app/pages/splash.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Binding element 'svgId' implicitly has an 'any' type.

Check failure on line 152 in app/pages/splash.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Binding element 'count' implicitly has an 'any' type.

Check failure on line 152 in app/pages/splash.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Binding element 'label' implicitly has an 'any' type.
<li key={svgId} className="flex gap-4">
<svg
Expand Down

0 comments on commit 6427199

Please sign in to comment.