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
18 changes: 9 additions & 9 deletions docs/skillkit/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ export default function App(): React.ReactElement {
<path d="M13.604 8.4h-3.405V12h3.405a1.8 1.8 0 0 0 0-3.6zM12 0C5.372 0 0 5.372 0 12s5.372 12 12 12 12-5.372 12-12S18.628 0 12 0zm1.604 14.4h-3.405V18H7.801V6h5.804a4.2 4.2 0 0 1 0 8.4z"/>
</svg>
<span className="text-zinc-400 group-hover:text-white font-medium">Featured</span>
</a>
<span className="text-zinc-800 hidden sm:inline">·</span>
<a
href="https://github.com/rohitg00/skillkit/blob/main/LICENSE"
target="_blank"
rel="noopener noreferrer"
className="text-zinc-500 hover:text-white transition-colors hidden sm:inline"
>
Apache 2.0
{stats.phUpvotes > 0 && (
<>
<span className="text-zinc-700 mx-0.5">·</span>
<svg className="w-3 h-3 text-[#da552f]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M5 15l7-7 7 7" />
</svg>
<span className="text-white font-medium">{stats.phUpvotes}</span>
</>
)}
</a>
</div>
</div>
Expand Down
24 changes: 22 additions & 2 deletions docs/skillkit/hooks/useStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Stats {
version: string;
downloads: string;
stars: number;
phUpvotes: number;
loading: boolean;
}

Expand Down Expand Up @@ -57,6 +58,7 @@ export function useStats(): Stats {
version: '1.9.0',
downloads: '2.4k',
stars: 66,
phUpvotes: 0,
loading: true,
});

Expand All @@ -69,13 +71,19 @@ export function useStats(): Stats {

async function fetchStats(): Promise<void> {
try {
const [npmResponse, githubResponse] = await Promise.allSettled([
const [npmResponse, githubResponse, phResponse] = await Promise.allSettled([
fetch('https://api.npmjs.org/downloads/point/last-month/skillkit'),
fetch('https://api.github.com/repos/rohitg00/skillkit'),
fetch('https://api.producthunt.com/v2/api/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ post(slug: "skillkit-2") { votesCount } }' }),
}),
]);

let downloads = '2.4k';
let stars = 66;
let phUpvotes = 0;
let version = '1.9.0';

if (npmResponse.status === 'fulfilled' && npmResponse.value.ok) {
Expand All @@ -92,6 +100,18 @@ export function useStats(): Stats {
}
}

if (phResponse.status === 'fulfilled' && phResponse.value.ok) {
try {
const phData = await phResponse.value.json();
const votes = phData?.data?.post?.votesCount;
if (typeof votes === 'number' && Number.isFinite(votes)) {
phUpvotes = votes;
}
} catch {
// PH API may require auth, fall back silently
}
}

try {
const registryResponse = await fetch('https://registry.npmjs.org/skillkit/latest');
if (registryResponse.ok) {
Expand All @@ -104,7 +124,7 @@ export function useStats(): Stats {
// Use default version
}

const newStats = { version, downloads, stars };
const newStats = { version, downloads, stars, phUpvotes };
setCachedStats(newStats);
setStats({ ...newStats, loading: false });
} catch {
Expand Down