From 4c229aec6ed8a271d08f5916d0b43ec96908f9f1 Mon Sep 17 00:00:00 2001 From: Tudor Date: Sun, 2 Aug 2026 21:39:59 +0100 Subject: [PATCH] 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 --- nextjs-app/hooks/useFilters.ts | 29 ------------------ nextjs-app/hooks/useMetrics.ts | 28 ----------------- nextjs-app/hooks/useSchoolDetails.ts | 28 ----------------- nextjs-app/hooks/useSchools.ts | 46 ---------------------------- nextjs-app/package-lock.json | 25 ++------------- nextjs-app/package.json | 1 - 6 files changed, 2 insertions(+), 155 deletions(-) delete mode 100644 nextjs-app/hooks/useFilters.ts delete mode 100644 nextjs-app/hooks/useMetrics.ts delete mode 100644 nextjs-app/hooks/useSchoolDetails.ts delete mode 100644 nextjs-app/hooks/useSchools.ts diff --git a/nextjs-app/hooks/useFilters.ts b/nextjs-app/hooks/useFilters.ts deleted file mode 100644 index 3045520..0000000 --- a/nextjs-app/hooks/useFilters.ts +++ /dev/null @@ -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( - '/filters', - fetcher, - { - revalidateOnFocus: false, - dedupingInterval: 60000, // 1 minute - } - ); - - return { - filters: data, - localAuthorities: data?.local_authorities || [], - schoolTypes: data?.school_types || [], - years: data?.years || [], - isLoading, - error, - }; -} diff --git a/nextjs-app/hooks/useMetrics.ts b/nextjs-app/hooks/useMetrics.ts deleted file mode 100644 index cb4f5bc..0000000 --- a/nextjs-app/hooks/useMetrics.ts +++ /dev/null @@ -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( - '/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, - }; -} diff --git a/nextjs-app/hooks/useSchoolDetails.ts b/nextjs-app/hooks/useSchoolDetails.ts deleted file mode 100644 index aec9be0..0000000 --- a/nextjs-app/hooks/useSchoolDetails.ts +++ /dev/null @@ -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( - urn ? `/schools/${urn}` : null, - fetcher, - { - revalidateOnFocus: false, - dedupingInterval: 30000, // 30 seconds - } - ); - - return { - schoolInfo: data?.school_info, - yearlyData: data?.yearly_data || [], - isLoading, - error, - mutate, - }; -} diff --git a/nextjs-app/hooks/useSchools.ts b/nextjs-app/hooks/useSchools.ts deleted file mode 100644 index 6858980..0000000 --- a/nextjs-app/hooks/useSchools.ts +++ /dev/null @@ -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( - 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, - }; -} diff --git a/nextjs-app/package-lock.json b/nextjs-app/package-lock.json index 4ce1fb4..81465f1 100644 --- a/nextjs-app/package-lock.json +++ b/nextjs-app/package-lock.json @@ -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", diff --git a/nextjs-app/package.json b/nextjs-app/package.json index d38b908..45a2434 100644 --- a/nextjs-app/package.json +++ b/nextjs-app/package.json @@ -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" },