Skip to content

Commit

Permalink
Merge pull request #619 from kailashchoudhary11/refactor/app
Browse files Browse the repository at this point in the history
fixes: search suggestions bug
  • Loading branch information
JasonDsouza212 authored Jun 14, 2023
2 parents f845c60 + cdcdbce commit 97d2b93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/pages/Bookmarks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ const BookMarks = () => {
if (checkFilter(filters)) return <Navigate to="/notfound" />

const filteredProducts = filterProducts(bookmarks, filters)
const currentProjects = searchProducts(filteredProducts, searchTerm)
let currentProducts = searchProducts(filteredProducts, searchTerm)

const productNames = filteredProducts?.map((product) => product.productName) || []

const filterNames = searchTerm.length > 0 ? productNames.filter((productName) => productName.toLowerCase().startsWith(searchTerm.toLowerCase())) : []

if (filterNames.length == 1 && currentProducts.filter(product => product.productName == searchTerm) == 1) {
currentProducts = currentProducts.filter(product => product.productName == filterNames[0])
}

return (
<div className="card_container">
<Header filteredSuggestions={filterNames} />
<div className="card-container">
{currentProjects.length === 0 ? (
{currentProducts.length === 0 ? (
<div className="not-found-wrapper">
<p className="no-results">Sorry, no BookMarks in sight!</p>
<img className="not-found-img" src={noresultimg} alt="no bookmarks" />
Expand All @@ -39,7 +43,7 @@ const BookMarks = () => {
<>
{filteredProducts.length > 0 ? (
<main className="grid">
{currentProjects.map((product) => (
{currentProducts.map((product) => (
<article>
<div className="text">
<div className="text_top">
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Card = () => {
if (checkFilter(filters)) return <Navigate to="/notfound" />

const filteredProducts = filterProducts(products, filters)
const currentProducts = searchProducts(filteredProducts, searchTerm)
let currentProducts = searchProducts(filteredProducts, searchTerm)

const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
Expand All @@ -40,6 +40,10 @@ const Card = () => {
const productNames = filteredProducts?.map((product) => product.productName) || []

const filterNames = searchTerm.length > 0 ? productNames.filter((productName) => productName.toLowerCase().startsWith(searchTerm.toLowerCase())) : []
if (filterNames.length == 1 && currentProducts.filter(product => product.productName == searchTerm).length == 1) {
currentProducts = currentProducts.filter(product => product.productName == filterNames[0])
}


return (
<div className="card_container">
Expand Down

1 comment on commit 97d2b93

@vercel
Copy link

@vercel vercel bot commented on 97d2b93 Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

free-hit – ./

free-hit-jasondsouza212.vercel.app
free-hit.vercel.app
free-hit-git-main-jasondsouza212.vercel.app

Please sign in to comment.