Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function HomePage() {
const [category, setCategory] = useState<CategoryFilterValue>('all');
const [compareIds, setCompareIds] = useState<Set<string>>(new Set());
const [compareOpen, setCompareOpen] = useState(false);
const handleCloseCompare = useCallback(() => setCompareOpen(false), []);

const toggleCompare = useCallback((product: Product) => {
setCompareIds((prev) => {
Expand Down Expand Up @@ -264,7 +265,7 @@ export default function HomePage() {
{compareOpen && compareProducts.length >= 2 && (
<CompareModal
products={compareProducts}
onClose={() => setCompareOpen(false)}
onClose={handleCloseCompare}
/>
)}
</section>
Expand Down
1 change: 1 addition & 0 deletions src/components/CategoryFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function CategoryFilter({ value, onChange, className }: CategoryFilterPro
ref={(el) => { tabRefs.current[i] = el; }}
role="tab"
aria-selected={value === cat}
aria-pressed={value === cat}
tabIndex={value === cat ? 0 : -1}
onClick={() => onChange(cat)}
onKeyDown={(e) => handleKeyDown(e, i)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/CompareModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Product } from '@/types';
import { basisPointsToPercent, formatUSDC } from '@/lib/format';
import { CATEGORY_ICONS } from '@/lib/constants';
import { memo } from 'react';
import { Modal } from './Modal';

interface Props {
Expand All @@ -18,7 +19,7 @@ const FIELDS = [
{ label: 'Status', getValue: (p: Product) => p.status },
];

export function CompareModal({ products, onClose }: Props) {
function CompareModalComponent({ products, onClose }: Props) {
return (
<Modal open={true} onClose={onClose} title="Compare Products" maxWidth="max-w-3xl">
<div className="overflow-x-auto">
Expand Down Expand Up @@ -52,3 +53,5 @@ export function CompareModal({ products, onClose }: Props) {
</Modal>
);
}

export const CompareModal = memo(CompareModalComponent);
6 changes: 5 additions & 1 deletion src/components/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ function ProductCardComponent({ product, compareSelected, onCompareToggle }: Pro
<TriggerConditionBadge product={product} />
</div>

<dl className="mt-4 grid grid-cols-2 gap-3 text-sm">
<dl className="mt-4 grid grid-cols-3 gap-3 text-sm">
<div className="rounded-xl bg-gray-100 dark:bg-white/5 p-3">
<dt className="text-[10px] uppercase tracking-widest text-gray-500 dark:text-gray-400">Premium</dt>
<dd className="mt-0.5 font-semibold text-teal-400">
{basisPointsToPercent(product.premiumRate)}
</dd>
</div>
<div className="rounded-xl bg-gray-100 dark:bg-white/5 p-3">
<dt className="text-[10px] uppercase tracking-widest text-gray-500 dark:text-gray-400">Min Coverage</dt>
<dd className="mt-0.5 font-semibold text-gray-950 dark:text-white">{formatUSDC(product.coverageMin)}</dd>
</div>
<div className="rounded-xl bg-gray-100 dark:bg-white/5 p-3">
<dt className="text-[10px] uppercase tracking-widest text-gray-500 dark:text-gray-400">Max Coverage</dt>
<dd className="mt-0.5 font-semibold text-gray-950 dark:text-white">{formatUSDC(product.coverageMax)}</dd>
Expand Down
9 changes: 9 additions & 0 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { useState, useEffect } from 'react';
import { usePathname } from 'next/navigation';
import { useDebounce } from '@/hooks/useDebounce';

interface SearchBarProps {
Expand All @@ -19,6 +20,14 @@ export function SearchBar({
}: SearchBarProps) {
const [query, setQuery] = useState('');
const debouncedQuery = useDebounce(query, debounceMs);
const pathname = usePathname();

useEffect(() => {
if (pathname === '/') {
setQuery('');
onSearch('');
}
}, [pathname, onSearch]);

useEffect(() => {
onSearch(debouncedQuery);
Expand Down
Loading