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 #1144

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
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';
import { Outlet } from 'react-router-dom';

import './App.scss';

Expand All @@ -10,9 +10,7 @@ export const App = () => {

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

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>
);
};
20 changes: 12 additions & 8 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 getLinkClass = ({ isActive }: { isActive: boolean }) =>
classNames('navbar-item', {
'has-background-grey-lighter': isActive,
});

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

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
>
<NavLink to="/people" className={getLinkClass}>
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
124 changes: 74 additions & 50 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
import { useSearchParams } from 'react-router-dom';
import cn from 'classnames';
import { SearchLink } from './SearchLink';
import { getSearchWith, SearchParams } from '../utils/searchHelper';

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

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const query = searchParams.get('query') || '';
const sex = searchParams.get('sex') || '';
const centuries = searchParams.getAll('centuries') || [];
const resetParams = {
query: null,
sex: null,
centuries: null,
};

function setSearchWith(params: SearchParams) {
const search = getSearchWith(searchParams, params);

setSearchParams(search);
}

function handleQuery(event: React.ChangeEvent<HTMLInputElement>) {
setSearchWith({ query: event.target.value });
}

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

<p className="panel-tabs" data-cy="SexFilter">
<a className="is-active" href="#/people">
<SearchLink
params={{ sex: null }}
className={cn({ 'is-active': !sex })}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>

<SearchLink
params={{ sex: 'm' }}
className={cn({ 'is-active': sex === 'm' })}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>

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

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

<span className="icon is-left">
Expand All @@ -33,63 +73,47 @@ 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>
{allAppliedCenturies.map(century => {
const isSelected = centuries.includes(century);

<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
>
20
</a>
return (
<SearchLink
key={century}
data-cy="century"
className={cn('button mr-1', { 'is-info': isSelected })}
params={{
centuries: isSelected
? centuries.filter(cent => cent !== century)
: [...centuries, century],
}}
>
{century}
</SearchLink>
);
})}
</div>

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

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

This file was deleted.

Loading