chore: drop unused SWR hooks and dependency
useSchools, useFilters, useMetrics and useSchoolDetails were imported by nothing and were the only consumers of swr. All data fetching goes through lib/api.ts on the server. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Custom hook for fetching filter options with SWR
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import useSWR from 'swr';
|
||||
import { fetcher } from '@/lib/api';
|
||||
import type { FiltersResponse } from '@/lib/types';
|
||||
|
||||
export function useFilters() {
|
||||
const { data, error, isLoading } = useSWR<FiltersResponse>(
|
||||
'/filters',
|
||||
fetcher,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
dedupingInterval: 60000, // 1 minute
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
filters: data,
|
||||
localAuthorities: data?.local_authorities || [],
|
||||
schoolTypes: data?.school_types || [],
|
||||
years: data?.years || [],
|
||||
isLoading,
|
||||
error,
|
||||
};
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* 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,
|
||||
};
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Custom hook for fetching school details with SWR
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import useSWR from 'swr';
|
||||
import { fetcher } from '@/lib/api';
|
||||
import type { SchoolDetailsResponse } from '@/lib/types';
|
||||
|
||||
export function useSchoolDetails(urn: number | null) {
|
||||
const { data, error, isLoading, mutate } = useSWR<SchoolDetailsResponse>(
|
||||
urn ? `/schools/${urn}` : null,
|
||||
fetcher,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
dedupingInterval: 30000, // 30 seconds
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
schoolInfo: data?.school_info,
|
||||
yearlyData: data?.yearly_data || [],
|
||||
isLoading,
|
||||
error,
|
||||
mutate,
|
||||
};
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Custom hook for fetching schools with SWR
|
||||
*/
|
||||
|
||||
'use client';
|
||||
|
||||
import useSWR from 'swr';
|
||||
import { fetcher } from '@/lib/api';
|
||||
import type { SchoolsResponse, SchoolSearchParams } from '@/lib/types';
|
||||
|
||||
export function useSchools(params: SchoolSearchParams = {}, shouldFetch: boolean = true) {
|
||||
const queryParams = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
queryParams.set(key, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
const queryString = queryParams.toString();
|
||||
const url = `/schools${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
const { data, error, isLoading, mutate } = useSWR<SchoolsResponse>(
|
||||
shouldFetch ? url : null,
|
||||
fetcher,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
dedupingInterval: 5000, // 5 seconds
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
schools: data?.schools || [],
|
||||
pagination: data ? {
|
||||
page: data.page,
|
||||
page_size: data.page_size,
|
||||
total: data.total,
|
||||
total_pages: data.total_pages,
|
||||
} : null,
|
||||
searchMode: data?.search_mode,
|
||||
locationInfo: data?.location_info,
|
||||
isLoading,
|
||||
error,
|
||||
mutate,
|
||||
};
|
||||
}
|
||||
Generated
+2
-23
@@ -21,7 +21,6 @@
|
||||
"react-chartjs-2": "^5.3.1",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-leaflet": "^5.0.0",
|
||||
"swr": "^2.4.0",
|
||||
"typescript": "^5.9.3",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
@@ -4150,7 +4149,9 @@
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz",
|
||||
"integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
@@ -9154,19 +9155,6 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/swr": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/swr/-/swr-2.4.0.tgz",
|
||||
"integrity": "sha512-sUlC20T8EOt1pHmDiqueUWMmRRX03W7w5YxovWX7VR2KHEPCTMly85x05vpkP5i6Bu4h44ePSMD9Tc+G2MItFw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dequal": "^2.0.3",
|
||||
"use-sync-external-store": "^1.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/symbol-tree": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
|
||||
@@ -9627,15 +9615,6 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/use-sync-external-store": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
|
||||
"integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/v8-to-istanbul": {
|
||||
"version": "9.3.0",
|
||||
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz",
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
"react-chartjs-2": "^5.3.1",
|
||||
"react-dom": "^19.2.4",
|
||||
"react-leaflet": "^5.0.0",
|
||||
"swr": "^2.4.0",
|
||||
"typescript": "^5.9.3",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user