Skip to content

Commit

Permalink
filter Mileage
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaIa committed Dec 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a230c4f commit bbf3fcb
Showing 2 changed files with 35 additions and 12 deletions.
35 changes: 26 additions & 9 deletions src/components/CarsList/CarsList.jsx
Original file line number Diff line number Diff line change
@@ -55,18 +55,35 @@ export const CarsList = () => {
console.log('filterBrandPriceCars', filterBrandPriceCars)
// priceTo === 'all' -> filterBrandCars || allCars

// mileage !== 'all' -> filterBrandCars(true) -> filterBrandCars.filter -> filterBrandPriceCars
// mileage !== '' -> filterBrandPriceCars(true)) -> filterBrandPriceCars.filter -> filterBrandPriceMileageCars

let filterBrandPriceMileageCars = false;
if (from !== '' && to !== '' && priceTo !== 'all') {
filterBrandPriceMileageCars = filterBrandPriceCars.filter(car => (car.mileage > from && car.mileage < to));
} else {
if (from !== '' && to !== '' && brand !== 'all') {
filterBrandPriceMileageCars = filterBrandCars.filter(car => (car.mileage > from && car.mileage < to));
} else {
filterBrandPriceMileageCars = allCars.filter(car => (car.mileage > from && car.mileage < to));
}
};

console.log('filterBrandPriceMileageCars', filterBrandPriceMileageCars);


if (priceTo !== 'all') {
dispatch(filterCarsSet(filterBrandPriceCars))
if ((from !== '' && to !== '')) {
dispatch(filterCarsSet(filterBrandPriceMileageCars))
} else {
if (brand !== 'all') {
dispatch(filterCarsSet(filterBrandCars))
} else {
return;
}
}
if (priceTo !== 'all') {
dispatch(filterCarsSet(filterBrandPriceCars))
} else {
if (brand !== 'all') {
dispatch(filterCarsSet(filterBrandCars))
} else {
return;
}
}
};

}, [dispatch, filter, allCars]);

12 changes: 9 additions & 3 deletions src/components/Filters/Filters.jsx
Original file line number Diff line number Diff line change
@@ -32,13 +32,19 @@ export const Filters = () => {
};

const onClickFilter = () => {
console.log('typeof filterMileageFrom', typeof filterMileageFrom);
if (mileageFrom !== '' && mileageTo !== '') {
if (mileageFrom >= mileageTo) {
alert('Mileage "From" must be less than mileage "To"')
return;
}
};

const commonFilter = {
brand: brand.value,
priceTo: toPrice.value,
mileage: {
from: mileageFrom,
to: mileageTo
from: parseInt(mileageFrom),
to: parseInt(mileageTo)
}
};
console.log(commonFilter);

0 comments on commit bbf3fcb

Please sign in to comment.