-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
Develop #1136
Conversation
There was a problem hiding this 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:
-
Sorting Logic: The
handleSortOrder
function always sets the order todesc
when the sort is initially applied. Please ensure this aligns with the desired behavior for sorting when no order is specified. -
Error Handling: The error state is set based on the length of
filteredPeople
. Make sure this logic is correct and thatfilteredPeople
is updated appropriately before this check to avoid incorrect error messages. -
Redundant Code: The
setIsLoading(false);
call in thefinally
block is redundant since it's already called in both thethen
andcatch
blocks. Please remove it from thefinally
block. -
State Management: The
setFilteredPeople
function might lead to duplicated entries if the effect runs multiple times. Consider settingfilteredPeople
directly toresponse
instead of spreadingprev
. -
Century Handling: Ensure that the logic for updating centuries in the
handleAddNewCentury
function is correctly handled in thegetSearchWith
function and that the returned value is used appropriately. -
Typo: Correct the typo in the interface name
ErrrorComponentProps
toErrorComponentProps
for consistency. -
Routing Logic: The nested route inside
/people
is redundant. Consider handling the logic for rendering different content based on the presence of:slug
within thePeoplePage
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.
<Route path="/people" element={<PeoplePage />}> | ||
<Route path="/people/:slug" element={<PeoplePage />} /> | ||
</Route> |
There was a problem hiding this comment.
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.
src/components/ErrorComponent.tsx
Outdated
import React from 'react'; | ||
import { ErrorMessages } from './PeoplePage'; | ||
|
||
interface ErrrorComponentProps { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
src/components/PeoplePage.tsx
Outdated
} | ||
|
||
setPeople(response); | ||
setFilteredPeople(prev => [...prev, ...response]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
src/components/PeoplePage.tsx
Outdated
if (filteredPeople.length === 0) { | ||
setError(ErrorMessages.NO_PEOPLE_MATCHING_CRITERIA); | ||
} else { | ||
setError(ErrorMessages.BLANK); | ||
} |
There was a problem hiding this comment.
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.
case sort && sort === label.toLowerCase() && !order: | ||
return getSearchWith(searchParams, { | ||
sort: label.toLowerCase(), | ||
order: Order.desc, | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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
src/components/ErrorComponent.tsx
Outdated
export function ErrorComponent({ message }: ErrorComponentProps) { | ||
return ( | ||
<> | ||
{message === ErrorMessages.SOMETHING_WENT_WRONG && ( |
There was a problem hiding this comment.
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>
)}
</>
src/components/Navbar.tsx
Outdated
@@ -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' : ''}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()}>
src/components/PeopleFilters.tsx
Outdated
export const PeopleFilters = () => { | ||
const availableCenturies = [16, 17, 18, 19, 20]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 =)
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())), | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 =)
There was a problem hiding this 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 =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice job =)
No description provided.