Skip to content

Commit 580207b

Browse files
committed
Global search implemented. Will need to refactor once we have a design.
1 parent 36c4ca9 commit 580207b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

components/RepositoryList.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,36 @@ const Loader = () => (
2121
export const RepositoryList = ({ repositories }: RepositoryListProps) => {
2222
const itemsPerScroll = 15;
2323
const [items, setItems] = useState(itemsPerScroll);
24+
const [filter, setFilter] = useState("");
25+
26+
const filteredRepositories = repositories.filter((repository) => {
27+
// Check if any property of the RepositoryItem matches the filter value
28+
return Object.values(repository).some((value) => {
29+
if (value === null) {
30+
return false;
31+
}
32+
return value.toString().toLowerCase().includes(filter.toLowerCase());
33+
});
34+
});
2435

2536
return (
2637
<main className="grow">
2738
<div className="p-4 w-full">
39+
<input
40+
type="text"
41+
value={filter}
42+
onChange={(e) => setFilter(e.target.value)}
43+
placeholder="Search Repositories"
44+
className="border rounded-sm p-2 mb-4"
45+
/>
2846
<InfiniteScroll
2947
dataLength={items}
3048
next={() => setItems(items + itemsPerScroll)}
31-
hasMore={items < repositories.length}
49+
hasMore={items < filteredRepositories.length}
3250
loader={<Loader />}
3351
>
34-
{repositories.slice(0, items).map((repository) => {
35-
// NOTE - We sometimes get duplicate values back from GitHub API
36-
// meaning we can't simply rely on the id as the key
52+
{filteredRepositories.slice(0, items).map((repository) => {
3753
const key = `${repository.id}_${new Date().getTime()}_${Math.random()}`;
38-
3954
return <RepositoryItem key={key} repository={repository} />;
4055
})}
4156
</InfiniteScroll>

0 commit comments

Comments
 (0)