Skip to content

LidiiaStarshynova-w2-React #12

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 29 commits into
base: main
Choose a base branch
from

Conversation

starshynova
Copy link

@starshynova starshynova commented Jan 31, 2025

Assignment Requirements ✅

  • The fake-data directory should not be a part of your project anymore
  • Your app will need to make 2 queries to the following endpoints:
    • https://fakestoreapi.com/products/categories -> To get all the categories
    • https://fakestoreapi.com/products or https://fakestoreapi.com/products/category/:selectedCategory -> To get the products. The API needs to do the filtering, not the frontend. Usually the amount of products will be too large to do the filtering on the frontend.
  • Your app needs to show that it is loading when waiting on the request to come back. You can test this by mimicing a slow connection in your browsers' developer tools
  • Your app needs to show an error message if the request failed
  • Your app needs to go to a detail page /product/:id whenever you click on the product card in the list. This should get the details from the endpoint: https://fakestoreapi.com/products/<id>. For now we won't add a navigation bar, the browsers 'back' button will do the trick. _TIP: You will need to add the react-router-dom package and add the routing to your app regardless.
  • You need to deploy your app somewhere (using something like netlify) and put the link in your PR! Make it a different one than the previous week.

Comments Rules

Type Description
Suggestions • Common best practices, standard improvements
• Should be considered for implementation
Nice-to-have • Based on personal preferences or coding style
• Optional enhancements
Question • Starting a discussion to understand technical decisions
• Asking for clarification or exploring different solutions
Praise • Recognizing and highlighting good practices
• Encouraging positive patterns

@starshynova starshynova force-pushed the LidiiaStarshynova-w2-React branch from d35f801 to 32605cf Compare February 8, 2025 19:55
@ChingHsun ChingHsun self-assigned this Feb 8, 2025
Copy link

@ChingHsun ChingHsun left a comment

Choose a reason for hiding this comment

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

Hi Lidiia
it is good, clean code structure. easy to understand your code.
About error handling and loading statement, there's also need to be handle in the home page.

const ProductDetail = () => {
const { id } = useParams();
const [product, setProduct] = useState(null);
const [loading, setLoading] = useState(true);

Choose a reason for hiding this comment

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

Discussion:
Here are three types of UI state handling, do you think there is any difference, and which one you prefer?

// 1.
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

// 2.
const [status, setStatus] = useState({ loading: true, error: null, success: false });

// 3.
const [status, setStatus] = useState('loading'); // 'loading' | 'error' | 'success'

Copy link
Author

Choose a reason for hiding this comment

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

I prefer the first option, because now for me it is more understandable code than types 2 and 3.


const fetchCategories = async () => {
try {
const response = await fetch('https://fakestoreapi.com/products/categories');

Choose a reason for hiding this comment

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

Suggestion:
In other fetching function you add below at the begining

 setLoading(true);
 setError(null);

But you don't need it here.

What is the difference? Do you need to add them or no need to?
Try to pick one and explain why you choose

Copy link
Author

Choose a reason for hiding this comment

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

In this case I do not need this piece of code, because CategoryList is the part of main page. It can not be loaded separately.

Choose a reason for hiding this comment

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

Comment on lines +16 to +17
setLoading(true);
setError(null);

Choose a reason for hiding this comment

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

Suggested change
setLoading(true);
setError(null);

I mean here, you don't need this,
since these states are already properly initialized when the component mounts.

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