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..abdcfb99f --- /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..3c85d9086 --- /dev/null +++ b/src/components/NameFilter.tsx @@ -0,0 +1,29 @@ +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" + /> + +