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://ihorshtoiko.github.io/react_people-table-advanced/) and add it to the PR description.
9 changes: 5 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react_people-table-advanced",
"homepage": "react_people-table-advanced",
"homepage": "https://ihorshtoiko.github.io/react_people-table-advanced/",
"version": "0.1.0",
"keywords": [],
"author": "Mate Academy",
Expand All @@ -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",
Expand Down
33 changes: 17 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { PeoplePage } from './components/PeoplePage';
import { Route, Routes, Navigate } from 'react-router-dom';
import { Navbar } from './components/Navbar';

import { PeoplePage } from './components/PeoplePage';
import './App.scss';

export const App = () => {
return (
<div data-cy="app">
<Navbar />

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
</div>
export const App = () => (
<div data-cy="app">
<Navbar />
<main className="section">
<div className="container">
<Routes>
<Route path="/" element={<h1 className="title">Home Page</h1>} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="/people" element={<PeoplePage />} />
<Route path="/people/:slug" element={<PeoplePage />} />
<Route path="*" element={<h1 className="title">Page not found</h1>} />
</Routes>
</div>
</div>
);
};
</main>
</div>
);
21 changes: 15 additions & 6 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { NavLink } from 'react-router-dom';

export const Navbar = () => {
return (
<nav
Expand All @@ -8,17 +10,24 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<NavLink
className={({ isActive }) =>
`navbar-item ${isActive ? 'has-background-grey-lighter' : ''}`
}
to="/"
>
Home
</a>
</NavLink>

<a
<NavLink
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
className={({ isActive }) =>
`navbar-item ${isActive ? 'has-background-grey-lighter' : ''}`
}
to="/people"
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
118 changes: 87 additions & 31 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import { useSearchParams } from 'react-router-dom';
import { getSearchWith } from '../utils/searchHelper';
import { SearchLink } from './SearchLink';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();

const query = searchParams.get('query') ?? '';
const sex = searchParams.get('sex');
const century = searchParams.getAll('centuries');

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={sex === null ? 'is-active' : ''}
params={{ sex: null }}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>
<SearchLink
className={sex === 'm' ? 'is-active' : ''}
params={{ sex: 'm' }}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>
<SearchLink
className={sex === 'f' ? 'is-active' : ''}
params={{ sex: 'f' }}
>
Female
</a>
</SearchLink>
</p>

<div className="panel-block">
Expand All @@ -22,6 +41,14 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
value={query}
onChange={e =>
setSearchParams(
getSearchWith(searchParams, {
query: e.target.value || null,
}),
)
}
/>

<span className="icon is-left">
Expand All @@ -33,63 +60,92 @@ export const PeopleFilters = () => {
<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
<a
<SearchLink
data-cy="century"
className="button mr-1"
href="#/people?centuries=16"
className={`button mr-1 ${century.includes('16') ? 'is-info' : ''}`}
params={{
centuries: century.includes('16')
? century.filter(c => c !== '16')
: [...century, '16'],
}}

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 sidebar should only appear when people are loaded. Currently PeopleFilters renders unconditionally. Consider adding a condition to only show the sidebar when !isLoading && people.length > 0.

>
16
</a>
</SearchLink>

<a
<SearchLink
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=17"
className={`button mr-1 ${century.includes('17') ? 'is-info' : ''}`}
params={{
centuries: century.includes('17')
? century.filter(c => c !== '17')
: [...century, '17'],
}}
>
17
</a>
</SearchLink>

<a
<SearchLink
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=18"
className={`button mr-1 ${century.includes('18') ? 'is-info' : ''}`}
params={{
centuries: century.includes('18')
? century.filter(c => c !== '18')
: [...century, '18'],
}}
>
18
</a>
</SearchLink>

<a
<SearchLink
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=19"
className={`button mr-1 ${century.includes('19') ? 'is-info' : ''}`}
params={{
centuries: century.includes('19')
? century.filter(c => c !== '19')
: [...century, '19'],
}}
>
19
</a>
</SearchLink>

<a
<SearchLink
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
className={`button mr-1 ${century.includes('20') ? 'is-info' : ''}`}
params={{
centuries: century.includes('20')
? century.filter(c => c !== '20')
: [...century, '20'],
}}
>
20
</a>
</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">
<SearchLink
className="button is-link is-outlined is-fullwidth"
params={{
query: null,
sex: null,
centuries: null,
sort: null,
order: null,
}}
>
Reset all filters
</a>
</SearchLink>
</div>
</nav>
);
Expand Down
Loading
Loading