mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { findMatches, getMatchById, getTopMatches, updateMatchStatus, type FindMatchesQuery } from '@/services/matching-api';
|
|
|
|
/**
|
|
* Query key factory for matches
|
|
*/
|
|
export const matchingKeys = {
|
|
all: ['matches'] as const,
|
|
byResource: (resourceId: string, query?: FindMatchesQuery) =>
|
|
[...matchingKeys.all, 'resource', resourceId, query] as const,
|
|
top: (limit?: number) => [...matchingKeys.all, 'top', limit] as const,
|
|
detail: (matchId: string) => [...matchingKeys.all, 'detail', matchId] as const,
|
|
};
|
|
|
|
/**
|
|
* Hook to find matches for a resource
|
|
* Returns empty array immediately to prevent blocking render
|
|
*/
|
|
export function useFindMatches(resourceId: string | null | undefined, query?: FindMatchesQuery) {
|
|
return useQuery({
|
|
queryKey: matchingKeys.byResource(resourceId!, query),
|
|
queryFn: () => findMatches(resourceId!, query),
|
|
enabled: !!resourceId,
|
|
placeholderData: { matches: [] }, // Render immediately with empty array
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to get top matches across the platform
|
|
*/
|
|
export function useTopMatches(limit?: number) {
|
|
return useQuery({
|
|
queryKey: matchingKeys.top(limit),
|
|
queryFn: () => getTopMatches(limit),
|
|
placeholderData: { matches: [] }, // Render immediately with empty array
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to get a single match by ID
|
|
*/
|
|
export function useMatch(matchId: string | null | undefined) {
|
|
return useQuery({
|
|
queryKey: matchingKeys.detail(matchId!),
|
|
queryFn: () => getMatchById(matchId!),
|
|
enabled: !!matchId,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Hook to update match status
|
|
*/
|
|
export function useUpdateMatchStatus() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({
|
|
matchId,
|
|
status,
|
|
actor,
|
|
notes,
|
|
}: {
|
|
matchId: string;
|
|
status: string;
|
|
actor: string;
|
|
notes?: string;
|
|
}) => updateMatchStatus(matchId, status, actor, notes),
|
|
onSuccess: (_, { matchId }) => {
|
|
// Invalidate the specific match and related queries
|
|
queryClient.invalidateQueries({ queryKey: matchingKeys.detail(matchId) });
|
|
queryClient.invalidateQueries({ queryKey: matchingKeys.top() });
|
|
},
|
|
});
|
|
}
|