From 7c677afd17e50de63bfaa83ce50fafe1fc5dd561 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Sun, 25 Oct 2020 22:33:32 -0500 Subject: [PATCH] UX improvements for the search page --- pages/search.tsx | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pages/search.tsx b/pages/search.tsx index 17b1fa425..3d18adb66 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -40,7 +40,10 @@ export default function Search({ const router = useRouter() const { asPath } = router const { q, sort } = router.query - const query = filterQuery({ q, sort }) + // `q` can be included but because categories and designers can't be searched + // in the same way of products, it's better to ignore the search input if one + // of those is selected + const query = filterQuery({ sort }) const { pathname, category, brand } = useSearchMeta(asPath) const activeCategory = categories.find( @@ -111,7 +114,7 @@ export default function Search({
- {q && ( + {(q || activeCategory || activeBrand) && (
{data ? ( <> @@ -121,8 +124,12 @@ export default function Search({ hidden: !data.found, })} > - Showing {data.products.length} results for " - {q}" + Showing {data.products.length} results{' '} + {q && ( + <> + for "{q}" + + )} - There are no products that match "{q}" + {q ? ( + <> + There are no products that match "{q}" + + ) : ( + <> + There are no products that match the selected category & + designer + + )} - ) : ( + ) : q ? ( <> Searching for: "{q}" + ) : ( + <>Searching... )}
)}