From 96b6e77a7990f1bdef144333c6d7542d5587a94b Mon Sep 17 00:00:00 2001 From: Mariana Caldas Date: Wed, 13 Sep 2023 19:15:22 -0700 Subject: [PATCH] Fix search functionality on blog page --- CHANGELOG.md | 1 + pages/blog/index.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af45749..161bae0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -123,3 +123,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Contact and Subscribe forms are saving Name on Mailchimp - Fixed Who We Are section on mobile. - Allow `BlogPostsContainer` display a dynamic number of cards per row with swipe functionality +- Fixed search funcitionality on blog page diff --git a/pages/blog/index.js b/pages/blog/index.js index edd890ab..6ce76519 100644 --- a/pages/blog/index.js +++ b/pages/blog/index.js @@ -11,15 +11,18 @@ import { blogSearch } from '@/utils/search'; export default function Blog({ posts }) { const [searchTerm, setSearchTerm] = useState(''); + let filteredPosts = posts; + let heading; + if (searchTerm) { - const filteredPosts = blogSearch(posts, searchTerm); - filteredData.posts = filteredPosts; - filteredData.heading = `${ + filteredPosts = blogSearch(posts, searchTerm); + + heading = `${ filteredPosts.length === 0 ? 'no' : filteredPosts.length } search ${ filteredPosts.length > 1 ? 'results' : 'result' } for '${searchTerm}'`; - filteredData.viewall = false; + filteredPosts.viewall = false; } return ( @@ -31,7 +34,7 @@ export default function Blog({ posts }) { - + {!searchTerm && Object.keys(tagToHeading).map(tag => (