Files
school_compare/nextjs-app/hooks/useMetrics.ts
Tudor 4dc0c10c9d
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 35s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m10s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
Fix metrics API response structure
Backend returns metrics as an array, not an object.
- Update MetricsResponse type to use MetricDefinition[] instead of Record
- Remove Object.values() conversion in compare and rankings pages
- Fix useMetrics hook to handle array instead of object
- Fix getMetric to use array.find() instead of object indexing

Fixes empty metric dropdown on compare page.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 22:00:07 +00:00

29 lines
600 B
TypeScript

/**
* Custom hook for fetching metric definitions with SWR
*/
'use client';
import useSWR from 'swr';
import { fetcher } from '@/lib/api';
import type { MetricsResponse } from '@/lib/types';
export function useMetrics() {
const { data, error, isLoading } = useSWR<MetricsResponse>(
'/metrics',
fetcher,
{
revalidateOnFocus: false,
dedupingInterval: 60000, // 1 minute
}
);
return {
metrics: data?.metrics || [],
metricsList: data?.metrics || [],
getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
isLoading,
error,
};
}