-
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
Initial solution #1110
base: master
Are you sure you want to change the base?
Initial solution #1110
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.
Good Job 👍
let's improve your solution
src/App.tsx
Outdated
<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 />} /> |
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.
Create an enum
for paths
src/components/Navbar/Navbar.tsx
Outdated
className={({ isActive }) => { | ||
return cn('navbar-item', { | ||
'has-background-grey-lighter': isActive, | ||
}); | ||
}} |
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={({ 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 }} |
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.
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 === '', |
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.
Create a variable for these conditions checks
export const PeoplePage = () => { | ||
const { people, error, loading, filteredPeople } = usePeople(); | ||
|
||
const succesfullyLoadedStatus = !!people.length && !loading; |
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.
succesfullyLoadedStatus
is descriptive but a bit verbose. Consider renaming it to isLoaded
for simplicity.
className={ | ||
personSlug === person.slug ? 'has-background-warning' : '' | ||
} |
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.
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' : ''} |
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.
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.
setLoading(true); | ||
setError(false); | ||
|
||
getPeople() | ||
.then(getPeopleWithParents) | ||
.then(setPeople) | ||
.catch(() => { | ||
setError(true); | ||
}) | ||
.finally(() => { | ||
setLoading(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.
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.
DEMO LINK