Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ implement the ability to filter and sort people in the table.
1. Keep search params when navigating within the `People` page (when selecting a person or clicking the `People` link).
1. The sidebar with the filters should appear only when people are loaded.
1. `NameFilter` should update the `query` search param with the text from the input.
- show only people with the `name`, `motherName` or `fatherName` that match the query case insensitive;
- if the input is empty there should not be `query` in the search params.
- show only people with the `name`, `motherName` or `fatherName` that match the query case insensitive;
- if the input is empty there should not be `query` in the search params.
1. `CenturyFilter` should allow to choose several centuries or all of them.
- add `centuries` search params using `append` method `getAll` method;
- add `centuries` search params using `append` method `getAll` method;
1. Implement sorting by `name`, `sex`, `born` and `died` by clicking on arrows in a `th`;
- the first click on a column sorts people by the selected field ascending (`a -> z` or `0 -> 9`);
- the second click (when people are already sorted ascending by this field) reverses the order of sorting;
- the third click (when people are already sorted in reversed order by this field) disables sorting;
- use `sort` search param to save sort field;
- add `order=desc` (short for `descending`) if sorted in reversed order;
- if sorting is disabled there should not be `sort` and `order` search params;
- the first click on a column sorts people by the selected field ascending (`a -> z` or `0 -> 9`);
- the second click (when people are already sorted ascending by this field) reverses the order of sorting;
- the third click (when people are already sorted in reversed order by this field) disables sorting;
- use `sort` search param to save sort field;
- add `order=desc` (short for `descending`) if sorted in reversed order;
- if sorting is disabled there should not be `sort` and `order` search params;

## Instructions

- Install Prettier Extention and use this [VSCode settings](https://mate-academy.github.io/fe-program/tools/vscode/settings.json) to enable format on save.
- 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 `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_people-table-advanced/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://Sviatoslav593.github.io/react_people-table-advanced/) and add it to the PR description.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PeoplePage } from './components/PeoplePage';
import React from 'react';
import { Navbar } from './components/Navbar';

import './App.scss';
import { Outlet } from 'react-router-dom';

export const App = () => {
return (
Expand All @@ -10,9 +11,7 @@ export const App = () => {

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<Outlet />
</div>
</div>
</div>
Expand Down
30 changes: 30 additions & 0 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required implementation: PeopleFilters.tsx - must implement NameFilter (query param), CenturyFilter (centuries param with append/getAll), and SexFilter (sex param) according to requirements.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required implementation: PeoplePage.tsx - must implement filtering logic (name, sex, centuries), sorting by name/sex/born/died, and URL search params persistence.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required implementation: PeopleTable.tsx - must implement sortable table headers with sort/order params, ascending/descending/disabled toggle cycle, and filter visibility only when people are loaded.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required implementation: PersonLink.tsx - must maintain search params when navigating to person details (preserve filters/sort on click).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing required implementation: SearchLink.tsx - utility component for updating URL search params that must be used throughout the app.

Navigate,
Route,
HashRouter as Router,
Routes,
} from 'react-router-dom';
import { App } from './App';
import React from 'react';
import { NotFoundPage } from './components/NotFoundPage';
import { HomePage } from './components/HomePage';
import { PeoplePage } from './components/PeoplePage';

export const Root = () => {
return (
<Router>
<Routes>
<Route path="/" element={<App />}>
<Route path="*" element={<NotFoundPage />}></Route>

<Route index element={<HomePage />} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="people/">
<Route index element={<PeoplePage />} />
<Route path=":slug" element={<PeoplePage />} />
</Route>
</Route>
</Routes>
</Router>
);
};
3 changes: 3 additions & 0 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export const HomePage = () => <h1 className="title">Home Page</h1>;
21 changes: 13 additions & 8 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import classNames from 'classnames';
import React from 'react';
import { NavLink } from 'react-router-dom';

export const Navbar = () => {
const isLinkActive = ({ isActive }: { isActive: boolean }) =>
classNames('navbar-item', {
'has-background-grey-lighter': isActive,
});

return (
<nav
data-cy="nav"
Expand All @@ -8,17 +17,13 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<NavLink className={isLinkActive} to="/">
Home
</a>
</NavLink>

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
>
<NavLink aria-current="page" className={isLinkActive} to="/people">
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
3 changes: 3 additions & 0 deletions src/components/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export const NotFoundPage = () => <h1 className="title">Page not found</h1>;
126 changes: 76 additions & 50 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
import React from 'react';
import { getSearchWith, SearchParams } from '../utils/searchHelper';
import { useSearchParams } from 'react-router-dom';
import { SearchLink } from './SearchLink';
import classNames from 'classnames';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const sort = searchParams.get('sort');
const order = searchParams.get('order');

const centuriesArray = searchParams.getAll('centuries');

const setSearchWith = (params: SearchParams) => {
const search = getSearchWith(searchParams, params);

setSearchParams(search);
};

const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchWith({ query: event.target.value.trim() || null });
};

const handleResetFiltersBtn = () => {
setSearchWith({
sort: sort || null,
order: order || null,
query: null,
sex: null,
centuries: null,
});
};

return (
<nav className="panel">
<p className="panel-heading">Filters</p>

<p className="panel-tabs" data-cy="SexFilter">
<a className="is-active" href="#/people">
<SearchLink
className={classNames({ 'is-active': !searchParams.get('sex') })}
params={{ sex: null }}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>
<SearchLink
className={classNames({
'is-active': searchParams.get('sex') === 'm',
})}
params={{ sex: 'm' }}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>
<SearchLink
className={classNames({
'is-active': searchParams.get('sex') === 'f',
})}
params={{ sex: 'f' }}
>
Female
</a>
</SearchLink>
</p>

<div className="panel-block">
Expand All @@ -22,6 +67,7 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
onChange={handleQueryChange}
/>

<span className="icon is-left">
Expand All @@ -33,63 +79,43 @@ export const PeopleFilters = () => {
<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=16"
>
16
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=17"
>
17
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=18"
>
18
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=19"
>
19
</a>

<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
>
20
</a>
{['16', '17', '18', '19', '20'].map(centurie => (
<SearchLink
key={centurie}
data-cy="century"
className={classNames('button mr-1', {
'is-info': centuriesArray.includes(centurie),
})}
params={{
centuries: centuriesArray?.includes(centurie)
? centuriesArray.filter(c => c !== centurie)
: [...centuriesArray, centurie],
}}
>
{centurie}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<a
<SearchLink
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
params={{ centuries: null }}
>
All
</a>
</SearchLink>
</div>
</div>
</div>

<div className="panel-block">
<a className="button is-link is-outlined is-fullwidth" href="#/people">
<button
className="button is-link is-outlined is-fullwidth"
onClick={handleResetFiltersBtn}
>
Reset all filters
</a>
</button>
</div>
</nav>
);
Expand Down
Loading
Loading