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

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

export const Root = () => (
<Router>
<Routes>
<Route path="/" element={<App />}>
<Route index 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={<NotFoundPage />} />
</Route>
</Routes>
</Router>
);
26 changes: 0 additions & 26 deletions src/components/Navbar.tsx

This file was deleted.

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

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

const [searchParams] = useSearchParams();

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={getLinkClass}>
Home
</NavLink>

<NavLink
to={{
pathname: '/people',
search: searchParams.toString(),
}}
aria-current="page"
className={getLinkClass}
>
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';
112 changes: 112 additions & 0 deletions src/components/PeopleFilter/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { ChangeEvent } from 'react';
import { useSearchParams } from 'react-router-dom';
import classNames from 'classnames';
import { SearchLink } from '../SearchLink';
import { getSearchWith } from '../../utils/searchHelper';
import { CENTURIES } from '../../constants/centuries';

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

setSearchParams(search);
};
Comment on lines +20 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The People NavLink always navigates to /people without preserving search params. Per requirement #2, search params should be kept when navigating within the People page (when clicking the People link). Consider using useSearchParams to append current search params to the link.


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

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

<SearchLink
className={classNames({ 'is-active': sex === 'm' })}
params={{ sex: 'm' }}
>
Male
</SearchLink>

<SearchLink
className={classNames({ 'is-active': sex === 'f' })}
params={{ 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">
{CENTURIES.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(num => century !== num)
: [...centuries, century],
}}
Comment on lines +76 to +81

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The century filter removes centuries from the array when clicked again (line 78). According to the requirements, it should use the append method. Consider using URLSearchParams append method instead of rebuilding the array to properly handle multiple centuries selection.

>
{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={{ query: null, centuries: null, sex: null }}
>
Reset all filters
</SearchLink>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/PeopleFilter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PeopleFilters';
96 changes: 0 additions & 96 deletions src/components/PeopleFilters.tsx

This file was deleted.

33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading
Loading