-
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
Solution #1156
base: master
Are you sure you want to change the base?
Solution #1156
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,3 +1,7 @@ | ||
iframe { | ||
display: none; | ||
} | ||
|
||
.section { | ||
margin-top: 3.25em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const HomePage = () => <h1 className="title">Home Page</h1>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PageNotFound = () => <h1 className="title">Page not found</h1>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PeopleTable } from '../components/PeopleTable'; | ||
|
||
export const PeoplePage = () => { | ||
return ( | ||
<> | ||
<h1 className="title">People Page</h1> | ||
<PeopleTable /> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
Navigate, | ||
Route, | ||
HashRouter as Router, | ||
Routes, | ||
} from 'react-router-dom'; | ||
import { App } from './App'; | ||
import { PeopleProvider } from './store/PeopleContext'; | ||
import { HomePage } from './Pages/HomePage'; | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { PageNotFound } from './Pages/PageNotFound'; | ||
import { FilterProvider } from './store/FilterContext'; | ||
|
||
export const Root = () => ( | ||
<Router> | ||
<FilterProvider> | ||
<PeopleProvider> | ||
<Routes> | ||
<Route path="/" element={<App />}> | ||
<Route path="home" element={<Navigate to="/" replace />} /> | ||
<Route index element={<HomePage />} /> | ||
<Route path="people" element={<PeoplePage />}> | ||
<Route index element={<PeoplePage />} /> | ||
<Route path=":slug?" /> | ||
</Route> | ||
<Route path="*" element={<PageNotFound />} /> | ||
</Route> | ||
</Routes> | ||
</PeopleProvider> | ||
</FilterProvider> | ||
</Router> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,58 @@ | ||
import { Link, NavLink } from 'react-router-dom'; | ||
import { useFilters } from '../store/FilterContext'; | ||
import classNames from 'classnames'; | ||
|
||
export const PeopleFilters = () => { | ||
const { query, sexs, centuries, setSearchWith, getSearchWith, searchParams } = | ||
useFilters(); | ||
|
||
function handleQueryChange(event: React.ChangeEvent<HTMLInputElement>) { | ||
setSearchWith({ query: event.target.value }); | ||
} | ||
|
||
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> | ||
<a className="" href="#/people?sex=m"> | ||
Male | ||
</a> | ||
<a className="" href="#/people?sex=f"> | ||
Female | ||
</a> | ||
{['All', 'Male', 'Female'].map(sex => { | ||
let normalizedSex = 'All'; | ||
|
||
switch (sex) { | ||
case 'Male': | ||
normalizedSex = 'm'; | ||
break; | ||
case 'Female': | ||
normalizedSex = 'f'; | ||
} | ||
Comment on lines
+21
to
+27
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 isActive = | ||
normalizedSex === 'All' | ||
? sexs.length === 0 | ||
: sexs.includes(normalizedSex); | ||
|
||
return ( | ||
<NavLink | ||
key={sex} | ||
to={{ | ||
search: getSearchWith( | ||
{ | ||
sexs: | ||
normalizedSex === 'All' | ||
? null | ||
: sexs.includes(normalizedSex) | ||
? sexs.filter(ch => normalizedSex !== ch) | ||
: [...sexs, normalizedSex], | ||
}, | ||
searchParams, | ||
), | ||
}} | ||
className={classNames('panel-tab', { 'is-active': isActive })} | ||
> | ||
{sex} | ||
</NavLink> | ||
); | ||
})} | ||
</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,56 @@ 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> | ||
{['16', '17', '18', '19', '20'].map(century => ( | ||
<Link | ||
key={century} | ||
to={{ | ||
search: getSearchWith( | ||
{ | ||
centuries: centuries.includes(century) | ||
? centuries.filter(ch => century !== ch) | ||
: [...centuries, century], | ||
}, | ||
searchParams, | ||
), | ||
}} | ||
data-cy="century" | ||
className={classNames('button mr-1', { | ||
'is-info': centuries.includes(century), | ||
})} | ||
> | ||
{century} | ||
</Link> | ||
))} | ||
</div> | ||
|
||
<div className="level-right ml-4"> | ||
<a | ||
<Link | ||
to={{ search: getSearchWith({ centuries: null }, searchParams) }} | ||
data-cy="centuryALL" | ||
className="button is-success is-outlined" | ||
href="#/people" | ||
className={classNames('button is-success ', { | ||
'is-outlined': centuries.length > 0, | ||
})} | ||
> | ||
All | ||
</a> | ||
</Link> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
<Link | ||
to={{ | ||
search: getSearchWith( | ||
{ centuries: null, sexs: null, query: '' }, | ||
searchParams, | ||
), | ||
}} | ||
className={classNames('button is-link is-fullwidth', { | ||
'is-outlined ': sexs.length > 0 || centuries.length > 0 || query, | ||
})} | ||
> | ||
Reset all filters | ||
</a> | ||
</Link> | ||
</div> | ||
</nav> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
import { PeopleFilters } from './PeopleFilters'; | ||
import { Loader } from './Loader'; | ||
import { PeopleTable } from './PeopleTable'; | ||
import { usePeople } from '../store/PeopleContext'; | ||
|
||
export const PeoplePage = () => { | ||
const { isLoading, errorMsg, filteredPeople } = usePeople(); | ||
|
||
if (isLoading) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1 className="title">People Page</h1> | ||
|
||
<div className="block"> | ||
<div className="columns is-desktop is-flex-direction-row-reverse"> | ||
<div className="column is-7-tablet is-narrow-desktop"> | ||
<PeopleFilters /> | ||
</div> | ||
{!isLoading && ( | ||
<div className="column is-7-tablet is-narrow-desktop"> | ||
<PeopleFilters /> | ||
</div> | ||
)} | ||
|
||
<div className="column"> | ||
<div className="box table-container"> | ||
<Loader /> | ||
|
||
<p data-cy="peopleLoadingError">Something went wrong</p> | ||
|
||
<p data-cy="noPeopleMessage">There are no people on the server</p> | ||
|
||
<p>There are no people matching the current search criteria</p> | ||
|
||
<PeopleTable /> | ||
{!isLoading && errorMsg && ( | ||
<p data-cy="peopleLoadingError" className="has-text-danger"> | ||
{errorMsg} | ||
</p> | ||
)} | ||
{!isLoading && !errorMsg && filteredPeople.length === 0 && ( | ||
<p data-cy="noPeopleMessage">{errorMsg}</p> | ||
)} | ||
Comment on lines
+32
to
+34
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 condition for displaying the 'no people' message uses |
||
{filteredPeople.length > 0 && <PeopleTable />} | ||
</div> | ||
</div> | ||
</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.
The import path for
PeoplePage
should be../components/PeoplePage
instead of./components/PeoplePage
to match the file structure.