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

feat: search results pagination #361

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mohannadzidan
Copy link
Contributor

This PR will add pagination buttons to search results to show more search results

closes #357, and closes #292

@henriqueleite42
Copy link

Closes #369

@zamitto
Copy link
Collaborator

zamitto commented May 15, 2024

Please, always add a screenshot when your PR is releated to UI stuff.

@mohannadzidan
Copy link
Contributor Author

mohannadzidan commented May 16, 2024

new translation keys are required for next_page and last_page

image

@piradata
Copy link
Contributor

piradata commented May 18, 2024

Could you please add the translation for en at least as it is the default fallback? The others can be added later.

LGTM overall, nice work :)

@piradata
Copy link
Contributor

piradata commented May 18, 2024

image

@mohannadzidan u can use it actually

the only problem is that this file uses const { t } = useTranslation("home"); instead of const { t } = useTranslation("catalogue"); 😅

@mohannadzidan
Copy link
Contributor Author

I have updated the code to use next_page, previous_page keys from the catalogue namespace

image

@mohannadzidan
Copy link
Contributor Author

@zamitto hey, this feature is ready to merge, can you please review the code?

@piradata
Copy link
Contributor

piradata commented Jun 2, 2024

hey @mohannadzidan , need some help here?

@mohannadzidan
Copy link
Contributor Author

Hello @piradata and @zamitto

I've implemented the changes requested in the previous review:

  1. Moved pagination inlined styles to home.css for better separation of concerns.
  2. Updated the searchGames function signature for improved clarity and reusability.
  3. Added functionality to disable the "next" button when there are no more results to prevent unexpected behavior.

Please take another look at the code and let me know if everything looks good or if you have any further suggestions. Thanks!

@@ -16,6 +20,8 @@ import { useNavigate, useSearchParams } from "react-router-dom";
import * as styles from "./home.css";
import { buildGameDetailsPath } from "@renderer/helpers";

const PAGE_SIZE = 12;
Copy link
Contributor

Choose a reason for hiding this comment

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

why set the pagesize here if you already set the default on the function itself to 12?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it like this to increase the code readability and avoid hard coding magic numbers in the code while calculating whether this is the last results page or not

For example if a new contributor saw this line

setIsEnd(results.length < 12)

He will be confused and wonder what does this number 12 mean and why we put it here, right? But by declaring this constant and use it properly in the query it is clearer and will make since to him

Copy link
Contributor

@piradata piradata Jun 3, 2024

Choose a reason for hiding this comment

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

but you can fetch this number from the search params the same way you does to get the page no?


const DEFAULT_SEARCH_ARGS: PaginationArgs = {
take: 12,
skip: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of skip, you could also just pass the page as a default for zero, and calculate the skip inside the function itself, then you dont need to know the default value for take when you just wannt to go to the page like 5 using the default "take" parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually your suggestion was exactly the previous version of the function when i modified it initially for this pagination feature, but I thought that it is more reusable like this? Like if in the future we had to use this function to display different number of results we will able to do this without revisting the code again and modify it

Copy link
Contributor

Choose a reason for hiding this comment

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

+/-, like, how it is now, you need to know the take parameter to send the skip correctly considering the number of the page you want, so you basically dont make use of the default value for take, as you need to consider it anyway to send the skip.

if you send only take and page, both optional to 12 an 0 respectively, you dont need to care about any of this logic, and can even just send the page arg for any request. and you also has access to the take (default or not) used on the query to see if you are on the last page (query could also return a parameter with the number of pages tho)

what do you think @zamitto?

Choose a reason for hiding this comment

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

I kinda agree with @piradata on this one, but the default to 12 on take I think that should be a global default value, indeed of having one here, another one in src/renderer/src/pages/home/search-results.tsx and so on.

Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda agree with @piradata on this one, but the default to 12 on take I think that should be a global default value, indeed of having one here, another one in src/renderer/src/pages/home/search-results.tsx and so on.

yea, i thought about it being defined on the own function internally, that way it would basically be a global default, without the need to import the default and the function separately

@piradata
Copy link
Contributor

piradata commented Jun 6, 2024

@zamitto what do you think on this one?

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.

[REQUEST] A button to "show more" when searching for games [BUG] Problems with searching
4 participants