import { useState, useEffect, useCallback } from 'react';
export interface LeaderboardEntry {
rank: string;
builder: string;
builderCode: string;
builderLogo?: string;
volume: number;
activeUsers: number;
verified: boolean;
}
type Period = 'DAY' | 'WEEK' | 'MONTH' | 'ALL';
export function useLeaderboard(period: Period = 'ALL') {
const [entries, setEntries] = useState<LeaderboardEntry[]>([]);
const [loading, setLoading] = useState(true);
const fetch_ = useCallback(async () => {
setLoading(true);
try {
const res = await fetch(`/api/analytics/rank?period=${period}`);
const d = await res.json();
if (d.leaderboard) {
setEntries(d.leaderboard);
}
} catch { /* ignore */ }
setLoading(false);
}, [period]);
useEffect(() => {
const t = setTimeout(fetch_, 0);
return () => { clearTimeout(t); };
}, [fetch_]);
return { entries, loading, refresh: fetch_ };
}
📜 Git History
6c47fa4chore: local Polikopi project home + Phase 1 redesign artifacts12 days ago
Show last diff
Loading...