mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 10:31:13 -05:00
Add contributor leaderboard
Add types, hook, UI components, and integration for leaderboard showing top users with badges
This commit is contained in:
25
src/hooks/useContributorLeaderboard.ts
Normal file
25
src/hooks/useContributorLeaderboard.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user