The seed effect only adopted the URL's schools when localStorage was empty, so a recipient who had ever used compare silently saw their own old shortlist instead of the shared one. Explicit URL urns now replace the stored selection on load (then persist as usual); bare /compare still restores the visitor's own selection. Adds replaceSchools() to the comparison context. Card values also switch to CHART_TEXT_COLORS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
35 lines
881 B
TypeScript
35 lines
881 B
TypeScript
/**
|
|
* ComparisonContext
|
|
* Global state for school comparison basket
|
|
*/
|
|
|
|
'use client';
|
|
|
|
import { createContext, useContext } from 'react';
|
|
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;
|
|
clearAll: () => void;
|
|
isSelected: (urn: number) => boolean;
|
|
canAddMore: boolean;
|
|
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;
|
|
}
|