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

Develop #519

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

Develop #519

wants to merge 11 commits into from

Conversation

cty2802
Copy link

@cty2802 cty2802 commented Oct 5, 2023

Copy link

@polosanya polosanya left a comment

Choose a reason for hiding this comment

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

Nice! Let's improve your solution a bit)
The filters shouldn't reset when we select a person
select

Comment on lines +24 to +33
if (sort) {
params.set('sort', sort);
} else {
params.delete('sort');
}

if (sort === oldSort && !oldOrder) {
params.set('order', 'desc');
} else {
params.delete('order');

Choose a reason for hiding this comment

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

Consider using switch...case here instead

Copy link
Author

@cty2802 cty2802 Oct 11, 2023

Choose a reason for hiding this comment

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

I considered using switch...case here, but I feel the code looks too complicated with it. The thing that I should check not only the 'sort' variable, but the 'oldOrder' variable too. Still, I would appreciate it if you give me an example of how it can be done nicely.

Choose a reason for hiding this comment

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

@cty2802 I would shorten the code like this:

if (sort === oldSort) {
  params.delete('sort');
  params.delete('order');
} else {
  params.set('sort', sort);
  params.delete('order');
  if (oldOrder) {
    params.set('order', 'desc');
  }
}

but it is worth analyzing in practice whether everything will work as it should 😄

Copy link
Author

@cty2802 cty2802 Oct 11, 2023

Choose a reason for hiding this comment

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

Unfortunately, it doesn't work. Under such conditions, sorting has only two states - asc and start position, but there is no desc position.
I like my code, can I keep it? And we will assume that it's not a bug, it's a feature -:)

Choose a reason for hiding this comment

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

@cty2802 of course, I only made assumptions based on your code, but if my approach does not work - then we leave it as you did))
One of the main rules of programming - if it works, don't touch it 😅

src/helper.tsx Outdated
Comment on lines 24 to 33
const humans: Person[] = [...people];

return humans.sort((humanA: Person, humanB: Person): number => {
if (oldSort === SortBy.Name) {
return oldOrder === SortOrder.Desc
? (humanA.name.localeCompare(humanB.name) * -1)
: humanA.name.localeCompare(humanB.name);
}

if (oldSort === SortBy.Sex) {

Choose a reason for hiding this comment

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

Same here

export const PeoplePage: React.FC = () => {
const [people, setPeople] = useState<Person[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [errorMassage, setErrorMassage] = useState('');

Choose a reason for hiding this comment

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

Suggested change
const [errorMassage, setErrorMassage] = useState('');
const [errorMessage, setErrorMessage] = useState('');

@cty2802 cty2802 requested a review from polosanya October 11, 2023 13:37
Copy link

@roman-mirzoian roman-mirzoian 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, but there is quite a bit of work to be done.
Also, if there are no search results, we have to see only the message, without the table:
image

Comment on lines 9 to 19
const setIconClass = (columnName: SortBy): string => {
if (columnName === oldSort && !oldOrder) {
return 'fas fa-sort-up';
}

if (columnName === oldSort && oldOrder) {
return 'fas fa-sort-down';
}

return 'fas fa-sort';
};

Choose a reason for hiding this comment

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

Use the classnames library for this logic

}}
>
<span className="icon">
<i className={setIconClass(SortBy.Name)} />

Choose a reason for hiding this comment

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

classnames issue

Comment on lines +24 to +33
if (sort) {
params.set('sort', sort);
} else {
params.delete('sort');
}

if (sort === oldSort && !oldOrder) {
params.set('order', 'desc');
} else {
params.delete('order');

Choose a reason for hiding this comment

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

@cty2802 I would shorten the code like this:

if (sort === oldSort) {
  params.delete('sort');
  params.delete('order');
} else {
  params.set('sort', sort);
  params.delete('order');
  if (oldOrder) {
    params.set('order', 'desc');
  }
}

but it is worth analyzing in practice whether everything will work as it should 😄

Comment on lines 22 to 24
return !centuries?.length
? true
: centuries.includes(Math.floor(person.born / 100).toString());

Choose a reason for hiding this comment

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

Suggested change
return !centuries?.length
? true
: centuries.includes(Math.floor(person.born / 100).toString());
return !centuries?.length || centuries.includes(Math.floor(person.born / 100).toString());

Choose a reason for hiding this comment

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

But avoid usign "magic values" (100)

Copy link

@roman-mirzoian roman-mirzoian left a comment

Choose a reason for hiding this comment

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

Well done 👍

Comment on lines 10 to 15
const setIconClass = (columnName: SortBy): string => {
return classNames('fas',
{ 'fa-sort-up': columnName === oldSort && !oldOrder },
{ 'fa-sort-down': columnName === oldSort && oldOrder },
{ 'fa-sort': columnName });
};

Choose a reason for hiding this comment

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

It is better to define this function outside the component so that it is not created every time a new render is performed.

const oldSort = searchParams.get('sort');
const oldOrder = searchParams.get('order');

const setIconClass = (columnName: SortBy): string => {

Choose a reason for hiding this comment

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

Suggested change
const setIconClass = (columnName: SortBy): string => {
const getIconClass = (columnName: SortBy): string => {

Comment on lines +24 to +33
if (sort) {
params.set('sort', sort);
} else {
params.delete('sort');
}

if (sort === oldSort && !oldOrder) {
params.set('order', 'desc');
} else {
params.delete('order');

Choose a reason for hiding this comment

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

@cty2802 of course, I only made assumptions based on your code, but if my approach does not work - then we leave it as you did))
One of the main rules of programming - if it works, don't touch it 😅

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