Skip to content
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
14 changes: 10 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { PeoplePage } from './components/PeoplePage';
import { PeoplePage } from './pages/PeoplePage';
import { Navbar } from './components/Navbar';

import './App.scss';
import { Navigate, Route, Routes } from 'react-router-dom';
import { HomePage } from './pages/HomePage';
import { PageNotFound } from './pages/PageNotFound';

export const App = () => {
return (
Expand All @@ -10,9 +13,12 @@ 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="/" element={<HomePage />} />
<Route path="home" element={<Navigate to="/" replace />} />
<Route path="people/:slug?" element={<PeoplePage />} />
<Route path="*" element={<PageNotFound />} />
</Routes>
</div>
</div>
</div>
Expand Down
35 changes: 28 additions & 7 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { NavLink, useLocation } from 'react-router-dom';
import classNames from 'classnames';

export const Navbar = () => {
const location = useLocation();

const peopleLink = {
pathname: '/people',
search: location.pathname.startsWith('/people') ? location.search : '',
};

return (
<nav
data-cy="nav"
Expand All @@ -8,17 +18,28 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<NavLink
className={({ isActive }) => {
return classNames('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}
to="/"
end
>
Home
</a>
</NavLink>

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
<NavLink
className={({ isActive }) =>
classNames('navbar-item', {
'has-background-grey-lighter': isActive,
})
}
to={peopleLink}
>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
95 changes: 49 additions & 46 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
export const PeopleFilters = () => {
type Props = {
handleQueryChange: (query: string) => void;
handleCenturyToggle: (century: string) => void;
handleAllCenturies: () => void;
handleSexChange: (sex: string | null) => void;
selectedCenturies: string[];
selectedSex: string | null;
};

export const PeopleFilters: React.FC<Props> = ({
handleQueryChange,
handleCenturyToggle,
handleAllCenturies,
selectedCenturies,
selectedSex,
handleSexChange,
}) => {
const CENTURIES = ['16', '17', '18', '19', '20'];

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

<p className="panel-tabs" data-cy="SexFilter">
<a className="is-active" href="#/people">
<a
className={!selectedSex ? 'is-active' : ''}
onClick={() => handleSexChange(null)}
>
All
</a>
<a className="" href="#/people?sex=m">
<a
className={selectedSex === 'm' ? 'is-active' : ''}
onClick={() => handleSexChange('m')}
>
Male
</a>
<a className="" href="#/people?sex=f">
<a
className={selectedSex === 'f' ? 'is-active' : ''}
onClick={() => handleSexChange('f')}
>
Female
</a>
</p>
Expand All @@ -22,6 +49,7 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
onChange={event => handleQueryChange(event.target.value)}
/>

<span className="icon is-left">
Expand All @@ -33,55 +61,30 @@ 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(century => (
<button
key={century}
type="button"
data-cy="century"
className={`button mr-1 ${
selectedCenturies.includes(century) ? 'is-info' : ''
}`}
onClick={() => handleCenturyToggle(century)}
>
{century}
</button>
))}
</div>

<div className="level-right ml-4">
<a
<button
type="button"
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
onClick={handleAllCenturies}
>
All
</a>
</button>
</div>
</div>
</div>
Expand Down
33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading
Loading