-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
implement filtering and sorting #507
base: master
Are you sure you want to change the base?
implement filtering and sorting #507
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.
src/components/PageNotFound.tsx
Outdated
@@ -0,0 +1,3 @@ | |||
export const PageNotFound: React.FC = () => ( |
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.
export const PageNotFound: React.FC = () => ( | |
export const NotFoundPage: React.FC = () => ( |
src/components/People.tsx
Outdated
person: Person, | ||
}; | ||
|
||
export const People: React.FC<Props> = ({ person }) => { |
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.
export const People: React.FC<Props> = ({ person }) => { | |
export const Person: React.FC<Props> = ({ person }) => { |
src/components/PeopleFilters.tsx
Outdated
function toggleCenturies(cntr: string) { | ||
const params = new URLSearchParams(searchParams); | ||
|
||
const newCenturies = centuries.includes(cntr) | ||
? centuries.filter(prevCentury => prevCentury !== cntr) | ||
: [...centuries, cntr]; | ||
|
||
params.delete('centuries'); | ||
newCenturies.forEach(cent => params.append('centuries', cent)); | ||
setSearchParams(params); | ||
} | ||
|
||
function handleClearAllCenturies() { | ||
const params = new URLSearchParams(searchParams); | ||
|
||
params.delete('centuries'); | ||
setSearchParams(params); | ||
} | ||
|
||
function handleResetAllFilters() { | ||
const params = new URLSearchParams(searchParams); | ||
|
||
params.delete('sex'); | ||
params.delete('query'); | ||
setSearchParams(params); | ||
} |
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 don't need these functions. You have params
prop in your SearchLink
for this
src/components/PeopleFilters.tsx
Outdated
<button | ||
key={century} | ||
type="button" | ||
data-cy="century" | ||
className={classNames('button mr-1', { | ||
'is-info': centuries.includes(century), | ||
})} | ||
onClick={() => toggleCenturies(century)} | ||
> | ||
{century} | ||
</button> |
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 should use SearchLink
here
src/components/PeopleFilters.tsx
Outdated
<button | ||
type="button" | ||
data-cy="centuryALL" | ||
className="button is-success is-outlined" | ||
href="#/people" | ||
className={classNames('button is-success', { | ||
'is-outlined': !!centuries.length, | ||
})} | ||
onClick={handleClearAllCenturies} | ||
> | ||
All | ||
</a> | ||
</button> |
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.
Same here, use SearchLink
src/components/PeopleFilters.tsx
Outdated
<a | ||
className="button is-link is-outlined is-fullwidth" | ||
href="#/people" | ||
onClick={() => handleResetAllFilters} | ||
> | ||
Reset all filters | ||
</a> |
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.
And here, use SearchLink
src/components/PeopleList.tsx
Outdated
'fa-sort': sort !== normalizedTitle, | ||
'fa-sort-up': sort === normalizedTitle && !order, | ||
'fa-sort-down': sort === normalizedTitle && order, |
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.
DRY, create variable for repeatable code
src/components/PeoplePage.tsx
Outdated
const preparedPeople = persons.map(person => { | ||
return { | ||
...person, | ||
mother: persons.find(({ name }) => person.motherName === name), | ||
father: persons.find(({ name }) => person.fatherName === name), | ||
}; | ||
}); |
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.
Move this logic to separate helper function
src/helpers/getSortedPeople.tsx
Outdated
if (sort) { | ||
personsClone = personsClone.sort((personA, personB) => { | ||
switch (sort) { | ||
case 'name': |
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 enum
for these options
src/helpers/getSortedPeople.tsx
Outdated
import { Person } from '../types'; | ||
|
||
export function getCentury(person: Person, centuries: string[]) { | ||
return centuries.includes(Math.ceil(person.born / 100).toString()); |
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.
Magic value
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 work 👍
Approved, but as I see this is still not implemented:
2) Keep search params when navigating within the People page (when selecting a person or clicking the People link).
const params = new URLSearchParams(searchParams); | ||
|
||
params.set('query', event.target.value); | ||
setSearchParams(params); |
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 get previous params in setSearchParams
demo link