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

first solution #615

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
15 changes: 6 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

import { Outlet } from 'react-router-dom';
import './App.scss';

import { Navbar } from './components/Navbar';

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

<div className="section">
<main className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<Outlet />
</div>
</div>
</main>
</div>
);
};
27 changes: 20 additions & 7 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export const Navbar = () => {
import React from 'react';
import { NavLink } from 'react-router-dom';
import cn from 'classnames';

export const Navbar: React.FC = () => {
const isActiveClass = ({ isActive }: { isActive: boolean }) => cn(
'navbar-item',
{ 'has-background-grey-lighter': isActive },
);

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

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
<NavLink
to="/people"
className={isActiveClass}
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
119 changes: 65 additions & 54 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,61 @@
export const PeopleFilters = () => {
import React, { ChangeEvent } from 'react';
import classNames from 'classnames';
import { useSearchParams } from 'react-router-dom';

import { SearchLink } from './SearchLink';
import { getSearchWith } from '../utils/searchHelper';

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

export const PeopleFilters: React.FC = () => {
const [searchParams, setSearchParams] = useSearchParams();

const params = {
query: searchParams.get('query') || '',
centuries: searchParams.getAll('century'),
sex: searchParams.get('sex'),
};

const handleQueryChange = (event: ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;

setSearchParams(getSearchWith(searchParams, { query: value || null }));
};

const renderSexFilter = (sex: string | null, label: string) => (
<SearchLink
className={classNames({ 'is-active': params.sex === sex })}
params={{ sex }}
>
{label}
</SearchLink>
);

const renderCenturyFilter = (century: number) => (
<SearchLink
key={century}
className={classNames('button mr-1', {
'is-info': params.centuries.includes(century.toString()),
})}
params={{
century: params.centuries.includes(century.toString())
? params.centuries.filter((paramsCentury) => century.toString()
!== paramsCentury)
: [...params.centuries, century.toString()],
}}
>
{century}
</SearchLink>
);

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>
{renderSexFilter(null, 'All')}
{renderSexFilter('m', 'Male')}

Choose a reason for hiding this comment

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

Something went wrong with their styles, check it

{renderSexFilter('f', 'Female')}
</p>

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

<span className="icon is-left">
<i className="fas fa-search" aria-hidden="true" />
</span>
Expand All @@ -26,67 +76,28 @@ 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>
</div>

<div className="level-left">{centuries.map(renderCenturyFilter)}</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': params.centuries.length !== 0,
})}
params={{ century: null }}
>
All
</a>
</SearchLink>
</div>
</div>
</div>

<div className="panel-block">
<a
<SearchLink
className="button is-link is-outlined is-fullwidth"
href="#/people"
params={{ century: null, sex: null, query: 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
Loading