33 lines
808 B
TypeScript
33 lines
808 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;
|
||
|
|
clearAll: () => void;
|
||
|
|
isSelected: (urn: number) => boolean;
|
||
|
|
canAddMore: 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;
|
||
|
|
}
|