From 73132cbcc1e40d756b28b5a29f6d8ff9a5761fd4 Mon Sep 17 00:00:00 2001 From: Rupert Wisdom Date: Thu, 2 Jul 2026 08:08:43 -0400 Subject: [PATCH 1/2] Implement filtering and sorting features --- README.md | 2 +- src/App.tsx | 32 +- src/components/CenturyFilter.tsx | 45 +++ src/components/NameFilter.tsx | 27 ++ src/components/Navbar.tsx | 28 +- src/components/PeopleFilters.tsx | 111 ++---- src/components/PeoplePage.tsx | 113 +++++- src/components/PeopleTable.tsx | 656 +++---------------------------- src/components/PersonLink.tsx | 26 ++ src/components/SortLink.tsx | 33 ++ 10 files changed, 364 insertions(+), 709 deletions(-) create mode 100644 src/components/CenturyFilter.tsx create mode 100644 src/components/NameFilter.tsx create mode 100644 src/components/PersonLink.tsx create mode 100644 src/components/SortLink.tsx diff --git a/README.md b/README.md index 064a39440..8ac7d3085 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://RupertWisdomjm.github.io/react_people-table-advanced/) and add it to the PR description. diff --git a/src/App.tsx b/src/App.tsx index adcb8594e..f9ba57822 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,20 +1,24 @@ +import { Navigate, Route, Routes } from 'react-router-dom'; + import { PeoplePage } from './components/PeoplePage'; import { Navbar } from './components/Navbar'; -import './App.scss'; - -export const App = () => { - return ( -
- +export const App = () => ( +
+ -
-
-

Home Page

-

Page not found

- -
+
+
+ + Home Page} /> + } /> + + } /> + } /> + + Page not found} /> +
- ); -}; +
+); diff --git a/src/components/CenturyFilter.tsx b/src/components/CenturyFilter.tsx new file mode 100644 index 000000000..49face8e1 --- /dev/null +++ b/src/components/CenturyFilter.tsx @@ -0,0 +1,45 @@ +import classNames from 'classnames'; +import { useSearchParams } from 'react-router-dom'; +import { SearchLink } from './SearchLink'; + +const AVAILABLE_CENTURIES = ['16', '17', '18', '19', '20']; + +export const CenturyFilter = () => { + const [searchParams] = useSearchParams(); + const centuries = searchParams.getAll('centuries'); + + return ( +
+
+ {AVAILABLE_CENTURIES.map(century => ( + c !== century) // we remove it from the selected + : [...centuries, century], // otherwise we add it to the selected + }} + > + {century} + + ))} +
+ +
+ 0, + })} + > + All + +
+
+ ); +}; diff --git a/src/components/NameFilter.tsx b/src/components/NameFilter.tsx new file mode 100644 index 000000000..97e559868 --- /dev/null +++ b/src/components/NameFilter.tsx @@ -0,0 +1,27 @@ +import { useSearchParams } from 'react-router-dom'; +import { getSearchWith } from '../utils/searchHelper'; + +export const NameFilter = () => { + const [searchParams, setSearchParams] = useSearchParams(); + const query = searchParams.get('query') || ''; + + return ( +

+ setSearchParams( + getSearchWith(searchParams, { + query: event.target.value || null, + }), + )} + className="input" + type="text" + placeholder="Search" + /> + +