Files
signal-platform/frontend/src/hooks/useScores.ts
Dennis Thiessen 61ab24490d
Some checks failed
Deploy / lint (push) Failing after 7s
Deploy / test (push) Has been skipped
Deploy / deploy (push) Has been skipped
first commit
2026-02-20 17:31:01 +01:00

27 lines
785 B
TypeScript

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