From b7a84892214753bb821c44c55969bc4e39b77fd4 Mon Sep 17 00:00:00 2001 From: Alyona Verbanova Date: Thu, 2 Jan 2025 13:36:54 +0100 Subject: [PATCH] improve code --- README.md | 2 +- src/constants/constants.ts | 1 + src/pages/PeoplePage.tsx | 9 ++++++--- src/types/sex.ts | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/constants/constants.ts create mode 100644 src/types/sex.ts diff --git a/README.md b/README.md index 064a39440..a3828a4d8 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,4 @@ implement the ability to filter and sort people in the table. - Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline). - Use the [React TypeScript cheat sheet](https://mate-academy.github.io/fe-program/js/extra/react-typescript). - Open one more terminal and run tests with `npm test` to ensure your solution is correct. -- Replace `` with your Github username in the [DEMO LINK](https://.github.io/react_people-table-advanced/) and add it to the PR description. +- Replace `` with your Github username in the [DEMO LINK](https://AlyonaV22.github.io/react_people-table-advanced/) and add it to the PR description. diff --git a/src/constants/constants.ts b/src/constants/constants.ts new file mode 100644 index 000000000..82d3961a1 --- /dev/null +++ b/src/constants/constants.ts @@ -0,0 +1 @@ +export const CENTURIES = [16, 17, 18, 19, 20]; diff --git a/src/pages/PeoplePage.tsx b/src/pages/PeoplePage.tsx index 053f50e2b..46f517835 100644 --- a/src/pages/PeoplePage.tsx +++ b/src/pages/PeoplePage.tsx @@ -19,11 +19,14 @@ const isSelectedPeople = ( if (query && query.trim()) { const newQuery = query.toLowerCase(); + const isQuery = (field: string | null | undefined): boolean => + field?.toLowerCase().includes(newQuery) ?? false; + selectedPeople = selectedPeople.filter( person => - person.name.toLowerCase().includes(newQuery) || - person.motherName?.toLowerCase().includes(newQuery) || - person.fatherName?.toLowerCase().includes(newQuery), + isQuery(person.name) || + isQuery(person.motherName) || + isQuery(person.fatherName), ); } diff --git a/src/types/sex.ts b/src/types/sex.ts new file mode 100644 index 000000000..5e86180d4 --- /dev/null +++ b/src/types/sex.ts @@ -0,0 +1,4 @@ +export enum Sex { + Male = 'm', + Female = 'f', +}