mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -05:00
Add types, hook, UI components, and integration for leaderboard showing top users with badges
26 lines
804 B
TypeScript
26 lines
804 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { supabase } from '@/lib/supabaseClient';
|
|
import { LeaderboardData, TimePeriod } from '@/types/contributor';
|
|
import { queryKeys } from '@/lib/queryKeys';
|
|
|
|
export function useContributorLeaderboard(
|
|
limit: number = 50,
|
|
timePeriod: TimePeriod = 'all_time'
|
|
) {
|
|
return useQuery({
|
|
queryKey: queryKeys.analytics.contributorLeaderboard(limit, timePeriod),
|
|
queryFn: async () => {
|
|
const { data, error } = await supabase.rpc('get_contributor_leaderboard', {
|
|
limit_count: limit,
|
|
time_period: timePeriod,
|
|
});
|
|
|
|
if (error) throw error;
|
|
|
|
return data as unknown as LeaderboardData;
|
|
},
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
refetchInterval: 5 * 60 * 1000, // Refresh every 5 minutes
|
|
});
|
|
}
|