Skip to content

Commit

Permalink
Merge pull request #198 from Web-Dev-Path/fix/search-functionality
Browse files Browse the repository at this point in the history
Fix search functionality on blog page
  • Loading branch information
mariana-caldas authored Sep 14, 2023
2 parents a208cbd + 96b6e77 commit ad8bf0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions pages/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -31,7 +34,7 @@ export default function Blog({ posts }) {
</BlogSearch>
</Container>

<BlogPostsContainer posts={posts} />
<BlogPostsContainer posts={filteredPosts} heading={heading}/>
{!searchTerm &&
Object.keys(tagToHeading).map(tag => (
<BlogPostsContainer
Expand Down

0 comments on commit ad8bf0c

Please sign in to comment.