mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 22:16:58 +00:00
Fixes relevance removing search query
This commit is contained in:
parent
37b436af52
commit
d13d0058c4
@ -13,6 +13,7 @@ function PathFilterItem({ item }: { item: PathFilterItem }) {
|
||||
const searchParams = useSearchParams();
|
||||
const [active, setActive] = useState(pathname === item.path);
|
||||
const newParams = new URLSearchParams(searchParams.toString());
|
||||
const DynamicTag = active ? 'p' : Link;
|
||||
|
||||
newParams.delete('q');
|
||||
|
||||
@ -22,7 +23,7 @@ function PathFilterItem({ item }: { item: PathFilterItem }) {
|
||||
|
||||
return (
|
||||
<li className="mt-2 flex text-black dark:text-white" key={item.title}>
|
||||
<Link
|
||||
<DynamicTag
|
||||
href={createUrl(item.path, newParams)}
|
||||
className={clsx(
|
||||
'w-full text-sm underline-offset-4 hover:underline dark:hover:text-gray-100',
|
||||
@ -32,7 +33,7 @@ function PathFilterItem({ item }: { item: PathFilterItem }) {
|
||||
)}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
</DynamicTag>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@ -42,33 +43,30 @@ function SortFilterItem({ item }: { item: SortFilterItem }) {
|
||||
const searchParams = useSearchParams();
|
||||
const [active, setActive] = useState(searchParams.get('sort') === item.slug);
|
||||
const q = searchParams.get('q');
|
||||
const href = createUrl(
|
||||
pathname,
|
||||
new URLSearchParams({
|
||||
...(q && { q }),
|
||||
...(item.slug && item.slug.length && { sort: item.slug })
|
||||
})
|
||||
);
|
||||
const DynamicTag = active ? 'p' : Link;
|
||||
|
||||
useEffect(() => {
|
||||
setActive(searchParams.get('sort') === item.slug);
|
||||
}, [searchParams, item.slug]);
|
||||
|
||||
const href =
|
||||
item.slug && item.slug.length
|
||||
? createUrl(
|
||||
pathname,
|
||||
new URLSearchParams({
|
||||
...(q && { q }),
|
||||
sort: item.slug
|
||||
})
|
||||
)
|
||||
: pathname;
|
||||
|
||||
return (
|
||||
<li className="mt-2 flex text-sm text-black dark:text-white" key={item.title}>
|
||||
<Link
|
||||
prefetch={false}
|
||||
<DynamicTag
|
||||
prefetch={!active ? false : undefined}
|
||||
href={href}
|
||||
className={clsx('w-full', {
|
||||
'underline underline-offset-4': active
|
||||
})}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
</DynamicTag>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user