diff --git a/pandamarket/sprint5/src/App.js b/pandamarket/sprint5/src/App.js index 38b126fc..37b4e22c 100644 --- a/pandamarket/sprint5/src/App.js +++ b/pandamarket/sprint5/src/App.js @@ -14,6 +14,7 @@ function App() { const [sortedItems, setSortedItems] = useState([]); const [sortedPageSize, setSortedPageSize] = useState(10); const [favoritePageSize, setFavoritePageSize] = useState(4); + const [searchItem, setSearchItem] = useState(''); const loadFavorite = async () => { let pageSize; @@ -24,7 +25,7 @@ function App() { setFavoritePageSize(pageSize); - const response = await getProduct(1, pageSize, 'favorite'); + const response = await getProduct(1, favoritePageSize, 'favorite'); setFavoriteItems(response.list); } @@ -37,10 +38,14 @@ function App() { setSortedPageSize(pageSize); - const response = await getProduct(1, pageSize, sort); + const response = await getProduct(1, sortedPageSize, sort, searchItem); setSortedItems(response.list); } + const handleSearch = (e) => { + setSearchItem(e.target.value); + } + useEffect(() => { const handleResize = () => { setScreenWidth(window.innerWidth); @@ -50,14 +55,14 @@ function App() { loadFavorite(); loadSorted(); - }, [screenWidth, sort]); + }, [screenWidth, sort, searchItem]); return (
- +
diff --git a/pandamarket/sprint5/src/components/ProductList.js b/pandamarket/sprint5/src/components/ProductList.js index c65591e7..de64948e 100644 --- a/pandamarket/sprint5/src/components/ProductList.js +++ b/pandamarket/sprint5/src/components/ProductList.js @@ -1,6 +1,8 @@ import '../style/productlist.css'; import likeIcon from '../img/LikeIcon.png'; +import { useState } from 'react'; + function ProductItem({ item , label }) { const {id, name, description, price, images, favoriteCount, createdAt, updatedAt} = item; @@ -18,9 +20,7 @@ function ProductItem({ item , label }) { ); } - - -function ProductList({ items, label, setSort }) { +function ProductList({ items, label, setSort, onSearch }) { const handleSortChange = (e) => { setSort(e.target.value); } @@ -31,7 +31,7 @@ function ProductList({ items, label, setSort }) { : (

{label}

- +