-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
128b53d
commit b882457
Showing
2 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client"; | ||
|
||
import { Post } from "@content"; | ||
import { useSearchParams } from "next/navigation"; | ||
import ArticleBlock from "@components/ArticleBlock"; | ||
|
||
interface TaggedItem { | ||
content: React.ReactNode; | ||
tags: string[]; | ||
slug: string; | ||
} | ||
|
||
interface TagFilteredListProps { | ||
children: TaggedItem[]; | ||
} | ||
|
||
/** | ||
* Displays a list of items, filtering them based on the tags in the URL query. | ||
* @param children The items to display, each with a `content`, `tags`, and `slug` property. | ||
*/ | ||
export default function TagFilteredList({ children }: TagFilteredListProps) { | ||
const selectedTags = useSearchParams().get("tags")?.split(",") || []; | ||
|
||
let filteredItems = children; | ||
if (selectedTags.length > 0) { | ||
filteredItems = children.filter((child: TaggedItem) => | ||
child.tags.some((tag) => selectedTags.includes(tag)) | ||
); | ||
} | ||
|
||
return ( | ||
<ul> | ||
<hr /> | ||
{filteredItems.map((item: TaggedItem) => ( | ||
<li key={item.slug}> | ||
{item.content} | ||
<hr /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} |