first commit
This commit is contained in:
26
frontend/src/hooks/useScores.ts
Normal file
26
frontend/src/hooks/useScores.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import * as scoresApi from '../api/scores';
|
||||
import { useToast } from '../components/ui/Toast';
|
||||
|
||||
export function useRankings() {
|
||||
return useQuery({
|
||||
queryKey: ['rankings'],
|
||||
queryFn: () => scoresApi.getRankings(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateWeights() {
|
||||
const qc = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (weights: Record<string, number>) => scoresApi.updateWeights(weights),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['rankings'] });
|
||||
addToast('success', 'Weights updated successfully');
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
addToast('error', error.message || 'Failed to update weights');
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user