-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Develop #1178
base: master
Are you sure you want to change the base?
Develop #1178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { Navbar } from './components/Navbar'; | ||
|
||
import './App.scss'; | ||
import { Outlet } from 'react-router-dom'; | ||
import { Navbar } from './components/Navbar'; | ||
|
||
export const App = () => { | ||
return ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
|
||
<div className="section"> | ||
<main className="section"> | ||
<div className="container"> | ||
<h1 className="title">Home Page</h1> | ||
<h1 className="title">Page not found</h1> | ||
<PeoplePage /> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
</main> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
HashRouter as Router, | ||
Navigate, | ||
Route, | ||
Routes, | ||
} from 'react-router-dom'; | ||
import { App } from './App'; | ||
import { HomePage } from './pages/HomePage'; | ||
import { NotFoundPage } from './pages/NotFoundPage'; | ||
import { PeoplePage } from './pages/PeoplePage'; | ||
|
||
export const Root = () => { | ||
return ( | ||
<Router> | ||
<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={<NotFoundPage />} /> | ||
</Route> | ||
</Routes> | ||
</Router> | ||
); | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NavLink, useSearchParams } from 'react-router-dom'; | ||
import cn from 'classnames'; | ||
|
||
const getLinkClass = ({ isActive }: { isActive: boolean }) => | ||
cn('navbar-item', { 'has-background-grey-lighter': isActive }); | ||
|
||
export const Navbar = () => { | ||
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() }} | ||
className={getLinkClass} | ||
> | ||
People | ||
</NavLink> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Navbar'; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { useSearchParams } from 'react-router-dom'; | ||
import cn from 'classnames'; | ||
import { SearchLink } from '../SearchLink'; | ||
import { getSearchWith, SearchParams } from '../../utils/searchHelper'; | ||
import { CENTURIES, PersonSex } from '../../utils/filters'; | ||
|
||
export const PeopleFilters = () => { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const query = searchParams.get('query') || ''; | ||
const sex = searchParams.get('sex'); | ||
const centuries = searchParams.getAll('centuries'); | ||
|
||
function setSearchWith(params: SearchParams) { | ||
const search = getSearchWith(searchParams, params); | ||
|
||
setSearchParams(search); | ||
} | ||
|
||
return ( | ||
<nav className="panel"> | ||
<p className="panel-heading">Filters</p> | ||
|
||
<p className="panel-tabs" data-cy="SexFilter"> | ||
{Object.values(PersonSex).map(sexFilter => { | ||
const sexValue = sexFilter.charAt(0); | ||
const filterTitle = sexValue.toUpperCase() + sexFilter.slice(1); | ||
|
||
return ( | ||
<SearchLink | ||
params={{ sex: sexFilter === PersonSex.All ? null : sexValue }} | ||
key={sexFilter} | ||
className={cn({ | ||
'is-active': | ||
sex === sexValue || | ||
(sex === null && sexFilter === PersonSex.All), | ||
})} | ||
> | ||
{filterTitle} | ||
</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={event => { | ||
setSearchWith({ query: event.target.value || null }); | ||
}} | ||
/> | ||
|
||
<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 => { | ||
const currentCenturies = centuries.includes(century) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is too much code here. I believe it would make sense to move some part of it to a separate function. To be more specific, the part where you filter your centuries array. |
||
? centuries.filter(current => century !== current) | ||
: [...centuries, century]; | ||
|
||
return ( | ||
<SearchLink | ||
params={{ centuries: currentCenturies }} | ||
key={century} | ||
data-cy="century" | ||
className={cn('button mr-1', { | ||
'is-info': centuries.includes(century), | ||
})} | ||
> | ||
{century} | ||
</SearchLink> | ||
); | ||
})} | ||
</div> | ||
|
||
<div className="level-right ml-4"> | ||
<SearchLink | ||
params={{ centuries: null }} | ||
data-cy="centuryALL" | ||
className={cn('button is-success', { | ||
'is-outlined': centuries.length, | ||
})} | ||
> | ||
All | ||
</SearchLink> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<SearchLink | ||
className="button is-link is-outlined is-fullwidth" | ||
params={{ query: null, sex: null, centuries: null }} | ||
> | ||
Reset all filters | ||
</SearchLink> | ||
</div> | ||
</nav> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PeopleFilters'; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not a big deal, but you could create an enum Sex { All = '', Female = 'f', Male = 'm' } and use Object.keys() to create the same tabs from the example. A key would play a role of tab's title (All. Female. Male) and key's value would be a search parameter ('', 'f', 'm').