Skip to content

Commit

Permalink
add people table solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuper18 committed Nov 22, 2023
1 parent 0eb1677 commit 7070ee5
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 738 deletions.
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://Kuper18.github.io/react_people-table-advanced/) and add it to the PR description.
7 changes: 3 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PeoplePage } from './components/PeoplePage';
// import { PeoplePage } from './components/PeoplePage';
import { Outlet } from 'react-router-dom';
import { Navbar } from './components/Navbar';

import './App.scss';
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
23 changes: 18 additions & 5 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { NavLink } from 'react-router-dom';
import cn from 'classnames';
import { ActiveParams } from '../types/ActiveParams';

const getClassLink = ({ isActive }: ActiveParams) => {
return cn('navbar-item', { 'has-background-grey-lighter': isActive });
};

export const Navbar = () => {
return (
<nav
Expand All @@ -8,15 +16,20 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">Home</a>
<NavLink
className={getClassLink}
to="/"
>
Home
</NavLink>

<a
<NavLink
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
className={getClassLink}
to="/people"
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
115 changes: 65 additions & 50 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
import { useSearchParams } from 'react-router-dom';
import cn from 'classnames';
import { SearchLink } from './SearchLink';
import { getSearchWith } from '../utils/searchHelper';

const centuries = ['16', '17', '18', '19', '20'];

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const centuriesUrl = searchParams.getAll('centuries') || [];
const query = searchParams.get('query') || '';

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

setSearchParams(search);
};

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

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

<SearchLink
className={cn({ 'is-active': searchParams.get('sex') === 'm' })}
params={{ sex: 'm' }}
>
Male
</SearchLink>
<SearchLink
className={cn({ 'is-active': searchParams.get('sex') === 'f' })}
params={{ sex: 'f' }}
>
Female
</SearchLink>
</p>

<div className="panel-block">
Expand All @@ -16,6 +51,8 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
value={query}
onChange={handleChangeQuery}
/>

<span className="icon is-left">
Expand All @@ -27,66 +64,44 @@ 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>
{centuries.map(item => (
<SearchLink
key={item}
data-cy="century"
className={cn('button mr-1', {
'is-info': centuriesUrl.includes(item),
})}
params={{
centuries: centuriesUrl.includes(item)
? centuriesUrl.filter(century => century !== item)
: [...centuriesUrl, item],
}}
>
{item}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<a
<SearchLink
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={cn('button is-success',
{ 'is-outlined': searchParams.get('centuries') })}
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={cn('button is-link is-outlined is-fullwidth')}
params={{ centuries: null, sex: null, query: null }}
>
Reset all filters
</a>
</SearchLink>
</div>
</nav>
);
Expand Down
Loading

0 comments on commit 7070ee5

Please sign in to comment.