2026-03-23 22:32:33 +00:00
|
|
|
/**
|
|
|
|
|
* SchoolRow Component
|
2026-03-24 09:27:22 +00:00
|
|
|
* Three-line row for school search results
|
|
|
|
|
*
|
|
|
|
|
* Line 1: School name · School type
|
|
|
|
|
* Line 2: R,W&M % · Progress score · Pupil count
|
|
|
|
|
* Line 3: Local authority · Distance
|
2026-03-23 22:32:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { School } from '@/lib/types';
|
|
|
|
|
import { formatPercentage, formatProgress, calculateTrend } from '@/lib/utils';
|
|
|
|
|
import { progressBand } from '@/lib/metrics';
|
|
|
|
|
import styles from './SchoolRow.module.css';
|
|
|
|
|
|
|
|
|
|
interface SchoolRowProps {
|
|
|
|
|
school: School;
|
|
|
|
|
isLocationSearch?: boolean;
|
|
|
|
|
isInCompare?: boolean;
|
|
|
|
|
onAddToCompare?: (school: School) => void;
|
|
|
|
|
onRemoveFromCompare?: (urn: number) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SchoolRow({
|
|
|
|
|
school,
|
|
|
|
|
isLocationSearch,
|
|
|
|
|
isInCompare = false,
|
|
|
|
|
onAddToCompare,
|
|
|
|
|
onRemoveFromCompare,
|
|
|
|
|
}: SchoolRowProps) {
|
|
|
|
|
const trend = calculateTrend(school.rwm_expected_pct, school.prev_rwm_expected_pct);
|
|
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
// Use reading progress as representative; fall back to writing, then maths
|
|
|
|
|
const progressScore =
|
|
|
|
|
school.reading_progress ?? school.writing_progress ?? school.maths_progress ?? null;
|
2026-03-23 22:32:33 +00:00
|
|
|
|
|
|
|
|
const handleCompareClick = () => {
|
|
|
|
|
if (isInCompare) {
|
|
|
|
|
onRemoveFromCompare?.(school.urn);
|
|
|
|
|
} else {
|
|
|
|
|
onAddToCompare?.(school);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={`${styles.row} ${isInCompare ? styles.rowInCompare : ''}`}>
|
2026-03-24 09:27:22 +00:00
|
|
|
{/* Left: three content lines */}
|
|
|
|
|
<div className={styles.rowContent}>
|
2026-03-23 22:32:33 +00:00
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
{/* Line 1: School name + type */}
|
|
|
|
|
<div className={styles.line1}>
|
|
|
|
|
<a href={`/school/${school.urn}`} className={styles.schoolName}>
|
|
|
|
|
{school.school_name}
|
|
|
|
|
</a>
|
|
|
|
|
{school.school_type && (
|
|
|
|
|
<span className={styles.schoolType}>{school.school_type}</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-03-23 22:32:33 +00:00
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
{/* Line 2: Key stats */}
|
|
|
|
|
<div className={styles.line2}>
|
|
|
|
|
{school.rwm_expected_pct != null ? (
|
|
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>
|
|
|
|
|
{formatPercentage(school.rwm_expected_pct, 0)}
|
|
|
|
|
</strong>
|
|
|
|
|
{school.prev_rwm_expected_pct != null && (
|
|
|
|
|
<span
|
|
|
|
|
className={`${styles.trend} ${styles[`trend${trend.charAt(0).toUpperCase() + trend.slice(1)}`]}`}
|
|
|
|
|
title={`Previous year: ${formatPercentage(school.prev_rwm_expected_pct)}`}
|
|
|
|
|
>
|
|
|
|
|
{trend === 'up' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9">
|
|
|
|
|
<path d="M8 3L14 10H2L8 3Z" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
|
|
|
|
{trend === 'down' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9">
|
|
|
|
|
<path d="M8 13L2 6H14L8 13Z" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
|
|
|
|
{trend === 'stable' && (
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="9" height="9">
|
|
|
|
|
<rect x="2" y="7" width="12" height="2" rx="1" fill="currentColor" />
|
|
|
|
|
</svg>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<span className={styles.statLabel}>R, W & M</span>
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>—</strong>
|
|
|
|
|
<span className={styles.statLabel}>R, W & M</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{progressScore != null && (
|
|
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>{formatProgress(progressScore)}</strong>
|
|
|
|
|
<span className={styles.statLabel}>
|
|
|
|
|
progress · {progressBand(progressScore)}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{school.total_pupils != null && (
|
|
|
|
|
<span className={styles.stat}>
|
|
|
|
|
<strong className={styles.statValue}>{school.total_pupils.toLocaleString()}</strong>
|
|
|
|
|
<span className={styles.statLabel}>pupils</span>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-03-23 22:32:33 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
{/* Line 3: Location + distance */}
|
|
|
|
|
<div className={styles.line3}>
|
|
|
|
|
{school.local_authority && (
|
|
|
|
|
<span>{school.local_authority}</span>
|
|
|
|
|
)}
|
2026-03-23 22:32:33 +00:00
|
|
|
{isLocationSearch && school.distance != null && (
|
|
|
|
|
<span className={styles.distanceBadge}>
|
2026-03-23 22:39:50 +00:00
|
|
|
{school.distance.toFixed(1)} mi
|
2026-03-23 22:32:33 +00:00
|
|
|
</span>
|
|
|
|
|
)}
|
2026-03-24 09:27:22 +00:00
|
|
|
{!isLocationSearch &&
|
|
|
|
|
school.religious_denomination &&
|
|
|
|
|
school.religious_denomination !== 'Does not apply' && (
|
|
|
|
|
<span>{school.religious_denomination}</span>
|
|
|
|
|
)}
|
2026-03-23 22:32:33 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-24 09:27:22 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right: actions, vertically centred */}
|
|
|
|
|
<div className={styles.rowActions}>
|
|
|
|
|
<a href={`/school/${school.urn}`} className={styles.btnView}>
|
|
|
|
|
View
|
|
|
|
|
</a>
|
|
|
|
|
{(onAddToCompare || onRemoveFromCompare) && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleCompareClick}
|
|
|
|
|
className={isInCompare ? styles.btnRemove : styles.btnCompare}
|
|
|
|
|
>
|
|
|
|
|
{isInCompare ? '✓ Remove' : '+ Add'}
|
|
|
|
|
</button>
|
2026-03-23 22:32:33 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|