From 580207bfd43dbcedf62353312806e69c361ca5dd Mon Sep 17 00:00:00 2001 From: Sean Marcia Date: Sat, 16 Sep 2023 14:35:19 -0400 Subject: [PATCH] Global search implemented. Will need to refactor once we have a design. --- components/RepositoryList.tsx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/components/RepositoryList.tsx b/components/RepositoryList.tsx index 441fc73c..6c2fe038 100644 --- a/components/RepositoryList.tsx +++ b/components/RepositoryList.tsx @@ -21,21 +21,36 @@ const Loader = () => ( export const RepositoryList = ({ repositories }: RepositoryListProps) => { const itemsPerScroll = 15; const [items, setItems] = useState(itemsPerScroll); + const [filter, setFilter] = useState(""); + + const filteredRepositories = repositories.filter((repository) => { + // Check if any property of the RepositoryItem matches the filter value + return Object.values(repository).some((value) => { + if (value === null) { + return false; + } + return value.toString().toLowerCase().includes(filter.toLowerCase()); + }); + }); return (
+ setFilter(e.target.value)} + placeholder="Search Repositories" + className="border rounded-sm p-2 mb-4" + /> setItems(items + itemsPerScroll)} - hasMore={items < repositories.length} + hasMore={items < filteredRepositories.length} loader={} > - {repositories.slice(0, items).map((repository) => { - // NOTE - We sometimes get duplicate values back from GitHub API - // meaning we can't simply rely on the id as the key + {filteredRepositories.slice(0, items).map((repository) => { const key = `${repository.id}_${new Date().getTime()}_${Math.random()}`; - return ; })}