-
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
Conversation
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.
Looks good! Just need few small change.
-
Changing the filter by
sex
should not reset other filters. The state of all other filters should be preserved while applying the new filter for sex. -
Keep search params when navigating within the People page (when selecting a person or clicking the People link).
-
The query match should occur not only on the
name
but also on themotherName
andfatherName
.
9cae7b1
to
1ddf996
Compare
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.
GJ 🔥
let's make some improvements
1 - All the filters and sort params should be saved as URL Search Params, so you could share the link to show exactly what you see.
2 - Keep search params when navigating within the People page (when selecting a person or clicking the People link).
src/Root.tsx
Outdated
<Routes> | ||
<Route path="/" element={<App />}> | ||
<Route path="*" element={<PageNotFound />} /> | ||
|
||
<Route index element={<HomePageTitle />} /> | ||
|
||
<Route path="people"> | ||
<Route path=":slugParam?" element={<PeoplePage />} /> | ||
</Route> | ||
|
||
<Route path="home" element={<Navigate to="/" replace />} /> | ||
</Route> |
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.
let's create Routes enum
src/components/PeoplePage.tsx
Outdated
const activeCenturies = searchParams.getAll('centuries') || ''; | ||
const activeSex = searchParams.get('sex') || ''; | ||
const activeQuery = searchParams.get('query') || ''; |
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.
let's replace strings with enum
src/components/PeoplePage.tsx
Outdated
case 'm': | ||
return peopleList.filter(person => person.sex === activeSex); | ||
case 'f': | ||
return peopleList.filter(person => person.sex === activeSex); |
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.
enum for sex
src/components/PeoplePage.tsx
Outdated
const fetchPeople = async () => { | ||
setFetchPeopleError(false); | ||
|
||
try { | ||
const response = await getPeople(); | ||
|
||
setPeople(response); | ||
setShowFilters(true); | ||
} catch (error) { | ||
setFetchPeopleError(true); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; |
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.
move this function out of the useEffect hook
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.
Overall - good job 👍
But review my comments and fix them)
src/Root.tsx
Outdated
} from 'react-router-dom'; | ||
|
||
import { App } from './App'; | ||
// eslint-disable-next-line import/extensions |
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?
src/components/PeopleFilters.tsx
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
move it to utils
directory. consts
file
src/components/PeopleFilters.tsx
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
use separate functions whenever u need a handle
function
src/components/PeopleFilters.tsx
Outdated
onClick={e => { | ||
e.preventDefault(); | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
newSearchParams.set('sex', 'm'); | ||
setSearchParams(newSearchParams); | ||
}} | ||
> |
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.
u can make 1 universal function for all cases
src/components/PeoplePage.tsx
Outdated
|
||
export const PeoplePage = () => { | ||
// #region states |
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.
remove all the comments from project
src/components/PeoplePage.tsx
Outdated
|
||
export const PeoplePage = () => { | ||
// #region states | ||
const [loading, setLoading] = useState(true); | ||
const [fetchPeopleError, setFetchPeopleError] = useState(false); |
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.
Fetch??? This prefix is only for fetch functions, NOT for booleans. Change it!
src/components/PeoplePage.tsx
Outdated
const fetchingErrorNotification = !loading && fetchPeopleError; | ||
const noPeopleNotification = !loading && !fetchPeopleError && !people.length; | ||
const showPeopleTable = !loading && !fetchPeopleError && !!people.length; |
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.
If there is an error or an active loader - ur list length will be 0.
u don't need to constantly duplicate conditions
const fetchingErrorNotification = !loading && fetchPeopleError; | |
const noPeopleNotification = !loading && !fetchPeopleError && !people.length; | |
const showPeopleTable = !loading && !fetchPeopleError && !!people.length; | |
const fetchingErrorNotification = fetchPeopleError; | |
const noPeopleNotification = !people.length; | |
const showPeopleTable = !!people.length; |
src/components/Person.tsx
Outdated
|
||
export const Person: React.FC<Props> = ({ person, people }) => { | ||
const { slugParam } = useParams(); | ||
const { name, sex, born, died, slug, motherName, fatherName } = person; |
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.
if u have 3 or more parameters - move them to separate line
const { name, sex, born, died, slug, motherName, fatherName } = person; | |
const { | |
name, | |
sex, | |
born, | |
died, | |
slug, | |
motherName, | |
fatherName | |
} = person; |
src/components/Person.tsx
Outdated
return ( | ||
<tr | ||
data-cy="person" | ||
className={person.slug === slugParam ? 'has-background-warning' : ''} |
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.
u always used the library - classNames
. Use it here too.
Never mix ur code styles
src/page/HomePageTitle.tsx
Outdated
@@ -0,0 +1 @@ | |||
export const HomePageTitle = () => <h1 className="title">Home Page</h1>; |
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.
i see u have 3 similar components with same styles where only the header changes.
Make 1 component that will accept the title as props
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.
Good Job 🔥
let's make some improvements
src/components/PeopleFilters.tsx
Outdated
setActiveFilter(searchParams.get('sex') || ''); | ||
setQuery(searchParams.get('query') || ''); |
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.
you have the enum QueryParams
so use it
setActiveFilter(searchParams.get('sex') || ''); | |
setQuery(searchParams.get('query') || ''); | |
setActiveFilter(searchParams.get(QueryParams.Sex) || ''); | |
setQuery(searchParams.get(QueryParams.Query) || ''); |
src/components/PeopleFilters.tsx
Outdated
const newSearchParams = new URLSearchParams(searchParams); | ||
|
||
if (!event.target.value) { | ||
newSearchParams.delete('query'); |
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.
use enum QueryParams
newSearchParams.delete('query'); | |
newSearchParams.delete(QueryParams.Query); |
src/components/PeopleFilters.tsx
Outdated
if (!event.target.value) { | ||
newSearchParams.delete('query'); | ||
} else { | ||
newSearchParams.set('query', event.target.value); |
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 same here, use enum QueryParams
src/components/PeopleFilters.tsx
Outdated
const handleResetSexFilter = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
e.preventDefault(); | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
newSearchParams.delete('sex'); |
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.
use enum QueryParams
src/components/PeopleFilters.tsx
Outdated
const handleSetMaleFilter = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
e.preventDefault(); | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
newSearchParams.set('sex', 'm'); |
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.
you have created the enum QueryParams
and enum Sex
use them in cases like this
src/components/PeopleFilters.tsx
Outdated
const handleSetFemaleFilter = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||
e.preventDefault(); | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
newSearchParams.set('sex', 'f'); |
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 same as above, use enum QueryParams
and enum Sex
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.
Good job 🔥
DEMO LINK