fix(compare): shared ?urns= links win over the visitor's stored selection (P1.3)

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>
This commit is contained in:
TudorandClaude Fable 5 committed 2026-07-02 21:34:07 +01:00
1 parent a1fa4fe874
commit 0294038fd3
4 files changed
+28 -11

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ interface ComparisonContextType {
error: any;
addSchool: (school: School) => void;
removeSchool: (urn: number) => void;
replaceSchools: (schools: School[]) => void;
clearAll: () => void;
isSelected: (urn: number) => boolean;
canAddMore: boolean;
@@ -65,6 +65,12 @@ export function ComparisonProvider({ children }: { children: React.ReactNode })
setSelectedSchools((prev) => prev.filter((s) => s.urn !== urn));
}, []);
// Replace the whole selection — used when a shared /compare?urns=… link
// must take precedence over whatever this visitor had stored.
const replaceSchools = useCallback((schools: School[]) => {
setSelectedSchools(schools.slice(0, MAX_SCHOOLS));
}, []);
const clearAll = useCallback(() => {
setSelectedSchools([]);
}, []);
@@ -86,6 +92,7 @@ export function ComparisonProvider({ children }: { children: React.ReactNode })
error: null,
addSchool,
removeSchool,
replaceSchools,
clearAll,
isSelected,
canAddMore: selectedSchools.length < MAX_SCHOOLS,