Skip to content

Commit

Permalink
clean-up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniilart01 committed Nov 29, 2023
1 parent 74310c6 commit 2f7ffbf
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions src/components/PeopleTable/PeopleTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ export const PeopleTable: React.FC<Props> = ({ people }) => {
const [searchParams] = useSearchParams();

const getSortingParams = useCallback((param: string): SearchParams => {
if (searchParams.get('sort') === param
&& searchParams.get('order') === 'desc') {
return { sort: null, order: null };
}

if (searchParams.get('sort') === param) {
if (searchParams.get('order') === 'desc') {
return { sort: null, order: null };
}

return { sort: param, order: 'desc' };
}

Expand Down Expand Up @@ -100,36 +99,43 @@ export const PeopleTable: React.FC<Props> = ({ people }) => {
</thead>

<tbody>
{proceedPeople(people, searchParams).map((person) => (
<tr
data-cy="person"
className={cn(
{ 'has-background-warning': person.slug === humanId },
)}
>
<td>
<PersonLink person={person} />
</td>
{proceedPeople(people, searchParams).map((person) => {
const {
sex, born, died, slug, motherName,
fatherName, mother, father,
} = person;

return (
<tr
data-cy="person"
className={cn(
{ 'has-background-warning': slug === humanId },
)}
>
<td>
<PersonLink person={person} />
</td>

<td>{person.sex}</td>
<td>{person.born}</td>
<td>{person.died}</td>
<td>
{
person.mother
? <PersonLink person={person.mother} />
: person.motherName || '-'
}
</td>
<td>
{
person.father
? <PersonLink person={person.father} />
: person.fatherName || '-'
}
</td>
</tr>
))}
<td>{sex}</td>
<td>{born}</td>
<td>{died}</td>
<td>
{
mother
? <PersonLink person={mother} />
: motherName || '-'
}
</td>
<td>
{
father
? <PersonLink person={father} />
: fatherName || '-'
}
</td>
</tr>
);
})}
</tbody>
</table>
);
Expand Down

0 comments on commit 2f7ffbf

Please sign in to comment.