Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

YaroslavKolesnyk
Copy link

Copy link

@OleksiiKislukhin OleksiiKislukhin left a 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.

  1. 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.

  2. Keep search params when navigating within the People page (when selecting a person or clicking the People link).

  3. The query match should occur not only on the name but also on the motherName and fatherName.

Copy link

@igorkruz igorkruz left a 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
Comment on lines 17 to 28
<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>
Copy link

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

Comment on lines 23 to 25
const activeCenturies = searchParams.getAll('centuries') || '';
const activeSex = searchParams.get('sex') || '';
const activeQuery = searchParams.get('query') || '';
Copy link

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

Comment on lines 52 to 55
case 'm':
return peopleList.filter(person => person.sex === activeSex);
case 'f':
return peopleList.filter(person => person.sex === activeSex);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum for sex

Comment on lines 65 to 78
const fetchPeople = async () => {
setFetchPeopleError(false);

try {
const response = await getPeople();

setPeople(response);
setShowFilters(true);
} catch (error) {
setFetchPeopleError(true);
} finally {
setLoading(false);
}
};
Copy link

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

Copy link

@VolodymyrKirichenko VolodymyrKirichenko left a 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

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?

activeCenturies,
}: PeopleFilterProps) => {
const [activeFilter, setActiveFilter] = useState('');
const centuryList = [16, 17, 18, 19, 20];

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

Comment on lines 59 to 64
onClick={e => {
e.preventDefault();
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.delete('sex');
setSearchParams(newSearchParams);
}}

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

Comment on lines 71 to 77
onClick={e => {
e.preventDefault();
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set('sex', 'm');
setSearchParams(newSearchParams);
}}
>

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


export const PeoplePage = () => {
// #region states

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


export const PeoplePage = () => {
// #region states
const [loading, setLoading] = useState(true);
const [fetchPeopleError, setFetchPeopleError] = useState(false);

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!

Comment on lines 86 to 88
const fetchingErrorNotification = !loading && fetchPeopleError;
const noPeopleNotification = !loading && !fetchPeopleError && !people.length;
const showPeopleTable = !loading && !fetchPeopleError && !!people.length;

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

Suggested change
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;


export const Person: React.FC<Props> = ({ person, people }) => {
const { slugParam } = useParams();
const { name, sex, born, died, slug, motherName, fatherName } = person;

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

Suggested change
const { name, sex, born, died, slug, motherName, fatherName } = person;
const {
name,
sex,
born,
died,
slug,
motherName,
fatherName
} = person;

return (
<tr
data-cy="person"
className={person.slug === slugParam ? 'has-background-warning' : ''}

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

@@ -0,0 +1 @@
export const HomePageTitle = () => <h1 className="title">Home Page</h1>;

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

Copy link

@igorkruz igorkruz left a 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

Comment on lines 27 to 28
setActiveFilter(searchParams.get('sex') || '');
setQuery(searchParams.get('query') || '');

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

Suggested change
setActiveFilter(searchParams.get('sex') || '');
setQuery(searchParams.get('query') || '');
setActiveFilter(searchParams.get(QueryParams.Sex) || '');
setQuery(searchParams.get(QueryParams.Query) || '');

const newSearchParams = new URLSearchParams(searchParams);

if (!event.target.value) {
newSearchParams.delete('query');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use enum QueryParams

Suggested change
newSearchParams.delete('query');
newSearchParams.delete(QueryParams.Query);

if (!event.target.value) {
newSearchParams.delete('query');
} else {
newSearchParams.set('query', event.target.value);

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

const handleResetSexFilter = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.delete('sex');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use enum QueryParams

const handleSetMaleFilter = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set('sex', 'm');

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

const handleSetFemaleFilter = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set('sex', 'f');

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

Copy link

@VolodymyrKirichenko VolodymyrKirichenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants