Skip to content

Commit

Permalink
Merge pull request #21 from in-tech-gration/filter-fix
Browse files Browse the repository at this point in the history
Filter fix
  • Loading branch information
kostasx authored Oct 29, 2024
2 parents 1419c86 + 2fbd1b0 commit a2e14ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions components/blog-category-filter.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import React from "react";

// Returns string array of all distinct categories of blogs
export const getBlogCategories = (blogPosts:any) => {
export const getBlogCategories = (blogPosts: any) => {
const categories = new Set<string>();

// TODO: Convert to Set()
const categories: string[] = [];

blogPosts.forEach((post:any) =>{
return post.meta?.categories?.forEach(
(category: string) =>
!categories.includes(category) && categories.push(category)
)
blogPosts.forEach((post: any) => {
return post.meta?.categories?.forEach((category: string) =>
categories.add(category)
);
});

return categories.sort((a, b) => a.localeCompare(b));
return categories;
};

const BlogCategoryFilter = (props: {
selectedCategory?: string | string[];
blogPosts?: any
selectedCategory?: string | null;
blogPosts?: any;
}) => {
const selectedCategory = props.selectedCategory;
const blogCategories: string[] = getBlogCategories(props.blogPosts);
const blogCategories: string[] = Array.from(
getBlogCategories(props.blogPosts)
).sort((a, b) => a.localeCompare(b));

return (
<div className="flex mt-4 items-center">
Expand Down
2 changes: 1 addition & 1 deletion components/blog-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function BlogList({ blogPosts }:{ blogPosts: any }) {
We post some really interesting stuff in here from time to time.
</p>

{blogPosts.length > 1 && category && (
{blogPosts.length > 1 && (
<BlogCategoryFilter selectedCategory={category} blogPosts={blogPosts} />
)}

Expand Down

0 comments on commit a2e14ba

Please sign in to comment.