From e2078007b2b12ab52ca77b5cc1046ee66bbd8fb3 Mon Sep 17 00:00:00 2001 From: valerij Date: Sat, 13 Jun 2026 09:06:57 +0300 Subject: [PATCH 1/2] react_people-table-advanced --- package-lock.json | 9 +- package.json | 2 +- src/App.tsx | 19 +- src/components/Navbar.tsx | 26 +- src/components/PeopleFilters.tsx | 121 +++--- src/components/PeoplePage.tsx | 102 ++++- src/components/PeopleTable.tsx | 726 +++++-------------------------- src/components/PersonLink.tsx | 22 + 8 files changed, 329 insertions(+), 698 deletions(-) create mode 100644 src/components/PersonLink.tsx diff --git a/package-lock.json b/package-lock.json index df276ce8a..a2d822adb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.9.12", + "@mate-academy/scripts": "^2.1.3", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", @@ -1184,10 +1184,11 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.9.12", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.9.12.tgz", - "integrity": "sha512-/OcmxMa34lYLFlGx7Ig926W1U1qjrnXbjFJ2TzUcDaLmED+A5se652NcWwGOidXRuMAOYLPU2jNYBEkKyXrFJA==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-2.1.3.tgz", + "integrity": "sha512-a07wHTj/1QUK2Aac5zHad+sGw4rIvcNl5lJmJpAD7OxeSbnCdyI6RXUHwXhjF5MaVo9YHrJ0xVahyERS2IIyBQ==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/rest": "^17.11.2", "@types/get-port": "^4.2.0", diff --git a/package.json b/package.json index 919fbd42b..77fc93ccf 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.9.12", + "@mate-academy/scripts": "^2.1.3", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", diff --git a/src/App.tsx b/src/App.tsx index adcb8594e..3bb22d5c0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,13 @@ +import { Routes, Route, Navigate } from 'react-router-dom'; import { PeoplePage } from './components/PeoplePage'; import { Navbar } from './components/Navbar'; import './App.scss'; +// Створюємо прості компоненти для сторінок прямо тут +const HomePage = () =>

Home Page

; +const NotFoundPage = () =>

Page not found

; + export const App = () => { return (
@@ -10,9 +15,17 @@ export const App = () => {
-

Home Page

-

Page not found

- + + } /> + } /> + + + } /> + } /> + + + } /> +
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 3f63898b2..6419803e8 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -1,4 +1,9 @@ +import { NavLink, useLocation } from 'react-router-dom'; + export const Navbar = () => { + // Дістаємо поточний рядок з параметрами (наприклад: "?sex=m¢uries=18") + const { search } = useLocation(); + return ( diff --git a/src/components/PeopleFilters.tsx b/src/components/PeopleFilters.tsx index c9c819cd3..b49450ba6 100644 --- a/src/components/PeopleFilters.tsx +++ b/src/components/PeopleFilters.tsx @@ -1,18 +1,59 @@ +import { Link, useSearchParams } from 'react-router-dom'; +import { getSearchWith } from '../utils/searchHelper'; + export const PeopleFilters = () => { + const [searchParams, setSearchParams] = useSearchParams(); + + // Витягуємо поточні значення з URL для підсвічування активних кнопок/табів + const query = searchParams.get('query') || ''; + const sex = searchParams.get('sex'); + const centuries = searchParams.getAll('centuries'); + + // Обробник для текстового поля пошуку + const handleQueryChange = (e: React.ChangeEvent) => { + const value = e.target.value; + + setSearchParams(getSearchWith(searchParams, { query: value || null })); + }; + + // Логіка для додавання/видалення століть + const getCenturySearch = (century: string) => { + let newCenturies = [...centuries]; + + if (newCenturies.includes(century)) { + newCenturies = newCenturies.filter(c => c !== century); + } else { + newCenturies.push(century); + } + + return getSearchWith(searchParams, { + centuries: newCenturies.length > 0 ? newCenturies : null, + }); + }; + return (