From aeb02fbe821a313e99c2497e8cbf1f4a440b1aa7 Mon Sep 17 00:00:00 2001 From: GrannyYetta Date: Wed, 28 Aug 2024 22:36:42 +0200 Subject: [PATCH 1/9] added the SearchForm Component and passed it to the List view --- src/components/SearchForm.jsx | 36 +++++++++++++++++++++++++++++++++++ src/views/List.jsx | 15 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/components/SearchForm.jsx diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx new file mode 100644 index 0000000..2ac2742 --- /dev/null +++ b/src/components/SearchForm.jsx @@ -0,0 +1,36 @@ +import { useState } from 'react'; + +export default function searchForm({ onSearch }) { + const [searchItem, setSearchItem] = useState(''); + + const handleSearch = (e) => { + e.preventDefault(); + const value = e.target.value; + setSearchItem(value); + onSearch(value); + }; + + const clearSearch = () => { + setSearchTerm(''); + onSearch(''); + }; + + return; +
+
+ + + {searchItem && ( + + )} +
+
; +} diff --git a/src/views/List.jsx b/src/views/List.jsx index 4b341e3..c51c6de 100644 --- a/src/views/List.jsx +++ b/src/views/List.jsx @@ -1,11 +1,26 @@ import { ListItem } from '../components'; +import { SearchForm } from '../components/SearchForm'; export function List({ data }) { + const [filteredItems, setFilteredItems] = useState(data); + + const handleSearch = (searchItem) => { + if (searchItem === '') { + setFilteredItems(data); + } else { + const filtered = data.filter((item) => + item.name.toLowerCase().includes(searchTerm.toLowerCase()), + ); + setFilteredItems(filtered); + } + }; + return ( <>

Hello from the /list page!

+ } - -{ - /* {searchTerm - ? filteredData.map((item) => ( - - )) */ -} From db8ee22b5b9e27d3704820b56a23883cffc7b423 Mon Sep 17 00:00:00 2001 From: GrannyYetta Date: Sat, 31 Aug 2024 14:59:21 +0200 Subject: [PATCH 9/9] matched label htmlFor attribute with id of input --- src/views/List.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/List.jsx b/src/views/List.jsx index 7834ba8..5e7f01c 100644 --- a/src/views/List.jsx +++ b/src/views/List.jsx @@ -24,7 +24,7 @@ export function List({ data }) {

- +