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

Initial solution #1110

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

Initial solution #1110

wants to merge 4 commits into from

Conversation

v1RnT
Copy link

@v1RnT v1RnT commented Nov 1, 2024

Copy link

@igorkruz igorkruz 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 solution

src/App.tsx Outdated
Comment on lines 17 to 24
<Route path="/">
<Route index element={<HomePage />} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="/people" element={<PeoplePage />}>
<Route index />
<Route path=":personSlug?" />
</Route>
<Route path="*" element={<PageNotFound />} />

Choose a reason for hiding this comment

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

Create an enum for paths

Comment on lines 15 to 19
className={({ isActive }) => {
return cn('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}

Choose a reason for hiding this comment

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

Suggested change
className={({ isActive }) => {
return cn('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}
className={({ isActive }) =>
cn('navbar-item', { 'has-background-grey-lighter': isActive })
}

<p className="panel-tabs" data-cy="SexFilter">
<SearchLink
className={cn({ 'is-active': sex === null })}
params={{ sex: null }}

Choose a reason for hiding this comment

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

You can create an enum for sex values

<div className="panel-block">
<SearchLink
className={cn('button is-link is-outlined is-fullwidth', {
'is-outlined': sex === null && !centuries.length && query === '',

Choose a reason for hiding this comment

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

Create a variable for these conditions checks

export const PeoplePage = () => {
const { people, error, loading, filteredPeople } = usePeople();

const succesfullyLoadedStatus = !!people.length && !loading;

Choose a reason for hiding this comment

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

succesfullyLoadedStatus is descriptive but a bit verbose. Consider renaming it to isLoaded for simplicity.

Comment on lines 55 to 57
className={
personSlug === person.slug ? 'has-background-warning' : ''
}

Choose a reason for hiding this comment

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

it's better to use classnames in cases like that, it allows you to dynamically toggle classes based on state or props without manually concatenating strings, making the code more maintainable and easier to read.

pathname: `/people/${person.slug}`,
search: searchParams.toString(),
}}
className={person.sex === 'f' ? 'has-text-danger' : ''}

Choose a reason for hiding this comment

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

it's better to use classnames in cases like that, it allows you to dynamically toggle classes based on state or props without manually concatenating strings, making the code more maintainable and easier to read.

Comment on lines +21 to +32
setLoading(true);
setError(false);

getPeople()
.then(getPeopleWithParents)
.then(setPeople)
.catch(() => {
setError(true);
})
.finally(() => {
setLoading(false);
});

Choose a reason for hiding this comment

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

It's better to move the logic inside the useEffect hook to a separate function, as it improves code readability, reusability, and makes testing easier. It also helps keep useEffect focused on side effects.

@v1RnT v1RnT requested a review from igorkruz November 27, 2024 20:33
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.

2 participants