Skip to content

Commit

Permalink
create price filter functionailty.
Browse files Browse the repository at this point in the history
relates #59
  • Loading branch information
Bas-Shiekh committed Sep 28, 2022
1 parent 43e96ae commit 7c82870
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
9 changes: 6 additions & 3 deletions client/src/Components/LandingPage/Products/Filter/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import FilterPrice from './FilterPrice';

import('./filter.css');

function Filter({ handleFilterCategory, category }) {
function Filter({ handleFilterCategory, category, changeFilterPrice }) {
return (
<section className="Filter-container">
<FilterCategory handleFilterCategory={handleFilterCategory} category={category}/>
<FilterPrice />
<FilterCategory
handleFilterCategory={handleFilterCategory}
category={category}
/>
<FilterPrice changeFilterPrice={changeFilterPrice} />
</section>
);
}
Expand Down
33 changes: 10 additions & 23 deletions client/src/Components/LandingPage/Products/Filter/FilterPrice.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
/* eslint-disable jsx-a11y/label-has-associated-control */

function FilterPrice() {
const handle = () => 'dadada'
function FilterPrice({ changeFilterPrice }) {
return (
<div className="filter-price-container">
<h4>Range Price</h4>
<label htmlFor="points">Max Price:</label>
<input
type="range"
name="points"
min="0"
max="10"
value={7}
onChange={handle}
/>
<label htmlFor="points">Min Price:</label>
<input
type="range"
name="points"
min="0"
max="10"
value={0}
onChange={handle}
/>
<h4>sort :</h4>
<button type="button" onClick={changeFilterPrice}>
max
</button>
<button type="button" onClick={changeFilterPrice}>
min
</button>
</div>
)
);
}

export default FilterPrice
export default FilterPrice;
36 changes: 23 additions & 13 deletions client/src/Components/LandingPage/Products/Products.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <p>Loading ...</p>;
return (
<section className="products-filter-container">
<Filter handleFilterCategory={handleFilterCategory} category={category} />
<Filter
handleFilterCategory={handleFilterCategory}
changeFilterPrice={changeFilterPrice}
category={category}
/>

<div className="products-container">
{category !== 'all'
? [...showMoreData,...newData]
.filter((ele)=> ele.category ===category)
.map((ele) => <Product data={ele} key={ele.id} />)
: [...showMoreData,...newData].map((ele) => <Product data={ele} key={ele.id} />)}
</div>
<button type='button' onClick={showMoreRequest}> Show More </button>
? [...showMoreData, ...newData]
.filter((ele) => ele.category === category)
.map((ele) => <Product data={ele} key={ele.id} />)
: [...showMoreData, ...newData].map((ele) => (
<Product data={ele} key={ele.id} />
))}
</div>
<button type="button" onClick={showMoreRequest}>
{' '}
Show More{' '}
</button>
</section>
);
}
Expand Down

0 comments on commit 7c82870

Please sign in to comment.