-
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 #1051
base: master
Are you sure you want to change the base?
Solution #1051
Changes from 2 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
HashRouter as Router, | ||
Routes, | ||
Route, | ||
Navigate, | ||
} from 'react-router-dom'; | ||
|
||
import { App } from './App'; | ||
// eslint-disable-next-line import/extensions | ||
import { PageNotFound } from './page/PageNotFound'; | ||
import { HomePageTitle } from './page/HomePageTitle'; | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { Routes as AppRoutes } from './enum/routes.enum'; | ||
|
||
export const Root = () => { | ||
return ( | ||
<Router> | ||
<Routes> | ||
<Route path={AppRoutes.Home} element={<App />}> | ||
<Route path={AppRoutes.PageNotFound} element={<PageNotFound />} /> | ||
|
||
<Route index element={<HomePageTitle />} /> | ||
|
||
<Route path={AppRoutes.People}> | ||
<Route path={AppRoutes.PeopleWithSlug} element={<PeoplePage />} /> | ||
</Route> | ||
|
||
<Route path={AppRoutes.HomeRedirect} element={<Navigate to={AppRoutes.Home} replace />} /> | ||
</Route> | ||
</Routes> | ||
</Router> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,17 +1,93 @@ | ||||||||||
export const PeopleFilters = () => { | ||||||||||
import cn from 'classnames'; | ||||||||||
|
||||||||||
import { SearchLink } from './SearchLink'; | ||||||||||
// eslint-disable-next-line import/extensions | ||||||||||
import { FilterBy } from '../types/FilterBy'; | ||||||||||
import { useEffect, useState } from 'react'; | ||||||||||
|
||||||||||
type PeopleFilterProps = { | ||||||||||
searchParams: URLSearchParams; | ||||||||||
setQuery: React.Dispatch<React.SetStateAction<string>>; | ||||||||||
setSearchParams: React.Dispatch<React.SetStateAction<URLSearchParams>>; | ||||||||||
activeQuery: string; | ||||||||||
toggleCenturies: (currentCentury: number) => string[]; | ||||||||||
activeCenturies: string[]; | ||||||||||
}; | ||||||||||
|
||||||||||
export const PeopleFilters = ({ | ||||||||||
toggleCenturies, | ||||||||||
searchParams, | ||||||||||
setQuery, | ||||||||||
activeQuery, | ||||||||||
setSearchParams, | ||||||||||
activeCenturies, | ||||||||||
}: PeopleFilterProps) => { | ||||||||||
const [activeFilter, setActiveFilter] = useState(''); | ||||||||||
const centuryList = [16, 17, 18, 19, 20]; | ||||||||||
|
||||||||||
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. move it to |
||||||||||
useEffect(() => { | ||||||||||
setActiveFilter(searchParams.get('sex') || ''); | ||||||||||
setQuery(searchParams.get('query') || ''); | ||||||||||
}, [searchParams, setQuery]); | ||||||||||
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. you have the
Suggested change
|
||||||||||
|
||||||||||
const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||
const newSearchParams = new URLSearchParams(searchParams); | ||||||||||
|
||||||||||
if (!event.target.value) { | ||||||||||
newSearchParams.delete('query'); | ||||||||||
} else { | ||||||||||
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. use
Suggested change
|
||||||||||
newSearchParams.set('query', event.target.value); | ||||||||||
} | ||||||||||
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 same here, use enum |
||||||||||
|
||||||||||
setSearchParams(newSearchParams); | ||||||||||
}; | ||||||||||
|
||||||||||
const resetAllFilters = () => { | ||||||||||
setQuery(''); | ||||||||||
setActiveFilter(''); | ||||||||||
setSearchParams(new URLSearchParams()); | ||||||||||
}; | ||||||||||
|
||||||||||
return ( | ||||||||||
<nav className="panel"> | ||||||||||
<p className="panel-heading">Filters</p> | ||||||||||
|
||||||||||
<p className="panel-tabs" data-cy="SexFilter"> | ||||||||||
<a className="is-active" href="#/people"> | ||||||||||
All | ||||||||||
<a | ||||||||||
className={cn({ 'is-active': activeFilter === '' })} | ||||||||||
href="#" | ||||||||||
onClick={e => { | ||||||||||
e.preventDefault(); | ||||||||||
const newSearchParams = new URLSearchParams(searchParams); | ||||||||||
newSearchParams.delete('sex'); | ||||||||||
setSearchParams(newSearchParams); | ||||||||||
}} | ||||||||||
> | ||||||||||
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. use separate functions whenever u need a |
||||||||||
{FilterBy.All} | ||||||||||
</a> | ||||||||||
<a className="" href="#/people?sex=m"> | ||||||||||
Male | ||||||||||
<a | ||||||||||
className={cn({ 'is-active': activeFilter === 'm' })} | ||||||||||
href="#" | ||||||||||
onClick={e => { | ||||||||||
e.preventDefault(); | ||||||||||
const newSearchParams = new URLSearchParams(searchParams); | ||||||||||
newSearchParams.set('sex', 'm'); | ||||||||||
setSearchParams(newSearchParams); | ||||||||||
}} | ||||||||||
> | ||||||||||
{FilterBy.Male} | ||||||||||
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. u can make 1 universal function for all cases |
||||||||||
</a> | ||||||||||
<a className="" href="#/people?sex=f"> | ||||||||||
Female | ||||||||||
<a | ||||||||||
className={cn({ 'is-active': activeFilter === 'f' })} | ||||||||||
href="#" | ||||||||||
onClick={e => { | ||||||||||
e.preventDefault(); | ||||||||||
const newSearchParams = new URLSearchParams(searchParams); | ||||||||||
newSearchParams.set('sex', 'f'); | ||||||||||
setSearchParams(newSearchParams); | ||||||||||
}} | ||||||||||
> | ||||||||||
{FilterBy.Female} | ||||||||||
</a> | ||||||||||
</p> | ||||||||||
|
||||||||||
|
@@ -22,6 +98,8 @@ export const PeopleFilters = () => { | |||||||||
type="search" | ||||||||||
className="input" | ||||||||||
placeholder="Search" | ||||||||||
value={activeQuery} | ||||||||||
onChange={handleQueryChange} | ||||||||||
/> | ||||||||||
|
||||||||||
<span className="icon is-left"> | ||||||||||
|
@@ -33,51 +111,26 @@ 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> | ||||||||||
{centuryList.map((century, index) => ( | ||||||||||
<SearchLink | ||||||||||
key={index} | ||||||||||
data-cy="century" | ||||||||||
className={cn('button mr-1', { | ||||||||||
'is-info': activeCenturies.includes(String(century)), | ||||||||||
})} | ||||||||||
params={{ centuries: toggleCenturies(century) }} | ||||||||||
> | ||||||||||
{century} | ||||||||||
</SearchLink> | ||||||||||
))} | ||||||||||
</div> | ||||||||||
|
||||||||||
<div className="level-right ml-4"> | ||||||||||
<a | ||||||||||
data-cy="centuryALL" | ||||||||||
className="button is-success is-outlined" | ||||||||||
className={cn('button is-success ', { | ||||||||||
'is-outlined': !!activeCenturies.length, | ||||||||||
})} | ||||||||||
href="#/people" | ||||||||||
> | ||||||||||
All | ||||||||||
|
@@ -87,7 +140,11 @@ export const PeopleFilters = () => { | |||||||||
</div> | ||||||||||
|
||||||||||
<div className="panel-block"> | ||||||||||
<a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||||||||||
<a | ||||||||||
className="button is-link is-outlined is-fullwidth" | ||||||||||
href="#/people" | ||||||||||
onClick={resetAllFilters} | ||||||||||
> | ||||||||||
Reset all filters | ||||||||||
</a> | ||||||||||
</div> | ||||||||||
|
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.
do u need this disable?why?