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

Assignment w2 react HANNA MELNYK #14

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

Conversation

hanna-melnyk
Copy link

No description provided.

@sycons sycons self-assigned this Sep 13, 2024
@sycons
Copy link

sycons commented Sep 15, 2024

Please add link to deployed app in the PR description.

@hanna-melnyk
Copy link
Author

Please add link to deployed app in the PR description.

hey, what do you mean by pr description?
I have a link in a readme file:

image

@sycons
Copy link

sycons commented Sep 16, 2024

Please add link to deployed app in the PR description.

hey, what do you mean by pr description? I have a link in a readme file:

image

I see it in the readme now. I missed it before.

By PR description, I was referring to the first comment in the PR.

image

Copy link

@sycons sycons left a comment

Choose a reason for hiding this comment

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

Following was implemented

  • fake-data directory is removed and app connects to endpoints to fetch data ✅
  • API does the filtering ✅
  • App shows error message when request failed ✅

Requested improvements:

  • App shows loading while waiting for request to complete
  • Use client side routing to route to product detail page
  • Improve folder structure by moving components into a folder called components if reusable and pages if standalone. This structure improves maintainability.

import {Product} from "./Product.jsx";


export const AppRoutes = () => {
Copy link

Choose a reason for hiding this comment

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

It's good practice to name the file the same name as the component. So either the file name can be changed to AppRoutes or component can be changed to Routes.


export const CategoryList = () => {
const [categories, setCategories] = useState([]);
const [selectedCategory, setSelectedCategory] = useState(null); // Initialize state with null to show all products
Copy link

Choose a reason for hiding this comment

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

Good use of comment to explain something that is not immediately clear from the code 👍

<img src={product.image} alt={product.title}/>
<h1>{product.title}</h1>
<p>{product.price}</p>
<p>{product.description}</p>
Copy link

Choose a reason for hiding this comment

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

Layout for this page can be improved to be more responsive.
Have a look at the live version


if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
if (!product) return null;
Copy link

Choose a reason for hiding this comment

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

Good practice to handle scenario where product is null 👍
This can be further improved by returning an informative message instead of null. E.g. Product was not found

<Route path="/" element={<CategoryList />} />
<Route path="/products" element={<ProductList />} />
<Route path="/product/:id" element={<Product />} />
</Routes>
Copy link

Choose a reason for hiding this comment

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

Good job of setting up client side routing 👍

} catch (error) {
setError(error.message);
} finally {
setLoading(false);
Copy link

Choose a reason for hiding this comment

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

When is setLoading set to true?

return (
<div className="product-grid">
{products.map((product) => (
<div key={product.id} className="product">
Copy link

Choose a reason for hiding this comment

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

There isn't a link here which when clicked on will lead to the product details page.

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

Successfully merging this pull request may close these issues.

2 participants