import Link from '@/components/Link'; import Tag from '@/components/Tag'; import { ComponentProps, useState } from 'react'; import Pagination from '@/components/Pagination'; import formatDate from '@/lib/utils/formatDate'; import { PostFrontMatter } from 'types/PostFrontMatter'; interface Props { posts: PostFrontMatter[]; title: string; initialDisplayPosts?: PostFrontMatter[]; pagination?: ComponentProps; } export default function ListLayout({ posts, title, initialDisplayPosts = [], pagination, }: Props) { const [searchValue, setSearchValue] = useState(''); const filteredBlogPosts = posts.filter((frontMatter) => { const searchContent = frontMatter.title + frontMatter.summary + frontMatter.tags.join(' '); return searchContent.toLowerCase().includes(searchValue.toLowerCase()); }); // If initialDisplayPosts exist, display it if no searchValue is specified const displayPosts = initialDisplayPosts.length > 0 && !searchValue ? initialDisplayPosts : filteredBlogPosts; return ( <>

{title}

setSearchValue(e.target.value)} placeholder="Search articles" className="block w-full rounded-md border border-gray-300 bg-white px-4 py-2 text-gray-900 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-900 dark:bg-gray-800 dark:text-gray-100" />
{pagination && pagination.totalPages > 1 && !searchValue && ( )} ); }