diff --git a/package-lock.json b/package-lock.json index 92e3541..42a07c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,7 @@ "eslint-plugin-react": "^7.35.0", "husky": "^9.1.4", "jsdom": "^24.1.1", - "lint-staged": "^15.2.8", + "lint-staged": "^15.2.9", "prettier": "^3.3.3", "typescript-eslint": "^8.2.0", "vite": "^5.3.5", diff --git a/package.json b/package.json index f8906fe..7e3d6a8 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "eslint-plugin-react": "^7.35.0", "husky": "^9.1.4", "jsdom": "^24.1.1", - "lint-staged": "^15.2.8", + "lint-staged": "^15.2.9", "prettier": "^3.3.3", "typescript-eslint": "^8.2.0", "vite": "^5.3.5", diff --git a/src/App.tsx b/src/App.tsx index 3621bed..b299d8c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,3 @@ -import React from "react"; - import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import { Home, Layout, List, ManageList } from "./views"; diff --git a/src/components/FilterListInput.tsx b/src/components/FilterListInput.tsx new file mode 100644 index 0000000..6ebe5ef --- /dev/null +++ b/src/components/FilterListInput.tsx @@ -0,0 +1,35 @@ +import { ChangeEvent, FormEvent } from "react"; + +interface FilterListProps { + searchTerm: string; + setSearchTerm: (term: string) => void; +} + +export function FilterListInput({ + searchTerm, + setSearchTerm, +}: FilterListProps) { + const handleChange = (e: ChangeEvent) => { + setSearchTerm(e.target.value); + }; + + const handleSubmit = (e: FormEvent) => { + e.preventDefault(); + }; + + return ( +
+ +
+ ); +} diff --git a/src/views/List.tsx b/src/views/List.tsx index bfd5a8b..b81d596 100644 --- a/src/views/List.tsx +++ b/src/views/List.tsx @@ -1,23 +1,38 @@ -import React from 'react'; -import { ListItem as ListItemComponent } from '../components/ListItem'; -import { ListItem } from '../api'; +import { useState, useMemo } from "react"; +import { ListItem as ListItemComponent } from "../components/ListItem"; +import { FilterListInput as FilterListComponent } from "../components/FilterListInput"; +import { ListItem } from "../api"; interface Props { data: ListItem[]; } -export function List({ data }: Props) { - const hasItem = data.length !== 0; +export function List({ data: unfilteredListItems }: Props) { + const [searchTerm, setSearchTerm] = useState(""); + + const filteredListItems = useMemo(() => { + return unfilteredListItems.filter((item) => + item.name.toLowerCase().includes(searchTerm.toLowerCase()), + ); + }, [searchTerm, unfilteredListItems]); + return ( <>

Hello from the /list page!

+ + {unfilteredListItems.length > 0 && ( + + )} +
    - {hasItem && - data.map((item) => ( - - ))} + {filteredListItems.map((item) => ( + + ))}
);