2026-03-05 09:33:47 +00:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
|
import { useComparison } from '@/hooks/useComparison';
|
|
|
|
|
|
import { usePathname } from 'next/navigation';
|
|
|
|
|
|
import styles from './ComparisonToast.module.css';
|
|
|
|
|
|
|
|
|
|
|
|
export function ComparisonToast() {
|
2026-03-23 21:31:28 +00:00
|
|
|
|
const { selectedSchools, clearAll, removeSchool } = useComparison();
|
2026-03-05 09:33:47 +00:00
|
|
|
|
const [mounted, setMounted] = useState(false);
|
2026-03-25 20:28:03 +00:00
|
|
|
|
const [collapsed, setCollapsed] = useState(false);
|
2026-03-05 09:33:47 +00:00
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setMounted(true);
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
if (!mounted) return null;
|
|
|
|
|
|
|
|
|
|
|
|
// Don't show toast on the compare page itself
|
|
|
|
|
|
if (pathname === '/compare') return null;
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedSchools.length === 0) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className={styles.toastContainer}>
|
2026-03-25 20:28:03 +00:00
|
|
|
|
<div className={`${styles.toastContent} ${collapsed ? styles.toastCollapsed : ''}`}>
|
2026-03-23 21:31:28 +00:00
|
|
|
|
<div className={styles.toastHeader}>
|
|
|
|
|
|
<span className={styles.toastTitle}>
|
|
|
|
|
|
<span className={styles.toastBadge}>{selectedSchools.length}</span>
|
2026-03-05 09:33:47 +00:00
|
|
|
|
{selectedSchools.length === 1 ? 'school' : 'schools'} selected
|
|
|
|
|
|
</span>
|
2026-03-25 20:28:03 +00:00
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setCollapsed(!collapsed)}
|
|
|
|
|
|
className={styles.collapseBtn}
|
|
|
|
|
|
aria-label={collapsed ? 'Expand comparison panel' : 'Minimize comparison panel'}
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg viewBox="0 0 16 16" fill="none" width="14" height="14">
|
|
|
|
|
|
{collapsed ? (
|
|
|
|
|
|
<path d="M4 10L8 6L12 10" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<path d="M4 6L8 10L12 6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
|
|
|
|
)}
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</button>
|
2026-03-05 09:33:47 +00:00
|
|
|
|
</div>
|
2026-03-25 20:28:03 +00:00
|
|
|
|
{!collapsed && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className={styles.schoolList}>
|
|
|
|
|
|
{selectedSchools.map(school => (
|
|
|
|
|
|
<div key={school.urn} className={styles.schoolItem}>
|
|
|
|
|
|
<span className={styles.schoolName} title={school.school_name}>
|
|
|
|
|
|
{school.school_name.length > 28 ? school.school_name.slice(0, 28) + '…' : school.school_name}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => removeSchool(school.urn)}
|
|
|
|
|
|
className={styles.removeSchoolBtn}
|
|
|
|
|
|
aria-label={`Remove ${school.school_name}`}
|
|
|
|
|
|
>×</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
2026-03-23 21:31:28 +00:00
|
|
|
|
</div>
|
2026-03-25 20:28:03 +00:00
|
|
|
|
<div className={styles.toastActions}>
|
2026-03-27 22:09:59 +00:00
|
|
|
|
<button onClick={clearAll} className={styles.btnClearAll}>Clear all</button>
|
2026-03-25 20:28:03 +00:00
|
|
|
|
<Link href="/compare" className={styles.btnCompare}>Compare Now</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-03-05 09:33:47 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|