-
Notifications
You must be signed in to change notification settings - Fork 1.9k
task solution #1820
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
base: master
Are you sure you want to change the base?
task solution #1820
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export const HomePage = () => { | ||
| return ( | ||
| <div className="container"> | ||
| <h1 className="title">Home Page</h1> | ||
| </div> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const NotFoundPage = () => <h1 className="title">Page not found</h1>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,58 @@ | ||
| import { useSearchParams } from 'react-router-dom'; | ||
| import React from 'react'; | ||
| import { SearchLink } from './SearchLink'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| export const PeopleFilters = () => { | ||
| const [searchParams, setSearchParams] = useSearchParams(); | ||
|
|
||
| const query = searchParams.get('query') || ''; | ||
| const centuries = searchParams.getAll('centuries') || []; | ||
| const sex = searchParams.get('sex'); | ||
| const allCenturies = ['16', '17', '18', '19', '20']; | ||
|
|
||
| function handleQueryChange(event: React.ChangeEvent<HTMLInputElement>) { | ||
| const params = new URLSearchParams(searchParams); | ||
| const value = event.target.value; | ||
|
|
||
| if (value) { | ||
| params.set('query', value); | ||
| } else { | ||
| params.delete('query'); | ||
| } | ||
|
|
||
| setSearchParams(params); | ||
|
Comment on lines
+14
to
+24
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 name filter handler correctly updates the |
||
| } | ||
|
|
||
| function getToggledCenturies(century: string) { | ||
| return centuries.includes(century) | ||
|
Comment on lines
+19
to
+28
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.
|
||
| ? centuries.filter(c => c !== century) | ||
| : [...centuries, century]; | ||
| } | ||
|
|
||
| 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"> | ||
|
|
@@ -22,6 +62,8 @@ export const PeopleFilters = () => { | |
| type="search" | ||
| className="input" | ||
| placeholder="Search" | ||
| value={query} | ||
| onChange={handleQueryChange} | ||
| /> | ||
|
|
||
| <span className="icon is-left"> | ||
|
|
@@ -33,63 +75,50 @@ 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> | ||
| {allCenturies.map(century => ( | ||
| <SearchLink | ||
| key={century} | ||
| data-cy={century} | ||
| params={{ | ||
| centuries: getToggledCenturies(century), | ||
| }} | ||
| className={classNames('button mr-1', { | ||
| 'is-info': centuries.includes(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-info': !centuries.length, | ||
| 'is-outlined': centuries.length, | ||
| })} | ||
| > | ||
| All | ||
| </a> | ||
| </SearchLink> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="panel-block"> | ||
| <a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
| <SearchLink | ||
| params={{ | ||
| query: null, | ||
| sex: null, | ||
| centuries: null, | ||
| sort: null, | ||
| order: null, | ||
| }} | ||
| className="button is-link is-outlined is-fullwidth" | ||
| > | ||
| Reset all filters | ||
| </a> | ||
| </SearchLink> | ||
| </div> | ||
| </nav> | ||
| ); | ||
|
|
||
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.
PersonLinkuses a plainNavLinkto/people/${person.slug}and does not preserve existing search params, so filters and sorting are lost when selecting a person. The requirements state that search params must be kept when navigating within the People page; consider usingSearchLinkor otherwise including the currentlocation.searchin the destination URL.