turash/bugulma/frontend/hooks/api/useAnalyticsAPI.ts
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- 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.
2025-11-25 06:02:57 +01:00

94 lines
2.5 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import type {
ConnectionStatistics,
DashboardStatistics,
SupplyDemandAnalysis,
} from '@/services/analytics-api.ts';
import * as analyticsApi from '@/services/analytics-api.ts';
/**
* Get connection statistics
* Returns safe defaults immediately to prevent blocking render
*/
export function useConnectionStatistics() {
return useQuery<ConnectionStatistics>({
queryKey: ['analytics', 'connections'],
queryFn: analyticsApi.getConnectionStatistics,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
placeholderData: { total_connections: 0 }, // Render immediately with default
});
}
/**
* Get supply and demand analysis
* Returns safe defaults immediately to prevent blocking render
*/
export function useSupplyDemandAnalysis() {
return useQuery<SupplyDemandAnalysis>({
queryKey: ['analytics', 'supply-demand'],
queryFn: analyticsApi.getSupplyDemandAnalysis,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
placeholderData: { supply: [], demand: [] }, // Render immediately with empty arrays
});
}
/**
* Get dashboard statistics
* Returns safe defaults immediately to prevent blocking render
*/
export function useDashboardStatistics() {
return useQuery<DashboardStatistics>({
queryKey: ['analytics', 'dashboard'],
queryFn: analyticsApi.getDashboardStatistics,
staleTime: 2 * 60 * 1000, // Cache for 2 minutes
placeholderData: {
total_organizations: 0,
recent_activity: [],
}, // Render immediately with defaults
});
}
/**
* Get platform statistics
*/
export function usePlatformStatistics() {
return useQuery({
queryKey: ['analytics', 'platform'],
queryFn: analyticsApi.getPlatformStatistics,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
});
}
/**
* Get matching statistics
*/
export function useMatchingStatistics() {
return useQuery({
queryKey: ['analytics', 'matching'],
queryFn: analyticsApi.getMatchingStatistics,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
});
}
/**
* Get resource flow statistics
*/
export function useResourceFlowStatistics() {
return useQuery({
queryKey: ['analytics', 'resource-flow'],
queryFn: analyticsApi.getResourceFlowStatistics,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
});
}
/**
* Get impact metrics
*/
export function useImpactMetrics() {
return useQuery({
queryKey: ['analytics', 'impact'],
queryFn: analyticsApi.getImpactMetrics,
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
});
}