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

commit solution #517

Open
wants to merge 3 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
17 changes: 13 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { PeoplePage } from './components/PeoplePage';
import { Navigate, Route, Routes } from 'react-router-dom';
import { PeoplePage } from './pages/PeoplePage';
import { Navbar } from './components/Navbar';
import { HomePage } from './pages/HomePage';
import { ErrorPage } from './pages/ErrorPage';

import './App.scss';

Expand All @@ -10,9 +13,15 @@ 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">
<Route index element={<PeoplePage />} />
<Route path=":slug" element={<PeoplePage />} />
</Route>
<Route path="*" element={<ErrorPage />} />
</Routes>
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/components/ErrorLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const ErrorLoading: React.FC = () => (
<p data-cy="peopleLoadingError" className="has-text-danger">
Something went wrong
</p>
);
24 changes: 0 additions & 24 deletions src/components/Navbar.tsx

This file was deleted.

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

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

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 to="/" className={handleClassName}>Home</NavLink>
<NavLink to="/people" className={handleClassName}>People</NavLink>
</div>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/Navbar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Navbar';
5 changes: 5 additions & 0 deletions src/components/NoPeople.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const NoPeople: React.FC = () => (
<p data-cy="noPeopleMessage">
There are no people on the server
</p>
);
93 changes: 0 additions & 93 deletions src/components/PeopleFilters.tsx

This file was deleted.

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

const centuriesButton = ['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 handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const search = getSearchWith(
searchParams,
{ query: event.target.value.trim() || null },
);

setSearchParams(search);
};

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={handleQueryChange}
/>

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

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

<div className="panel-block">
<SearchLink
className="button is-link is-outlined is-fullwidth"
params={{
centuries: null,
sex: null,
query: null,
}}
>
Reset all filters
</SearchLink>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/PeopleFilters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PeopleFilters';
35 changes: 0 additions & 35 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading