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

Develop #1136

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Develop #1136

wants to merge 6 commits into from

Conversation

italomagno
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Thank you for your hard work on this Pull Request! While your code is mostly well-structured and meets the task requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Sorting Logic: The handleSortOrder function always sets the order to desc when the sort is initially applied. Please ensure this aligns with the desired behavior for sorting when no order is specified.

  2. Error Handling: The error state is set based on the length of filteredPeople. Make sure this logic is correct and that filteredPeople is updated appropriately before this check to avoid incorrect error messages.

  3. Redundant Code: The setIsLoading(false); call in the finally block is redundant since it's already called in both the then and catch blocks. Please remove it from the finally block.

  4. State Management: The setFilteredPeople function might lead to duplicated entries if the effect runs multiple times. Consider setting filteredPeople directly to response instead of spreading prev.

  5. Century Handling: Ensure that the logic for updating centuries in the handleAddNewCentury function is correctly handled in the getSearchWith function and that the returned value is used appropriately.

  6. Typo: Correct the typo in the interface name ErrrorComponentProps to ErrorComponentProps for consistency.

  7. Routing Logic: The nested route inside /people is redundant. Consider handling the logic for rendering different content based on the presence of :slug within the PeoplePage component itself.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and feel free to reach out if you have any questions or need further clarification. 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

Comment on lines +16 to +18
<Route path="/people" element={<PeoplePage />}>
<Route path="/people/:slug" element={<PeoplePage />} />
</Route>

Choose a reason for hiding this comment

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

The nested route inside /people is redundant since it uses the same component PeoplePage. If PeoplePage is supposed to handle both /people and /people/:slug, you might want to handle the logic for rendering different content based on the presence of :slug within the PeoplePage component itself. Consider removing the nested route or adjusting the component logic.

import React from 'react';
import { ErrorMessages } from './PeoplePage';

interface ErrrorComponentProps {

Choose a reason for hiding this comment

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

There is a typo in the interface name ErrrorComponentProps. It should be corrected to ErrorComponentProps to maintain consistency and avoid confusion.

? centuries.filter(c => c !== century.toString())
: [...centuries, century.toString()];

return newCenturies;

Choose a reason for hiding this comment

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

The handleAddNewCentury function returns newCenturies, but this value is not used directly in the component. Instead, it's passed to getSearchWith in the to prop of the Link component. Ensure that the logic for updating the centuries is correctly handled in the getSearchWith function and that the returned value is used appropriately.

}

setPeople(response);
setFilteredPeople(prev => [...prev, ...response]);

Choose a reason for hiding this comment

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

The setFilteredPeople function is called with a function that spreads the previous state and adds the response. This might lead to duplicated entries if the effect runs multiple times. Consider setting filteredPeople directly to response instead of spreading prev.

setIsLoading(false);
})
.finally(() => {
setIsLoading(false);

Choose a reason for hiding this comment

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

The setIsLoading(false); call in the finally block is redundant since it's already called in both the then and catch blocks. You can remove it from the finally block.

Comment on lines 131 to 135
if (filteredPeople.length === 0) {
setError(ErrorMessages.NO_PEOPLE_MATCHING_CRITERIA);
} else {
setError(ErrorMessages.BLANK);
}

Choose a reason for hiding this comment

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

The error state is set based on the length of filteredPeople. Ensure that this logic is correct and that filteredPeople is updated appropriately before this check. Otherwise, it might lead to incorrect error messages.

Comment on lines +37 to +41
case sort && sort === label.toLowerCase() && !order:
return getSearchWith(searchParams, {
sort: label.toLowerCase(),
order: Order.desc,
});

Choose a reason for hiding this comment

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

In the handleSortOrder function, the first case checks if sort is equal to label.toLowerCase() and order is falsy. This will always set the order to desc when the sort is initially applied. Ensure this logic aligns with the desired behavior for sorting when no order is specified.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: 7]

If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: 7]

If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: 7]

If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link

@raulriato raulriato left a comment

Choose a reason for hiding this comment

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

Hey, @italomagno. It seems you forgot to run the deploy for your project. Please do it so I can review it

@italomagno
Copy link
Author

This is the deployed

export function ErrorComponent({ message }: ErrorComponentProps) {
return (
<>
{message === ErrorMessages.SOMETHING_WENT_WRONG && (

Choose a reason for hiding this comment

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

The way you implemented this isn't wrong, but i would recommend to use dynamic property access to avoid repetition (and personally i think that's also improves code readability)!

Imagine if we have 50 types of error messages, what would we do?

an example implementation:

    <>
        {message && (
            <p data-cy={`${message}Message`}>
            {ErrorMessages[message]}
            </p>
        )}
    </>

@@ -8,13 +13,16 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<a
className={`navbar-item ${path.includes('home') || path === '/' ? 'has-background-grey-lighter' : ''}`}

Choose a reason for hiding this comment

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

Suggested change
className={`navbar-item ${path.includes('home') || path === '/' ? 'has-background-grey-lighter' : ''}`}
className={`navbar-item ${path.includes('home') || path === '/' ? 'has-background-grey-lighter' : ''}`}

We can extract it to a variable (or a function) to avoid complexity in the JSX =)

    const getHomeLinkClassNames = () => {
        const isHome = path.includes('home') || path === '/'

        return isHome ? 'has-background-grey-lighter' : ''
    }

    ...

    <a className={getHomeLinkClassNames()}>

export const PeopleFilters = () => {
const availableCenturies = [16, 17, 18, 19, 20];

Choose a reason for hiding this comment

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

Suggested change
const availableCenturies = [16, 17, 18, 19, 20];
const availableCenturies = [16, 17, 18, 19, 20];

We can move this variable to outside of the component, since we aren't changing it's values anywhere in the code flow, so we can avoid it's re-creation across re-renders =)

Comment on lines +85 to +94
setFilteredPeople(prev => {
return [...prev].filter(
person =>
person.name.toLowerCase().includes(query.toLowerCase()) ||
(person.mother &&
person.mother.name.toLowerCase().includes(query.toLowerCase())) ||
(person.father &&
person.father.name.toLowerCase().includes(query.toLowerCase())),
);
});

Choose a reason for hiding this comment

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

Suggested change
setFilteredPeople(prev => {
return [...prev].filter(
person =>
person.name.toLowerCase().includes(query.toLowerCase()) ||
(person.mother &&
person.mother.name.toLowerCase().includes(query.toLowerCase())) ||
(person.father &&
person.father.name.toLowerCase().includes(query.toLowerCase())),
);
});
setFilteredPeople(prev => {
return [...prev].filter(
person =>
person.name.toLowerCase().includes(query.toLowerCase()) ||
(person.mother &&
person.mother.name.toLowerCase().includes(query.toLowerCase())) ||
(person.father &&
person.father.name.toLowerCase().includes(query.toLowerCase())),
);
});

I would recommend to use the classical if/else here, it would improve readability and facilitate to add new filters in the future =)

Copy link

@julianFBarbosa julianFBarbosa left a comment

Choose a reason for hiding this comment

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

I left some comments and suggestions.

But the main target is well done: the app is working the same way as the example!

Congrats =)

Copy link

@julianFBarbosa julianFBarbosa left a comment

Choose a reason for hiding this comment

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

nice job =)

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.

4 participants