-
Notifications
You must be signed in to change notification settings - Fork 1.9k
realize react_peoplt-table-advanced #1829
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,75 @@ | ||
| import { PeopleFilters } from './PeopleFilters'; | ||
| import { useState, useEffect } from 'react'; | ||
| import { useSearchParams } from 'react-router-dom'; | ||
| import { getPreparedPeople } from '../utils/getPreparedPeople'; | ||
| import { getPeople } from '../api'; | ||
| import { Person } from '../types/Person'; | ||
| import { Loader } from './Loader'; | ||
| import { PeopleFilters } from './PeopleFilters'; | ||
| import { PeopleTable } from './PeopleTable'; | ||
|
|
||
| export const PeoplePage = () => { | ||
| const [people, setPeople] = useState<Person[]>([]); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [hasError, setHasError] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| setIsLoading(true); | ||
|
|
||
| getPeople() | ||
| .then(setPeople) | ||
| .catch(() => setHasError(true)) | ||
| .finally(() => setIsLoading(false)); | ||
| }, []); | ||
|
|
||
| const [searchParams] = useSearchParams(); | ||
|
|
||
|
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.
|
||
| const sex = searchParams.get('sex'); | ||
| const query = searchParams.get('query'); | ||
| const centuries = searchParams.getAll('centuries'); | ||
| const sort = searchParams.get('sort'); | ||
| const order = searchParams.get('order'); | ||
|
|
||
| const visiblePeople = getPreparedPeople(people, { | ||
| sex, | ||
| query, | ||
| centuries, | ||
| sort, | ||
| order, | ||
| }); | ||
|
|
||
| const isLoaded = !isLoading && !hasError; | ||
| const noPeopleOnServer = isLoaded && people.length === 0; | ||
| const showContent = isLoaded && people.length > 0; | ||
|
|
||
| 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 /> | ||
| {showContent && <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 && <Loader />} | ||
| {!isLoading && hasError && ( | ||
| <p data-cy="peopleLoadingError" className="has-text-danger"> | ||
| Something went wrong | ||
| </p> | ||
| )} | ||
| {noPeopleOnServer && ( | ||
| <p data-cy="noPeopleMessage"> | ||
| There are no people on the server | ||
| </p> | ||
| )} | ||
| {showContent && visiblePeople.length === 0 && ( | ||
| <p>There are no people matching the current search criteria</p> | ||
| )} | ||
| {showContent && visiblePeople.length > 0 && ( | ||
| <PeopleTable people={visiblePeople} /> | ||
| )}{' '} | ||
| </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.
setSearchParams(getSearchWith(searchParams, { query: newQuery || null }))correctly updates thequeryparam and removes it when the input is empty, matching the NameFilter URL behavior requirement. Ensure similar|| nullhandling for any future optional params you might introduce.