From 7c82870be2bf8aea247b130923870afd7f919fc5 Mon Sep 17 00:00:00 2001 From: Bas-sheikh Date: Wed, 28 Sep 2022 09:39:38 +0300 Subject: [PATCH] create price filter functionailty. relates #59 --- .../LandingPage/Products/Filter/Filter.jsx | 9 +++-- .../Products/Filter/FilterPrice.jsx | 33 ++++++----------- .../LandingPage/Products/Products.jsx | 36 ++++++++++++------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/client/src/Components/LandingPage/Products/Filter/Filter.jsx b/client/src/Components/LandingPage/Products/Filter/Filter.jsx index bca9255..3c0c94b 100644 --- a/client/src/Components/LandingPage/Products/Filter/Filter.jsx +++ b/client/src/Components/LandingPage/Products/Filter/Filter.jsx @@ -4,11 +4,14 @@ import FilterPrice from './FilterPrice'; import('./filter.css'); -function Filter({ handleFilterCategory, category }) { +function Filter({ handleFilterCategory, category, changeFilterPrice }) { return (
- - + +
); } diff --git a/client/src/Components/LandingPage/Products/Filter/FilterPrice.jsx b/client/src/Components/LandingPage/Products/Filter/FilterPrice.jsx index 4d7b5e8..42dfe20 100644 --- a/client/src/Components/LandingPage/Products/Filter/FilterPrice.jsx +++ b/client/src/Components/LandingPage/Products/Filter/FilterPrice.jsx @@ -1,30 +1,17 @@ /* eslint-disable jsx-a11y/label-has-associated-control */ -function FilterPrice() { - const handle = () => 'dadada' +function FilterPrice({ changeFilterPrice }) { return (
-

Range Price

- - - - +

sort :

+ +
- ) + ); } -export default FilterPrice +export default FilterPrice; diff --git a/client/src/Components/LandingPage/Products/Products.jsx b/client/src/Components/LandingPage/Products/Products.jsx index 0986c7f..afd6362 100644 --- a/client/src/Components/LandingPage/Products/Products.jsx +++ b/client/src/Components/LandingPage/Products/Products.jsx @@ -8,35 +8,45 @@ import('./Products.css'); function Products() { const [newData, setNewData] = useState([]); const [showMoreData, setShowMoreData] = useState([]); - const [showMoreCounter, setShowMoreCounter] = useState(3); + const [showMoreCounter, setShowMoreCounter] = useState(1); const [category, setCategory] = useState('all'); const handleFilterCategory = (e) => setCategory(e.target.textContent); - const showMoreRequest = ( ) => axios.get(`/api/v1/showMore/${showMoreCounter}`) - .then(({ data }) => { - setShowMoreData([...showMoreData,...data.data]); - setShowMoreCounter(showMoreCounter+1); + const changeFilterPrice = (e) => e.target.textContent; + + const showMoreRequest = () => + axios.get(`/api/v1/showMore/${showMoreCounter}`).then(({ data }) => { + setShowMoreData([...showMoreData, ...data.data]); + setShowMoreCounter(showMoreCounter + 1); }); useEffect(() => { axios.get('/api/v1/products').then(({ data }) => setNewData(data.data)); }, []); - if (!newData.length) return

Loading ...

; return (
- +
{category !== 'all' - ? [...showMoreData,...newData] - .filter((ele)=> ele.category ===category) - .map((ele) => ) - : [...showMoreData,...newData].map((ele) => )} -
- + ? [...showMoreData, ...newData] + .filter((ele) => ele.category === category) + .map((ele) => ) + : [...showMoreData, ...newData].map((ele) => ( + + ))} + +
); }