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

implement filtering and sorting #507

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

Conversation

serkrops
Copy link

@serkrops serkrops commented Oct 4, 2023

Copy link

@Moroz-Dmytro Moroz-Dmytro left a comment

Choose a reason for hiding this comment

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

image

@@ -0,0 +1,3 @@
export const PageNotFound: React.FC = () => (

Choose a reason for hiding this comment

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

Suggested change
export const PageNotFound: React.FC = () => (
export const NotFoundPage: React.FC = () => (

person: Person,
};

export const People: React.FC<Props> = ({ person }) => {

Choose a reason for hiding this comment

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

Suggested change
export const People: React.FC<Props> = ({ person }) => {
export const Person: React.FC<Props> = ({ person }) => {

Comment on lines 34 to 59
function toggleCenturies(cntr: string) {
const params = new URLSearchParams(searchParams);

const newCenturies = centuries.includes(cntr)
? centuries.filter(prevCentury => prevCentury !== cntr)
: [...centuries, cntr];

params.delete('centuries');
newCenturies.forEach(cent => params.append('centuries', cent));
setSearchParams(params);
}

function handleClearAllCenturies() {
const params = new URLSearchParams(searchParams);

params.delete('centuries');
setSearchParams(params);
}

function handleResetAllFilters() {
const params = new URLSearchParams(searchParams);

params.delete('sex');
params.delete('query');
setSearchParams(params);
}

Choose a reason for hiding this comment

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

You don't need these functions. You have params prop in your SearchLink for this

Comment on lines 112 to 122
<button
key={century}
type="button"
data-cy="century"
className={classNames('button mr-1', {
'is-info': centuries.includes(century),
})}
onClick={() => toggleCenturies(century)}
>
{century}
</button>

Choose a reason for hiding this comment

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

You should use SearchLink here

Comment on lines 126 to 135
<button
type="button"
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={classNames('button is-success', {
'is-outlined': !!centuries.length,
})}
onClick={handleClearAllCenturies}
>
All
</a>
</button>

Choose a reason for hiding this comment

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

Same here, use SearchLink

Comment on lines 140 to 146
<a
className="button is-link is-outlined is-fullwidth"
href="#/people"
onClick={() => handleResetAllFilters}
>
Reset all filters
</a>

Choose a reason for hiding this comment

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

And here, use SearchLink

Comment on lines 57 to 59
'fa-sort': sort !== normalizedTitle,
'fa-sort-up': sort === normalizedTitle && !order,
'fa-sort-down': sort === normalizedTitle && order,

Choose a reason for hiding this comment

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

DRY, create variable for repeatable code

Comment on lines 30 to 36
const preparedPeople = persons.map(person => {
return {
...person,
mother: persons.find(({ name }) => person.motherName === name),
father: persons.find(({ name }) => person.fatherName === name),
};
});

Choose a reason for hiding this comment

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

Move this logic to separate helper function

if (sort) {
personsClone = personsClone.sort((personA, personB) => {
switch (sort) {
case 'name':

Choose a reason for hiding this comment

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

Create enum for these options

import { Person } from '../types';

export function getCentury(person: Person, centuries: string[]) {
return centuries.includes(Math.ceil(person.born / 100).toString());

Choose a reason for hiding this comment

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

Magic value

@serkrops serkrops requested a review from Moroz-Dmytro October 10, 2023 10:25
Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

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

Good work 👍
Approved, but as I see this is still not implemented:
2) Keep search params when navigating within the People page (when selecting a person or clicking the People link).

Comment on lines +21 to +24
const params = new URLSearchParams(searchParams);

params.set('query', event.target.value);
setSearchParams(params);

Choose a reason for hiding this comment

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

You can get previous params in setSearchParams

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.

3 participants