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

solution #1125

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

solution #1125

wants to merge 2 commits into from

Conversation

Shevchuchka
Copy link

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.

Great job on implementing the task requirements! 🎉 While there are some minor areas for improvement, such as simplifying routing logic and refining useEffect dependencies, these do not significantly impact the functionality. Keep up the good work and consider the feedback for future enhancements! 🚀

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

Comment on lines +11 to +12
<Route index element={<HomePage />} />
<Route path=":home" element={<HomePage />} />

Choose a reason for hiding this comment

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

There is a potential redundancy here. Both the index route and the :home route point to HomePage. If :home is intended to be a dynamic segment, consider clarifying its purpose or removing it if unnecessary.

}) => {
const query = searchParams.get('query') || '';
const sex = searchParams.get('sex') || '';
const centuries = searchParams.getAll('centuries') || [];

Choose a reason for hiding this comment

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

The getAll method for searchParams will return an array, so the fallback to an empty array is unnecessary. Consider removing || [].

onCenturieFilter();

setCurrentPeopleList(newPeopleList);
}, [sex, query, centuries]);

Choose a reason for hiding this comment

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

Ensure that setCurrentPeopleList is included in the dependency array of useEffect if it is not guaranteed to be stable across renders. This can prevent potential bugs related to stale closures.


useEffect(() => {
setNewList(newPeopleList);
}, [peopleList]);

Choose a reason for hiding this comment

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

Consider adding newPeopleList to the dependency array of this useEffect to ensure it updates correctly when peopleList changes.


useEffect(() => {
sortListFunc();
}, [sort, order, newList]);

Choose a reason for hiding this comment

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

The newList dependency in this useEffect might cause unnecessary re-renders. Since sortListFunc updates newList, it might be better to remove newList from the dependencies to avoid potential infinite loops.

Comment on lines +6 to +8
if (home === 'home') {
return <Navigate to="/" replace />;
}

Choose a reason for hiding this comment

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

The check for home === 'home' and subsequent redirect to '/' seems unnecessary. If the home parameter is not required for any specific logic, consider removing this condition to simplify the component.


export const PeoplePage = () => {
const [people, setPeople] = useState<Person[]>([]);
const [currentPeopleList, setCurrentPeopleList] = useState<Person[]>(people);

Choose a reason for hiding this comment

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

Initializing currentPeopleList with people directly might lead to unexpected behavior since people is initially an empty array. Consider initializing currentPeopleList as an empty array or updating it in the useEffect after people is fetched.

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Good job 👍
Let's improve your code

  1. Don't need to reset filters after clicking on the person
image image
  1. Fix the search UI when we don't have people, check it on the working example
image

<Link
to={`/people/${person.mother.slug}`}
className={classNames({
'has-text-danger': person.mother.sex === 'f',

Choose a reason for hiding this comment

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

Create a enum for 'f' and use it everywhere

<p data-cy="peopleLoadingError">Something went wrong</p>
)}

{!loading && people.length === 0 && (

Choose a reason for hiding this comment

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

Suggested change
{!loading && people.length === 0 && (
{!loading && !people.length && (

</p>
)}

{!loading && !error && people.length > 0 && (

Choose a reason for hiding this comment

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

Suggested change
{!loading && !error && people.length > 0 && (
{!loading && !error && !!people.length && (

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