Files
school_compare/nextjs-app/context/ComparisonContext.tsx
Tudor 200fccb615
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 35s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m13s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s
Fix comparison badge to update in real-time across components
- Move comparison state from hook to shared context provider
- All components now share the same state instance
- Badge count updates immediately when schools are added/removed
- Add key prop to badge to re-trigger animation on count change
- Add storage event listener for cross-tab synchronization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:26:23 +00:00

34 lines
834 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;
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;
}