/** * One place page, shared by all four families. * * They differ in what fills the registry, not in what the page shows, so a * second component would be a second place to forget the same change. * * The local-versus-England comparison is the reason this page is not a list: * it is the one number a parent cannot get by reading the schools one by one, * and it is what keeps the page from reading as a name dropped into a * template. */ import Link from 'next/link'; import type { PlaceDetail, PlaceSummary } from '@/lib/places'; import { placeUrl, authoritySlug } from '@/lib/places'; import { schoolUrl } from '@/lib/utils'; import styles from './PlaceView.module.css'; interface Props { detail: PlaceDetail; phase?: 'primary' | 'secondary'; englandAverage: number | null; /** Nearby places, so the page links onward instead of dead-ending. */ neighbours: PlaceSummary[]; } // Ofsted grades in the order they are reported. const OFSTED_LABELS: Array<[number, string]> = [ [1, 'Outstanding'], [2, 'Good'], [3, 'Requires improvement'], [4, 'Inadequate'], ]; export function PlaceView({ detail, phase, englandAverage, neighbours }: Props) { const { place, schools, averages } = detail; const metric = phase === 'secondary' ? 'attainment_8_score' : 'rwm_expected_pct'; const local = averages[metric]; const phaseWord = phase === 'secondary' ? 'Secondary schools' : phase === 'primary' ? 'Primary schools' : 'Schools'; const graded = OFSTED_LABELS .map(([grade, label]) => [label, schools.filter((s) => s.ofsted_grade === grade).length] as const) .filter(([, n]) => n > 0); return (

{phaseWord} in {place.name}

{place.count} schools {place.parent_authority && ( <> {' · '} {place.parent_authority} )}

{local != null && englandAverage != null && (

{place.name} averages {Math.round(local)} against{' '} {Math.round(englandAverage)} across England.

)} {graded.length > 0 && ( )}
{schools.map((s) => ( ))}
School {phase === 'secondary' ? 'Attainment 8' : 'RWM expected'}
{s.school_name} {s[metric] == null ? '—' : Math.round(Number(s[metric]))}
{neighbours.length > 0 && ( )}
); }