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;
+ ;
+}
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!
+
{data.map((item) => (
From d247f3c9308209ad794239be64cefbc7e49b48a8 Mon Sep 17 00:00:00 2001
From: GrannyYetta
Date: Thu, 29 Aug 2024 14:53:37 +0200
Subject: [PATCH 2/9] debugged SearchForm and List view
---
src/components/SearchForm.jsx | 40 ++++++++++++++++-------------------
src/views/List.jsx | 19 ++++++++++++-----
2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx
index 2ac2742..fcc583c 100644
--- a/src/components/SearchForm.jsx
+++ b/src/components/SearchForm.jsx
@@ -1,36 +1,32 @@
-import { useState } from 'react';
-
-export default function searchForm({ onSearch }) {
- const [searchItem, setSearchItem] = useState('');
-
+function SearchForm({ onSearch }) {
const handleSearch = (e) => {
e.preventDefault();
const value = e.target.value;
- setSearchItem(value);
+
onSearch(value);
};
const clearSearch = () => {
- setSearchTerm('');
onSearch('');
};
- return;
-
+ );
}
+
+export default SearchForm;
diff --git a/src/views/List.jsx b/src/views/List.jsx
index c51c6de..68cebf0 100644
--- a/src/views/List.jsx
+++ b/src/views/List.jsx
@@ -1,15 +1,22 @@
import { ListItem } from '../components';
-import { SearchForm } from '../components/SearchForm';
+import SearchForm from '../components/SearchForm';
+import { useState } from 'react';
export function List({ data }) {
const [filteredItems, setFilteredItems] = useState(data);
+ const [searchTerm, setSearchTerm] = useState('');
+
+ console.log(data);
+
const handleSearch = (searchItem) => {
+ console.log(searchItem);
+ setSearchTerm(searchItem);
if (searchItem === '') {
setFilteredItems(data);
} else {
const filtered = data.filter((item) =>
- item.name.toLowerCase().includes(searchTerm.toLowerCase()),
+ item.name.toLowerCase().includes(searchItem.toLowerCase()),
);
setFilteredItems(filtered);
}
@@ -22,9 +29,11 @@ export function List({ data }) {
- {data.map((item) => (
-
- ))}
+ {searchTerm
+ ? filteredItems.map((item) => (
+
+ ))
+ : data.map((item) => )}
>
);
From 7d31273a33f305f1c8fdac2bf559ec76b135df28 Mon Sep 17 00:00:00 2001
From: GrannyYetta
Date: Fri, 30 Aug 2024 12:06:12 +0200
Subject: [PATCH 3/9] eliminated onSearch and simplified the filtering funciton
in the List view
---
src/components/SearchForm.jsx | 13 ++++++++-----
src/views/List.jsx | 19 ++++---------------
2 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx
index fcc583c..901d5ad 100644
--- a/src/components/SearchForm.jsx
+++ b/src/components/SearchForm.jsx
@@ -1,13 +1,15 @@
-function SearchForm({ onSearch }) {
+import { useState } from 'react';
+
+function SearchForm() {
+ const [searchItem, setSearchItem] = useState('');
+
const handleSearch = (e) => {
e.preventDefault();
- const value = e.target.value;
-
- onSearch(value);
+ setSearchItem(e.target.value);
};
const clearSearch = () => {
- onSearch('');
+ setSearchItem('');
};
return (
@@ -15,6 +17,7 @@ function SearchForm({ onSearch }) {
{
- console.log(searchItem);
- setSearchTerm(searchItem);
- if (searchItem === '') {
- setFilteredItems(data);
- } else {
- const filtered = data.filter((item) =>
- item.name.toLowerCase().includes(searchItem.toLowerCase()),
- );
- setFilteredItems(filtered);
- }
- };
+ const filteredData = data.filter((item) =>
+ item.name.toLowerCase().includes(searchTerm.toLowerCase()),
+ );
return (
<>
Hello from the /list
page!
-
+
{searchTerm
? filteredItems.map((item) => (
From c9878741cac60d31cc482ea15c25436b5b930a7d Mon Sep 17 00:00:00 2001
From: tataw-cl <127490325+tataw-cl@users.noreply.github.com>
Date: Fri, 30 Aug 2024 11:40:10 +0100
Subject: [PATCH 4/9] attempt to resolve seach functionality issues
---
src/components/SearchForm.jsx | 5 +++--
src/views/List.jsx | 27 ++++++++++++++++++---------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx
index 901d5ad..b19d04e 100644
--- a/src/components/SearchForm.jsx
+++ b/src/components/SearchForm.jsx
@@ -1,11 +1,12 @@
import { useState } from 'react';
-function SearchForm() {
+function SearchForm({ entry }) {
const [searchItem, setSearchItem] = useState('');
const handleSearch = (e) => {
e.preventDefault();
setSearchItem(e.target.value);
+ entry = searchItem;
};
const clearSearch = () => {
@@ -17,7 +18,7 @@ function SearchForm() {
Hello from the
/list
page!
-
-
- {searchTerm
- ? filteredItems.map((item) => (
-
- ))
- : data.map((item) => )}
-
+
+ {/*
+ - data.map((item) => )}
+
+
*/}
>
);
}
+
+// {filteredData.map((item)=>(
+//
- {item.name}
+// ))}
+// }
+
+{
+ /* {searchTerm
+ ? filteredData.map((item) => (
+
+ )) */
+}
From 26e7688699e49e242f8b0cea7823df1774375ebc Mon Sep 17 00:00:00 2001
From: GrannyYetta
Date: Fri, 30 Aug 2024 14:50:27 +0200
Subject: [PATCH 5/9] simplified the structure and reorganized the rendering in
the List view
---
src/components/SearchForm.jsx | 4 +--
src/views/List.jsx | 51 +++++++++++++++++++++++++++--------
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/src/components/SearchForm.jsx b/src/components/SearchForm.jsx
index 901d5ad..acfbbfd 100644
--- a/src/components/SearchForm.jsx
+++ b/src/components/SearchForm.jsx
@@ -17,12 +17,12 @@ function SearchForm() {