-
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 #609
base: master
Are you sure you want to change the base?
Develop #609
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,23 @@ | ||
import { Routes, Route, Navigate } from 'react-router-dom'; | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { Navbar } from './components/Navbar'; | ||
|
||
import './App.scss'; | ||
|
||
export const App = () => { | ||
return ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
|
||
<div className="section"> | ||
<div className="container"> | ||
<h1 className="title">Home Page</h1> | ||
<h1 className="title">Page not found</h1> | ||
<PeoplePage /> | ||
</div> | ||
export const App = () => ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
<main className="section"> | ||
<div className="container"> | ||
<Routes> | ||
<Route path="/home" element={<Navigate to="/" replace />} /> | ||
<Route path="/" element={<h1 className="title">Home Page</h1>} /> | ||
<Route path="people"> | ||
<Route index element={<PeoplePage />} /> | ||
<Route path=":userSlug" element={<PeoplePage />} /> | ||
</Route> | ||
<Route path="*" element={<h1 className="title">Page not found</h1>} /> | ||
</Routes> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
</main> | ||
</div> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,64 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { PeopleFilters } from './PeopleFilters'; | ||
import { Loader } from './Loader'; | ||
import { PeopleTable } from './PeopleTable'; | ||
import { getPeople } from '../api'; | ||
import { getVisiblePeople } from '../utils/getVisiblePeople'; | ||
import { Person } from '../types/Person'; | ||
|
||
export const PeoplePage = () => { | ||
const [people, setPeople] = useState<Person[] | null>(null); | ||
const [isLoad, setIsLoad] = useState<boolean>(true); | ||
const [error, setError] = useState<string | null>(null); | ||
const [searchParams] = useSearchParams(); | ||
|
||
const sex = searchParams.get('sex'); | ||
const query = searchParams.get('query')?.trim().toLocaleLowerCase(); | ||
const centuries = searchParams.getAll('centuries') || []; | ||
const sort = searchParams.get('sort'); | ||
const order = searchParams.get('order'); | ||
|
||
useEffect(() => { | ||
getPeople() | ||
.then(setPeople) | ||
.catch(() => { | ||
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. Try to catch an |
||
setError('Something went wrong'); | ||
}) | ||
.finally(() => setIsLoad(false)); | ||
}, []); | ||
|
||
const visiblePeople = getVisiblePeople( | ||
people, | ||
sex, | ||
query, | ||
centuries, | ||
sort, | ||
order, | ||
); | ||
|
||
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 /> | ||
{people && <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 /> | ||
{isLoad && <Loader />} | ||
{error && ( | ||
<p data-cy="peopleLoadingError" className="has-text-danger"> | ||
{error} | ||
</p> | ||
)} | ||
{people && <PeopleTable people={visiblePeople} />} | ||
{!isLoad && !error && !people && ( | ||
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 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. Maybe I've already fixed it with lowder, because I don't see this problem now |
||
<p data-cy="noPeopleMessage">no people</p> | ||
)} | ||
</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.
Find a better way to reset all by just 1 line of code. If you had 20 filters, would you set null to all of them?
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.
all the other options I can think of
will either just increase the amount of code or reset the sorting as well.