Files
thrilltrack-explorer/src/hooks/useContributorLeaderboard.ts
gpt-engineer-app[bot] 9b1c2415b0 Add contributor leaderboard
Add types, hook, UI components, and integration for leaderboard showing top users with badges
2025-11-11 17:51:15 +00:00

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
});
}