-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
solution #1133
base: master
Are you sure you want to change the base?
solution #1133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
export const PeopleFilters = () => { | ||
import React from 'react'; | ||
import { SearchLink } from './SearchLink'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import classNames from 'classnames'; | ||
|
||
const centuriesValue: string[] = ['16', '17', '18', '19', '20']; | ||
|
||
export const PeopleFilters: React.FC = () => { | ||
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, | ||
}; | ||
|
||
Comment on lines
+13
to
+17
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. The |
||
const isActiveSex = (value: string | null) => { | ||
return value === sex; | ||
}; | ||
|
||
const getCenturies = (century: string) => { | ||
return centuries.includes(century) | ||
? centuries.filter(currentCentury => currentCentury !== century) | ||
: [...centuries, century]; | ||
}; | ||
|
||
function handleQueryChange(event: React.ChangeEvent<HTMLInputElement>) { | ||
const params = new URLSearchParams(searchParams); | ||
|
||
params.set('query', event.target.value); | ||
setSearchParams(params); | ||
} | ||
|
||
return ( | ||
<nav className="panel"> | ||
<p className="panel-heading">Filters</p> | ||
|
||
<p className="panel-tabs" data-cy="SexFilter"> | ||
<a className="is-active" href="#/people"> | ||
<SearchLink | ||
className={classNames({ 'is-active': isActiveSex(null) })} | ||
params={{ sex: null }} | ||
> | ||
All | ||
</a> | ||
<a className="" href="#/people?sex=m"> | ||
</SearchLink> | ||
<SearchLink | ||
className={classNames({ 'is-active': isActiveSex('m') })} | ||
params={{ sex: 'm' }} | ||
> | ||
Male | ||
</a> | ||
<a className="" href="#/people?sex=f"> | ||
</SearchLink> | ||
<SearchLink | ||
className={classNames({ 'is-active': isActiveSex('f') })} | ||
params={{ sex: 'f' }} | ||
> | ||
Female | ||
</a> | ||
</SearchLink> | ||
</p> | ||
|
||
<div className="panel-block"> | ||
|
@@ -22,6 +65,8 @@ export const PeopleFilters = () => { | |
type="search" | ||
className="input" | ||
placeholder="Search" | ||
value={query} | ||
onChange={handleQueryChange} | ||
/> | ||
|
||
<span className="icon is-left"> | ||
|
@@ -33,63 +78,43 @@ 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> | ||
{centuriesValue.map(century => { | ||
return ( | ||
<SearchLink | ||
key={century} | ||
data-cy="century" | ||
className={classNames('button mr-1', { | ||
'is-info': centuries.includes(century), | ||
})} | ||
params={{ centuries: getCenturies(century) }} | ||
> | ||
{century} | ||
</SearchLink> | ||
); | ||
})} | ||
</div> | ||
|
||
<div className="level-right ml-4"> | ||
<a | ||
<SearchLink | ||
data-cy="centuryALL" | ||
className="button is-success is-outlined" | ||
href="#/people" | ||
className={classNames('button is-success', { | ||
'is-outlined': centuries.length > 0, | ||
})} | ||
params={{ centuries: null }} | ||
> | ||
All | ||
</a> | ||
</SearchLink> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
<SearchLink | ||
className="button is-link is-outlined is-fullwidth" | ||
params={resetParams} | ||
> | ||
Reset all filters | ||
</a> | ||
</SearchLink> | ||
</div> | ||
</nav> | ||
); | ||
|
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.
The nested route for
PeoplePage
is defined, but it might be worth checking if thePeoplePage
component is designed to handle both the base path/people
and the nested:slug
path. IfPeoplePage
is not intended to handle both, consider creating a separate component for the nested route.