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

table_advansed #639

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 4 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';
import { Outlet } from 'react-router-dom';
import { NavBar } from './components/Navbar';

import './App.scss';

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

<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
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Person } from './types/Person';
import { PersonType } from './types/Person';

// eslint-disable-next-line max-len
const API_URL = 'https://mate-academy.github.io/react_people-table/api/people.json';
Expand All @@ -7,9 +7,9 @@ function wait(delay: number) {
return new Promise(resolve => setTimeout(resolve, delay));
}

export async function getPeople(): Promise<Person[]> {
export async function getPeople(): Promise<PersonType[]> {
// keep this delay for testing purpose
return wait(500)
.then(() => fetch(API_URL))
.then(response => response.json());
.then((response) => response.json());
}
5 changes: 5 additions & 0 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const HomePage = () => {
return (
<h1 className="title">Home Page</h1>
);
};
25 changes: 18 additions & 7 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export const Navbar = () => {
import classNames from 'classnames';
import { NavLink } from 'react-router-dom';

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

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

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
<NavLink
className={handleNavActive}
to="/people"
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
5 changes: 5 additions & 0 deletions src/components/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const NotFoundPage = () => {
return (
<h1 className="title">Page not found</h1>
);
};
119 changes: 70 additions & 49 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
import { useSearchParams } from 'react-router-dom';
import { ChangeEvent } from 'react';
import cn from 'classnames';
import { SearchLink } from './SearchLink';
import { getSearchWith } from '../utils/searchHelper';
import { searchENUM } from '../types/serchENUM';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const centuriesList = ['16', '17', '18', '19', '20'];

const sex = searchParams.get(searchENUM.Sex);
const centuries = searchParams.getAll(searchENUM.Centuries);
const query = searchParams.get(searchENUM.Query) || '';

function handleQuery(event: ChangeEvent<HTMLInputElement>) {
const params = (event.target.value === '')
? getSearchWith(searchParams, { query: null })
: getSearchWith(searchParams, { query: event.target.value });

setSearchParams(params);
}

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
params={{ sex: null }}
className={cn({ 'is-active': !sex })}
>
All
</SearchLink>

<SearchLink
params={{ sex: 'm' }}
className={cn({ 'is-active': sex === 'm' })}
>
Male
</SearchLink>

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

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

<span className="icon is-left">
<i className="fas fa-search" aria-hidden="true" />
</span>
</p>
</div>

<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>
{centuriesList.map(century => (
<SearchLink
key={century}
params={{
centuries: centuries.includes(century)
? centuries.filter(c => c !== century)
: [...centuries, century],
}}
className={cn('button mr-1', {
'is-info': centuries.includes(century),
})}
>
{century}
</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
<SearchLink
className="button is-link is-outlined is-fullwidth"
href="#/people"
params={{
sex: null,
query: null,
centuries: null,
}}
>
Reset all filters
</a>
</SearchLink>

</div>
</nav>
);
Expand Down
Loading
Loading