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

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
17 changes: 10 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

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

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 />
</div>
</div>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/home" element={<Navigate to={'/'} replace={true} />} />
<Route path="/people" element={<PeoplePage />} />
<Route path="/people/:slug" element={<PeoplePage />} />
<Route path="*" element={<PageNotFound />} />
</Routes>
</div>
);
};
7 changes: 7 additions & 0 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const Home = () => (
<main className="section">
<div className="container">
<h1 className="title">Home Page</h1>
</div>
</main>
);
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 className={getLinkClass} to="/">
Home
</a>
</NavLink>

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
>
<NavLink className={getLinkClass} to="/people">
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
9 changes: 9 additions & 0 deletions src/components/PageNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const PageNotFound = () => (
<>
<div className="section">
<div className="container">
<h1 className="title">Page not found</h1>
</div>
</div>
</>
);
108 changes: 58 additions & 50 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
import { useSearchParams } from 'react-router-dom';
import { ChangeEvent } from 'react';
import { getSearchWith, SearchParams } from '../utils/searchHelper';
import { SearchLink } from './SearchLink';
import classNames from 'classnames';

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

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

setSearchParams(search);
}

const handleSearchChange = (event: ChangeEvent<HTMLInputElement>) => {
setSearchWith({ search: event.target.value || null });
};

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={classNames({ 'is-active': !sex })}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>
<SearchLink
params={{ sex: 'm' }}
className={classNames({ 'is-active': sex === 'm' })}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>
<SearchLink
params={{ sex: 'f' }}
className={classNames({ 'is-active': sex === 'f' })}
>
Female
</a>
</SearchLink>
</p>

<div className="panel-block">
Expand All @@ -22,6 +51,7 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
onChange={event => handleSearchChange(event)}
/>

<span className="icon is-left">
Expand All @@ -33,55 +63,33 @@ 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>
{[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">
<a
<SearchLink
params={{ centuries: null }}
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={classNames('button is-success', {
'is-outlined': centuries.length > 0,
})}
>
All
</a>
</SearchLink>
</div>
</div>
</div>
Expand Down
9 changes: 0 additions & 9 deletions src/components/PeoplePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PeopleFilters } from './PeopleFilters';
import { Loader } from './Loader';
import { PeopleTable } from './PeopleTable';

export const PeoplePage = () => {
Expand All @@ -15,14 +14,6 @@ export const PeoplePage = () => {

<div className="column">
<div className="box table-container">
<Loader />

<p data-cy="peopleLoadingError">Something went wrong</p>

<p data-cy="noPeopleMessage">There are no people on the server</p>

<p>There are no people matching the current search criteria</p>

<PeopleTable />
</div>
</div>
Expand Down
Loading
Loading