Skip to content

Dorelys w2 react #20

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

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

Conversation

dorelysrod
Copy link

Here is the Link to the website

@crevulus crevulus self-assigned this Feb 6, 2025
Copy link

@crevulus crevulus left a comment

Choose a reason for hiding this comment

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

Hi Dorelys,

What a beautiful app! Great attention to detail.

As discussed on the call, please make changes to your fetch calls, as well as some other changes I've mentioned in this review.

<Route
path="/"
element={
<>
Copy link

Choose a reason for hiding this comment

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

It's best practice to use a component here, rather than putting lots of JSX inline in the element prop. You can imagine if your site has 50 routes, that will be 50 implementations of JSX. This file would quickly become unmanageable! 🟢

@@ -0,0 +1,31 @@
#category-list {
Copy link

Choose a reason for hiding this comment

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

Lovely css directory organisation!

margin: 40px auto;
}

.product-detail img {
Copy link

Choose a reason for hiding this comment

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

It's better to apply a class to the img, p, and the h2, rather than targeting the image and title elements inside another class. We only really do this if we're importing a third party library and you need to access elements you can't add class names to. But in your case, you can control the class names on those elements. 🟠

background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
Copy link

Choose a reason for hiding this comment

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

In some places you use hex codes and in others you use rgb. Choose one and stick to it in order to be more consistent. 🟢

transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-item:hover {
Copy link

Choose a reason for hiding this comment

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

Nice attention to detail!

if (err.name !== "AbortError") {
setProducts([]);
setError("Failed to load products");
setLoading(false);
Copy link

Choose a reason for hiding this comment

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

You call setLoading(false) twice. Can you think of a way to only do it once? Hint: it is a method related to your try---catch logic. 🟠


return (
<div id="product-list" className="product-list">
{loading && <Spinner />}
Copy link

Choose a reason for hiding this comment

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

That's a lot of conditional inline logic! It will become hard to manage very quickly. you need to check if loading, if loading but not error, if error but not data etc.

Instead, it's better to do conditional logic above your main return statement.

if (loading) return ...
if (error) return ...

🟠

Comment on lines 14 to 15
const controller = new AbortController();
const signal = controller.signal;
Copy link

Choose a reason for hiding this comment

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

This is a very advanced pattern, and probably too complex for this kinf of application. I suggest you remove it and make this fetch call more similar to your fetch calls in other components. 🟠

setLoading(false);
})
.catch((err) => {
if (err.name !== "AbortError") {
Copy link

Choose a reason for hiding this comment

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

Once you've made your change to remove AbortController you will not need this if line. 🟠

})
.then((data) => {
setCategories(Array.isArray(data) ? data : []);
setLoading(false);
Copy link

Choose a reason for hiding this comment

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

In this implementation you call setLoading twice, but in ProductDetail you only call it once. Once is better! 🟠

Copy link
Author

Choose a reason for hiding this comment

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

All requested changes have been implemented. Here is the link to the newly deployed version.

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

Successfully merging this pull request may close these issues.

2 participants