-
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
Develop #616
base: master
Are you sure you want to change the base?
Develop #616
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.
Nice!
src/components/PeopleFilters.tsx
Outdated
params={{ sex: 'f' }} | ||
> | ||
Female | ||
</SearchLink> |
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.
nothing serious but you can use the map method here
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.
Implement
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🔥 Fix comments and also Reset all filters
button should reset filter NOT by leading to /people
😉
src/components/PeoplePage.tsx
Outdated
const getVisiblePeople = ( | ||
people: Person[], { | ||
sex, centuries, query, sort, order, | ||
}: { | ||
sex: string, | ||
centuries: string[], | ||
query: string, | ||
sort: string | null, | ||
order: string | null, | ||
}, | ||
) => { | ||
let copiePeople = [...people]; | ||
|
||
if (sex) { | ||
copiePeople = copiePeople.filter(person => { | ||
switch (sex) { | ||
case 'm': | ||
return person.sex === 'm'; | ||
case 'f': | ||
return person.sex === 'f'; | ||
case '': | ||
default: | ||
return copiePeople; | ||
} | ||
}); | ||
} | ||
|
||
if (centuries.length > 0) { | ||
copiePeople = copiePeople.filter(person => { | ||
return centuries.includes(Math.ceil(person.born / 100).toString()); | ||
}); | ||
} | ||
|
||
if (query) { | ||
const normalizedQuery = query.toLowerCase().trim(); | ||
|
||
copiePeople = copiePeople.filter(person => { | ||
return person.name.toLowerCase().includes(normalizedQuery) | ||
|| person.motherName?.toLowerCase().includes(normalizedQuery) | ||
|| person.fatherName?.toLowerCase().includes(normalizedQuery); | ||
}); | ||
} | ||
|
||
if (sort) { | ||
copiePeople = copiePeople.sort((person1, person2): number => { | ||
switch (sort) { | ||
case 'name': | ||
return order | ||
? person2.name.localeCompare(person1.name) | ||
: person1.name.localeCompare(person2.name); | ||
case 'sex': | ||
return order | ||
? person2.sex.localeCompare(person1.sex) | ||
: person1.sex.localeCompare(person2.sex); | ||
case 'born': | ||
return order | ||
? person2.born - person1.born | ||
: person1.born - person2.born; | ||
case 'died': | ||
return order | ||
? person2.died - person1.died | ||
: person1.died - person2.died; | ||
default: | ||
return 0; | ||
} | ||
}); | ||
} | ||
|
||
return copiePeople; | ||
}; |
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.
Let's take this function to separate file
src/components/PeopleTable.tsx
Outdated
if (sort && sort !== column) { | ||
newParams = { sort: column, order: null }; | ||
} | ||
|
||
if (sort && sort === column && order) { | ||
newParams = { sort: null, order: 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.
2 conditions return the same thing, combine
src/components/PeopleFilters.tsx
Outdated
params={{ sex: 'f' }} | ||
> | ||
Female | ||
</SearchLink> |
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.
Implement
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! I'm approving it, but please pay attention to the comments)
export const getSexParam = (filterType: string) => { | ||
let newParam = {}; | ||
|
||
if (filterType === 'All') { |
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.
Consider using Enum instead of the hardcoded value where it's possible
switch (sort) { | ||
case 'name': | ||
return order | ||
? person2.name.localeCompare(person1.name) | ||
: person1.name.localeCompare(person2.name); | ||
case 'sex': | ||
return order | ||
? person2.sex.localeCompare(person1.sex) | ||
: person1.sex.localeCompare(person2.sex); |
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.
Similar cases can be combined
{arayOfFilterType.map(filterType => ( | ||
<SearchLink | ||
className={cn({ |
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.
Don't forget about key attribute
DEMO LINK