Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all issues( #1 to #8) #68

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

brudevtek
Copy link

Hey, could you please review my changes. I fixed issues and added the new features as requested in issues#1 to 8. My previous PR failed the automated tests. This is a new one after attempting to resolve the issue.
Happy to discuss the changes if necessary.

src/Components/Cart.jsx Outdated Show resolved Hide resolved
src/Components/Cart.jsx Outdated Show resolved Hide resolved
src/Components/Cart.jsx Outdated Show resolved Hide resolved
src/Components/NavBar.jsx Outdated Show resolved Hide resolved
Comment on lines +11 to +15
filterOptions,
setFilterOptions,
sortOptions,
setSortOptions,
products,
Copy link
Member

@sbmsr sbmsr Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This is quite a lot of props coming in to this component. This usually indicates a smell. Check out how I fixed the functionality of this component here, without needing to add many props.‏

Comment on lines 94 to 132
filterOptions.price.forEach((element) => {
if (element.minValue.toString() === e.target.value) {
if (element.checked === false) {
element.checked = true;
} else if (element.checked === true)
element.checked = false;
}
});
let selected_array = [];

let selected_products = filterOptions.price.filter(
function (x) {
return x.checked === true;
}
);

selected_products.forEach((element) => {
selected_array.push(
allproducts.filter(function (item) {
return (
item.price > element.minValue &&
item.price < element.maxValue
);
})
);
});
if (selected_array.length > 0) {
setProducts(selected_array.flat(1));
setselectedByPrice(selected_array.flat(1));
} else {
if (selectedByColor.length > 0) {
setProducts(selectedByColor);
} else {
setProducts(allproducts);
setselectedByPrice(allproducts);
}
}

set_Nbr_Filters_price(selected_array.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: We should try and refactor this. It's quite a large chunk of code which is hard to maneuver at first glance.

I also notice its very similar to some of the code below (160 - 206). Given it's size right, it helps to isolate this to a single helper function, and then call it from the onClick handlers.‏

Copy link
Member

@sbmsr sbmsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, nicely done! I see the exercise definitely got the gears turning. I would take a peek at my PR for some alternative approaches to fixing the issues in the project.

I've added lots of constructive feedback. Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants