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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<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://Nika-Andriy.github.io/react_people-table-advanced/) and add it to the PR description.
12 changes: 9 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

import './App.scss';
import { Navigate, Route, Routes } from 'react-router-dom';
import { HomePage } from './components/HomePage';
import { NotFoundPage } from './components/NotFoundPage';

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

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="/people/:slug?" element={<PeoplePage />} />
<Route path="*" element={<NotFoundPage />} />
</Routes>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HomePage = () => {
return <h1 className="title">Home Page</h1>;
};
15 changes: 10 additions & 5 deletions src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import './Loader.scss';

export const Loader = () => (
<div className="Loader" data-cy="loader">
<div className="Loader__content" />
</div>
);
type Props = {
load: boolean;
};

export const Loader: React.FC<Props> = ({ load }) =>
load && (
<div className="Loader" data-cy="loader">
<div className="Loader__content" />
</div>
);
24 changes: 18 additions & 6 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import classNames from 'classnames';
import { Link, useLocation } from 'react-router-dom';

export const Navbar = () => {
const { pathname, search } = useLocation();

return (
<nav
data-cy="nav"
Expand All @@ -8,17 +13,24 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<Link
className={classNames('navbar-item', {
'has-background-grey-lighter': pathname === '/',
})}
to="/"
>
Home
</a>
</Link>

<a
<Link

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The People link should use SearchLink instead of Link to preserve search params when navigating. This is required by task requirement #2: 'Keep search params when navigating within the People page (when selecting a person or clicking the People link).'

aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
className={classNames('navbar-item', {
'has-background-grey-lighter': pathname.startsWith('/people'),
})}
to={{ pathname: '/people', search }}
>
People
</a>
</Link>
</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 @@
export const NotFoundPage = () => {
return <h1 className="title">Page not found</h1>;
};
174 changes: 141 additions & 33 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
export const PeopleFilters = () => {
import { Link, SetURLSearchParams } from 'react-router-dom';
import { getSearchWith } from '../utils/searchHelper';
import classNames from 'classnames';

type Props = {
searchParams: URLSearchParams;
setSearchParams: SetURLSearchParams;
};

export const PeopleFilters: React.FC<Props> = ({
setSearchParams,
searchParams,
}) => {
const query = searchParams.get('query') || '';
const sex = searchParams.get('sex') || '';
const centuries = searchParams.getAll('centuries') || '';

const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchParams(
getSearchWith(searchParams, {
query: event.target.value || null,
}),
);
};

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

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

<div className="panel-block">
Expand All @@ -21,6 +72,8 @@ export const PeopleFilters = () => {
data-cy="NameFilter"
type="search"
className="input"
value={query}
onChange={handleQueryChange}
placeholder="Search"
/>

Expand All @@ -33,63 +86,118 @@ export const PeopleFilters = () => {
<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
<a
<Link
data-cy="century"
className="button mr-1"
href="#/people?centuries=16"
className={classNames('button mr-1', {
'is-info': centuries.includes('16'),
})}
to={{
search: getSearchWith(searchParams, {
centuries: centuries.includes('16')
? centuries.filter(century => century !== '16')
: [...centuries, '16'],
}),
}}
>
16
</a>
</Link>

<a
<Link
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=17"
className={classNames('button mr-1', {
'is-info': centuries.includes('17'),
})}
to={{
search: getSearchWith(searchParams, {
centuries: centuries.includes('17')
? centuries.filter(century => century !== '17')
: [...centuries, '17'],
}),
}}
>
17
</a>
</Link>

<a
<Link
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=18"
className={classNames('button mr-1', {
'is-info': centuries.includes('18'),
})}
to={{
search: getSearchWith(searchParams, {
centuries: centuries.includes('18')
? centuries.filter(century => century !== '18')
: [...centuries, '18'],
}),
}}
>
18
</a>
</Link>

Comment on lines +135 to 136

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The sorting logic updates URL params correctly, but the actual people array is never sorted before rendering. The people prop is rendered as-is without any sorting applied. You need to implement sorting logic that reads sort and order from searchParams and sorts the array accordingly before passing it to PersonTable.

<a
<Link
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=19"
className={classNames('button mr-1', {
'is-info': centuries.includes('19'),
})}
to={{
search: getSearchWith(searchParams, {
centuries: centuries.includes('19')
? centuries.filter(century => century !== '19')
: [...centuries, '19'],
}),
}}
>
19
</a>
</Link>

<a
<Link
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
className={classNames('button mr-1', {
'is-info': centuries.includes('20'),
})}
to={{
search: getSearchWith(searchParams, {
centuries: centuries.includes('20')
? centuries.filter(century => century !== '20')
: [...centuries, '20'],
}),
}}
>
20
</a>
</Link>
</div>

<div className="level-right ml-4">
<a
<Link
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={classNames('button is-success', {
'is-outlined': centuries.length !== 0,
})}
to={{
search: getSearchWith(searchParams, {
centuries: null,
}),
}}
>
All
</a>
</Link>
</div>
</div>
</div>

<div className="panel-block">
<a className="button is-link is-outlined is-fullwidth" href="#/people">
<Link
className="button is-link is-outlined is-fullwidth"
to={{
search: getSearchWith(searchParams, {
query: null,
sex: null,
centuries: null,
}),
}}
>
Reset all filters
</a>
</Link>
</div>
</nav>
);
Expand Down
Loading
Loading