Files
school_compare/nextjs-app/context/ComparisonContext.tsx
TudorandClaude Opus 5.5 587cfe3f0b
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m13s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 17s
PR Checks / Build Frontend (no push) (pull_request) Canceled after 1m6s
PR Checks / Build Pipeline (no push) (pull_request) Canceled after 0s
PR Checks / AI Code Review (Claude) (pull_request) Canceled after 0s
fix(compare): give every basket entry a real phase
Review of the per-phase limit found entries reaching the basket with no
phase, and a phase-less entry holds a slot in both groups:

- Nearby-school cards added without one. The API now returns each
  peer's own phase (its pool is a phase group, so an all-through school
  can sit beside a primary); the button passes it through, and an older
  API simply leaves the conservative both-groups count in place.
- Baskets saved before this change were never migrated. The compare
  page now backfills missing phases from the data it already fetches,
  and never overwrites a phase the basket has.
- "16 plus" counted against both groups; it is secondary, as the API's
  PHASE_GROUPS files it.

Also rewraps the HomeView doc comment the previous commit left awkward.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 12:04:39 +01:00

39 lines
1.2 KiB
TypeScript

/**
* ComparisonContext
* Global state for school comparison basket
*/
'use client';
import { createContext, useContext } from 'react';
import type { CompareGroup } from '@/lib/compareLogic';
import type { School } from '@/lib/types';
interface ComparisonContextType {
selectedSchools: School[];
comparisonData: any;
isLoading: boolean;
error: any;
addSchool: (school: School) => void;
removeSchool: (urn: number) => void;
replaceSchools: (schools: School[]) => void;
/** Fill in phases missing from stored entries; never overwrites one. */
backfillPhases: (phases: Record<number, string | null | undefined>) => void;
clearAll: () => void;
isSelected: (urn: number) => boolean;
/** The comparison group with no room for this school, or null. */
fullGroupFor: (school: Pick<School, 'phase'>) => CompareGroup | null;
isInitialized: boolean;
mutate: () => void;
}
export const ComparisonContext = createContext<ComparisonContextType | undefined>(undefined);
export function useComparisonContext() {
const context = useContext(ComparisonContext);
if (!context) {
throw new Error('useComparisonContext must be used within ComparisonProvider');
}
return context;
}