diff --git a/components/blog-category-filter.tsx b/components/blog-category-filter.tsx index 3004061..531d24d 100644 --- a/components/blog-category-filter.tsx +++ b/components/blog-category-filter.tsx @@ -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(); - // 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 (
diff --git a/components/blog-list.tsx b/components/blog-list.tsx index 1ecf817..9d6943c 100644 --- a/components/blog-list.tsx +++ b/components/blog-list.tsx @@ -24,7 +24,7 @@ export default function BlogList({ blogPosts }:{ blogPosts: any }) { We post some really interesting stuff in here from time to time.

- {blogPosts.length > 1 && category && ( + {blogPosts.length > 1 && ( )}