Skip to content

Commit

Permalink
카테고리 필터링 추가
Browse files Browse the repository at this point in the history
- 영어 대소문자 구별하지 않고 중복제거
  • Loading branch information
pithesun committed Sep 16, 2024
1 parent 31718fd commit 5dbd5fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/components/Categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import React from "react";
import { CategoryLabel } from "../CategoryLabel";
import { commonCategory } from "./style.module.css";
import { DEFAULT_LABEL } from "../../constants";
import { filterCategories } from "../../utils";

export const Categories = ({ categories, selectedLabel, onSelect }) => {
const refinedCategories = React.useMemo(() => {
return filterCategories(categories);
}, [categories]);

return (
<div className={commonCategory}>
{
Expand All @@ -14,12 +19,12 @@ export const Categories = ({ categories, selectedLabel, onSelect }) => {
active={selectedLabel === DEFAULT_LABEL}
/>
}
{categories.map((category) => {
{refinedCategories.map((category) => {
return (
<CategoryLabel
categoryLabel={category.fieldValue}
categoryLabel={category}
onSelect={onSelect}
active={selectedLabel === category.fieldValue}
active={selectedLabel === category}
/>
);
})}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const BlogPage = ({ data }) => {
? data.allMdx.nodes
: data.allMdx.group
?.filter((field) => {
return field.fieldValue === selectedLabel;
return (
String(field.fieldValue).toLowerCase() ===
String(selectedLabel).toLowerCase()
);
})?.[0]
.edges?.flatMap((edge) => edge.node)
}
Expand Down

0 comments on commit 5dbd5fa

Please sign in to comment.