mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-05 03:12:34 -06:00
added front - react+ts
ocr improved
This commit is contained in:
48
rmser-view/src/hooks/useOcr.ts
Normal file
48
rmser-view/src/hooks/useOcr.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '../services/api';
|
||||
import type { MatchRequest, ProductMatch, CatalogItem, UnmatchedItem } from '../services/types';
|
||||
import { message } from 'antd';
|
||||
|
||||
export const useOcr = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const catalogQuery = useQuery<CatalogItem[], Error>({
|
||||
queryKey: ['catalog'],
|
||||
queryFn: api.getCatalogItems,
|
||||
staleTime: 1000 * 60 * 5,
|
||||
});
|
||||
|
||||
const matchesQuery = useQuery<ProductMatch[], Error>({
|
||||
queryKey: ['matches'],
|
||||
queryFn: api.getMatches,
|
||||
});
|
||||
|
||||
const unmatchedQuery = useQuery<UnmatchedItem[], Error>({
|
||||
queryKey: ['unmatched'],
|
||||
queryFn: api.getUnmatched,
|
||||
staleTime: 0,
|
||||
});
|
||||
|
||||
const createMatchMutation = useMutation({
|
||||
// Теперь типы совпадают, any не нужен
|
||||
mutationFn: (newMatch: MatchRequest) => api.createMatch(newMatch),
|
||||
onSuccess: () => {
|
||||
message.success('Связь сохранена');
|
||||
queryClient.invalidateQueries({ queryKey: ['matches'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['unmatched'] });
|
||||
},
|
||||
onError: () => {
|
||||
message.error('Ошибка при сохранении');
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
catalog: catalogQuery.data || [],
|
||||
matches: matchesQuery.data || [],
|
||||
unmatched: unmatchedQuery.data || [],
|
||||
isLoading: catalogQuery.isPending || matchesQuery.isPending,
|
||||
isError: catalogQuery.isError || matchesQuery.isError,
|
||||
createMatch: createMatchMutation.mutate,
|
||||
isCreating: createMatchMutation.isPending,
|
||||
};
|
||||
};
|
||||
12
rmser-view/src/hooks/useRecommendations.ts
Normal file
12
rmser-view/src/hooks/useRecommendations.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../services/api';
|
||||
import type { Recommendation } from '../services/types';
|
||||
|
||||
export const useRecommendations = () => {
|
||||
return useQuery<Recommendation[], Error>({
|
||||
queryKey: ['recommendations'],
|
||||
queryFn: api.getRecommendations,
|
||||
// Обновлять данные каждые 30 секунд, если вкладка активна
|
||||
refetchInterval: 30000,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user