Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #487

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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://Vayts.github.io/react_people-table-advanced/) and add it to the PR description.
21 changes: 16 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { PeoplePage } from './components/PeoplePage';
import { Navigate, Route, Routes } from 'react-router-dom';
import { Navbar } from './components/Navbar';

import './App.scss';
import { HomePage } from './pages/HomePage';
import { NothingFound } from './pages/NotFind';
import { PeoplePage } from './pages/PeoplePage';

export const App = () => {
return (
Expand All @@ -10,9 +12,18 @@ 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="/home" element={<Navigate to="/" replace />} />
<Route path="/" element={<HomePage />} />
<Route path="people">
<Route index element={<PeoplePage />} />
<Route path=":userSlug" element={<PeoplePage />} />
</Route>
<Route
path="*"
element={<NothingFound />}
/>
</Routes>
</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 classNames from 'classnames';

const linkClassName = ({ isActive }: { isActive: boolean }) => classNames(
'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={linkClassName}
to="/"
>
Home
</NavLink>

<a
<NavLink
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
className={linkClassName}
to="/people"
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
129 changes: 80 additions & 49 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
export const PeopleFilters = () => {
import React from 'react';
import classNames from 'classnames';
import { SexFilter } from '../types/SexFilter';
import { SearchLink } from './SearchLink';

type Props = {
sex: string,
query: string,
centuries: string[],
handleQuery: (query: React.ChangeEvent<HTMLInputElement>) => void,
handleSexFilter: (sex: SexFilter) => void,
};

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

export const PeopleFilters: React.FC<Props> = ({
sex,
query,
centuries,
handleQuery,
handleSexFilter,
}) => {
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={classNames({
'is-active': sex === SexFilter.All,
})}
params={{ sex: null }}
onClick={() => handleSexFilter(SexFilter.All)}
>
All
</SearchLink>
<SearchLink
className={classNames({
'is-active': sex === SexFilter.Male,
})}
params={{ sex: SexFilter.Male }}
onClick={() => SexFilter.Male}
>
Male
</SearchLink>
<SearchLink
className={classNames({
'is-active': sex === SexFilter.Female,
})}
params={{ sex: SexFilter.Female }}
onClick={() => SexFilter.Female}
>
Female
</SearchLink>
</p>

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

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

<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>
</div>

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

<div className="panel-block">
<a
<SearchLink
className="button is-link is-outlined is-fullwidth"
href="#/people"
params={{
centuries: null,
query: null,
sex: null,
}}
>
Reset all filters
</a>
</SearchLink>
</div>
</nav>
);
Expand Down
35 changes: 0 additions & 35 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading