Skip to content

Commit

Permalink
colums mother and father added!
Browse files Browse the repository at this point in the history
  • Loading branch information
JulyaPetrovskaya committed Nov 25, 2023
1 parent 6f61f2f commit 7e24036
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/components/PeopleTable.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import React, { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
import classNames from "classnames";
import { Person } from "../types";
import { TableItem } from "./TableItem";
import { SearchLink } from "./SearchLink";
import { SortFields } from "../types/SortFields";
import React, { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import classNames from 'classnames';
import { Person } from '../types';
import { TableItem } from './TableItem';
import { SearchLink } from './SearchLink';
import { SortFields } from '../types/SortFields';

type Props = {
people: Person[];
};

export const PeopleTable: React.FC<Props> = ({ people }) => {
function isQueryIncluded(str = "", person: Person) {
function isQueryIncluded(str = '', person: Person) {
return (
person.name.toLowerCase().includes(str) ||
person.fatherName?.toLowerCase().includes(str) ||
person.motherName?.toLowerCase().includes(str)
person.name.toLowerCase().includes(str)
|| person.fatherName?.toLowerCase().includes(str)
|| person.motherName?.toLowerCase().includes(str)
);
}

function isBornInCentury(centuries: string[] = [], person: Person) {
return (
!centuries.length ||
centuries.includes(Math.ceil(person.born / 100).toString())
!centuries.length
|| centuries.includes(Math.ceil(person.born / 100).toString())
);
}

const [searchParams] = useSearchParams();
const sex = searchParams.get("sex");
const query = searchParams.get("query");
const centuries = searchParams.getAll("centuries") || [];
const sort = searchParams.get("sort") || "";
const order = searchParams.get("order") || "";
const sex = searchParams.get('sex');
const query = searchParams.get('query');
const centuries = searchParams.getAll('centuries') || [];
const sort = searchParams.get('sort') || '';
const order = searchParams.get('order') || '';
const preparedPeople = useMemo(() => {
const filtredAndSortedPeople = people
.filter((person) => {
const lowerQuery = query?.toLowerCase();

return (
(sex ? person.sex === sex : person) &&
isQueryIncluded(lowerQuery, person) &&
isBornInCentury(centuries, person)
(sex ? person.sex === sex : person)
&& isQueryIncluded(lowerQuery, person)
&& isBornInCentury(centuries, person)
);
})
.sort((person1, person2) => {
Expand All @@ -58,7 +58,7 @@ export const PeopleTable: React.FC<Props> = ({ people }) => {
}
});

if (order === "desc") {
if (order === 'desc') {
filtredAndSortedPeople.reverse();
}

Expand All @@ -77,15 +77,15 @@ export const PeopleTable: React.FC<Props> = ({ people }) => {
{String(field)}
<SearchLink
params={{
sort: order === "desc" && sort === field ? null : field,
order: sort === field && !order ? "desc" : null,
sort: order === 'desc' && sort === field ? null : field,
order: sort === field && !order ? 'desc' : null,
}}
>
<span className="icon">
<i
className={classNames("fas", "fa-sort", {
"fa-sort-up": sort === field && !order,
"fa-sort-down": sort === field && order,
className={classNames('fas', 'fa-sort', {
'fa-sort-up': sort === field && !order,
'fa-sort-down': sort === field && order,
})}
/>
</span>
Expand Down

0 comments on commit 7e24036

Please sign in to comment.