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

Solution #1138

Open
wants to merge 1 commit 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
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 './App.scss';

import { Outlet } from 'react-router-dom';
import { Navbar } from './components/Navbar/Navbar';

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 />
<Outlet />
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HashRouter, Navigate, Route, Routes } from 'react-router-dom';
import { PeoplePage } from './pages/PeoplePage';
import { NotFound } from './pages/NotFound';
import { HomePage } from './pages/HomePage';
import { App } from './App';

export const Root = () => {
return (
<HashRouter>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<HomePage />} />
<Route path="/home" element={<Navigate replace to="/" />} />
<Route path="/people">
<Route index element={<PeoplePage />} />
<Route path=":slug?" element={<PeoplePage />} />
</Route>
<Route path="*" element={<NotFound />} />
</Route>
</Routes>
</HashRouter>
);
};
26 changes: 0 additions & 26 deletions src/components/Navbar.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import classNames from 'classnames';
import { NavLink } from 'react-router-dom';

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

export const Navbar = () => {
return (
<nav
data-cy="nav"
className="navbar is-fixed-top has-shadow"
role="navigation"
aria-label="main navigation"
>
<div className="container">
<div className="navbar-brand">
<NavLink className={getLinkStyle} to="/">
Home
</NavLink>

<NavLink className={getLinkStyle} to="/people">
People
</NavLink>
</div>
</div>
</nav>
);
};
96 changes: 0 additions & 96 deletions src/components/PeopleFilters.tsx

This file was deleted.

113 changes: 113 additions & 0 deletions src/components/PeopleFilters/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { useSearchParams } from 'react-router-dom';
import { SearchLink } from '../SearchLink/SearchLink';
import classNames from 'classnames';

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

const sex = searchParams.get('sex') || null;
const centuries = searchParams.getAll('centuries') || [];
const query = searchParams.get('query') || '';

const resetFilters = {
sex: null,
centuries: null,
query: null,
};

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

<p className="panel-tabs" data-cy="SexFilter">
<SearchLink
params={{ sex: null }}
className={classNames({ 'is-active': !sex })}
>
All
</SearchLink>
<SearchLink
params={{ sex: 'm' }}
className={classNames({ 'is-active': sex === 'm' })}
>
Male
</SearchLink>
<SearchLink
params={{ sex: 'f' }}
className={classNames({ 'is-active': sex === 'f' })}
>
Female
</SearchLink>
</p>

<div className="panel-block">
<p className="control has-icons-left">
<input
data-cy="NameFilter"
type="search"
className="input"
placeholder="Search"
value={query || ''}
onChange={e =>
setSearchParams(
{
...Object.fromEntries(searchParams.entries()),
query: e.target.value || '',
},
{ replace: true },
)
}
/>

<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">
{[16, 17, 18, 19, 20].map(century => (
<SearchLink
key={century}
params={{
centuries: centuries.includes(century.toString())
? centuries.filter(c => c !== century.toString())
: [...centuries, century.toString()],
}}
className={classNames('button mr-1', {
'is-info': centuries.includes(century.toString()),
})}
data-cy="century"
>
{century}
</SearchLink>
))}
</div>

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

<div className="panel-block">
<SearchLink
params={resetFilters}
className="button is-link is-outlined is-fullwidth"
>
Reset all filters
</SearchLink>
</div>
</nav>
);
};
33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading
Loading