mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Fixes search page bugs. (#1019)
This commit is contained in:
@@ -12,6 +12,9 @@ function PathFilterItem({ item }: { item: PathFilterItem }) {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const [active, setActive] = useState(pathname === item.path);
|
||||
const newParams = new URLSearchParams(searchParams.toString());
|
||||
|
||||
newParams.delete('q');
|
||||
|
||||
useEffect(() => {
|
||||
setActive(pathname === item.path);
|
||||
@@ -20,7 +23,7 @@ function PathFilterItem({ item }: { item: PathFilterItem }) {
|
||||
return (
|
||||
<li className="mt-2 flex text-sm text-gray-400" key={item.title}>
|
||||
<Link
|
||||
href={createUrl(item.path, searchParams)}
|
||||
href={createUrl(item.path, newParams)}
|
||||
className={clsx('w-full hover:text-gray-800 dark:hover:text-gray-100', {
|
||||
'text-gray-600 dark:text-gray-400': !active,
|
||||
'font-semibold text-black dark:text-white': active
|
||||
@@ -36,6 +39,7 @@ function SortFilterItem({ item }: { item: SortFilterItem }) {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const [active, setActive] = useState(searchParams.get('sort') === item.slug);
|
||||
const q = searchParams.get('q');
|
||||
|
||||
useEffect(() => {
|
||||
setActive(searchParams.get('sort') === item.slug);
|
||||
@@ -43,7 +47,13 @@ function SortFilterItem({ item }: { item: SortFilterItem }) {
|
||||
|
||||
const href =
|
||||
item.slug && item.slug.length
|
||||
? createUrl(pathname, new URLSearchParams({ sort: item.slug }))
|
||||
? createUrl(
|
||||
pathname,
|
||||
new URLSearchParams({
|
||||
...(q && { q }),
|
||||
sort: item.slug
|
||||
})
|
||||
)
|
||||
: pathname;
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user