2026-02-02 20:34:35 +00:00
|
|
|
/**
|
|
|
|
|
* ComparisonContext
|
|
|
|
|
* Global state for school comparison basket
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { createContext, useContext } from 'react';
|
2026-09-30 11:56:54 +01:00
|
|
|
import type { CompareGroup } from '@/lib/compareLogic';
|
2026-02-02 20:34:35 +00:00
|
|
|
import type { School } from '@/lib/types';
|
|
|
|
|
|
|
|
|
|
interface ComparisonContextType {
|
|
|
|
|
selectedSchools: School[];
|
|
|
|
|
comparisonData: any;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
error: any;
|
|
|
|
|
addSchool: (school: School) => void;
|
|
|
|
|
removeSchool: (urn: number) => void;
|
2026-07-02 21:34:07 +01:00
|
|
|
replaceSchools: (schools: School[]) => void;
|
2026-09-30 12:04:39 +01:00
|
|
|
/** Fill in phases missing from stored entries; never overwrites one. */
|
|
|
|
|
backfillPhases: (phases: Record<number, string | null | undefined>) => void;
|
2026-02-02 20:34:35 +00:00
|
|
|
clearAll: () => void;
|
|
|
|
|
isSelected: (urn: number) => boolean;
|
2026-09-30 11:56:54 +01:00
|
|
|
/** The comparison group with no room for this school, or null. */
|
|
|
|
|
fullGroupFor: (school: Pick<School, 'phase'>) => CompareGroup | null;
|
2026-02-03 14:26:23 +00:00
|
|
|
isInitialized: boolean;
|
2026-02-02 20:34:35 +00:00
|
|
|
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;
|
|
|
|
|
}
|