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

Develop #616

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

Develop #616

wants to merge 4 commits into from

Conversation

PaninDmytro
Copy link

Copy link

@Stim1 Stim1 left a comment

Choose a reason for hiding this comment

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

Nice!

params={{ sex: 'f' }}
>
Female
</SearchLink>
Copy link

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

Choose a reason for hiding this comment

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

Implement

Copy link

@superpooperxxx superpooperxxx 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🔥 Fix comments and also Reset all filters button should reset filter NOT by leading to /people😉

Comment on lines 9 to 78
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;
};

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

Comment on lines 35 to 41
if (sort && sort !== column) {
newParams = { sort: column, order: null };
}

if (sort && sort === column && order) {
newParams = { sort: null, order: null };
}

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

params={{ sex: 'f' }}
>
Female
</SearchLink>

Choose a reason for hiding this comment

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

Implement

Copy link

@polosanya polosanya 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! I'm approving it, but please pay attention to the comments)

export const getSexParam = (filterType: string) => {
let newParam = {};

if (filterType === 'All') {

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

Comment on lines +48 to +56
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);

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

Comment on lines +33 to +35
{arayOfFilterType.map(filterType => (
<SearchLink
className={cn({

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

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