fix(client): hide 'Load more news' button when no more news available#145
fix(client): hide 'Load more news' button when no more news available#145
Conversation
Summary of ChangesHello @trett, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a user experience issue where the 'Load more news' button remained visible even after all available news items had been loaded. By introducing a new state variable to track the availability of additional news and integrating an observer to update this state, the button's visibility is now correctly managed, ensuring it only appears when there are indeed more items to fetch. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where the 'Load more news' button was not hidden when all news items were loaded. The approach of introducing a hasMoreVar state variable and an observer to update it based on the number of items fetched per page is sound. The logic to control the button's visibility is also correct. I have one suggestion to improve the code's consistency and performance slightly by using the existing signals from the model and a more efficient Laminar operator.
| hidden <-- Signal.combine(feedVar.signal, hasMoreVar.signal).map { | ||
| (xs, hasMore) => | ||
| xs.isEmpty || !hasMore | ||
| } |
There was a problem hiding this comment.
For better code clarity and consistency, you can use the feedSignal and hasMoreSignal already defined in the Model. Additionally, using combineWith with a combinator function is slightly more efficient than Signal.combine followed by .map as it avoids creating an intermediate tuple.
hidden <-- feedSignal.combineWith(hasMoreSignal)((feeds, hasMore) => feeds.isEmpty || !hasMore)|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly implements the logic to hide the 'Load more news' button when no more news are available by introducing a hasMoreVar state. The implementation is clean and follows the existing application patterns. However, I've identified a significant pre-existing bug in the pagination logic that is closely related to these changes and could lead to infinite requests. I've left a detailed comment on this issue.
| hidden <-- feedSignal.combineWith(hasMoreSignal).map { case (feeds, hasMore) => | ||
| feeds.isEmpty || !hasMore | ||
| } |
There was a problem hiding this comment.
This logic correctly hides the 'More News' button. However, there's a related high-severity issue in the pagination logic on the preceding line (103). The current page calculation, onClick.mapTo(feedVar.now().size / pageLimit + 1), can lead to an infinite loop of fetching the same page. This occurs if a new page of feeds contains items that are already loaded, as feedsObserver uses distinctBy(_.link). In this case, feedVar.now().size won't increase by a full page, causing the same page number to be calculated on the next click.
To fix this, the page number calculation should be more robust. For example, using ceiling division:
(feedVar.now().size + pageLimit - 1) / pageLimit + 1Since this issue is on an unchanged line, I'm adding this comment here for visibility.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request successfully addresses a bug where the 'Load more news' button remained visible even when no more news items were available. The introduction of hasMoreVar and its corresponding observer is a clean solution. The pagination logic has also been improved to be more robust. I have one suggestion regarding code duplication to improve maintainability.
| data.addObserver(feedsObserver)(ctx.owner) | ||
| data.addObserver(hasMoreObserver)(ctx.owner) | ||
| errors.addObserver(errorObserver)(ctx.owner) |
There was a problem hiding this comment.
The logic for observing the feed response stream (data and errors) is duplicated here and in the feeds() method (lines 121-123). This PR, by adding hasMoreObserver in both places, highlights this maintainability issue. To avoid having to update two locations for future changes, consider extracting this observer attachment logic into a single helper method.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue of the 'Load more news' button's visibility by introducing hasMoreVar to track pagination state. The refactoring to extract duplicated logic into the bindFeeds method and the correction of the pagination calculation are excellent improvements for maintainability and correctness. I have one suggestion to further simplify the code in the feeds method for better clarity.
| onMountBind(ctx => | ||
| stream --> (tryFeeds => bindFeeds(EventStream.fromValue(tryFeeds), ctx.owner)) | ||
| ), |
There was a problem hiding this comment.
The use of onMountBind combined with creating a new EventStream from a value within a subscription (-->) is functionally correct but overly complex for this scenario. A more direct and idiomatic approach in Laminar for handling side-effects on component mount is to use onMountCallback. This simplifies the code, making it more readable and maintainable by clearly stating the intent of performing an action when the component is mounted.
onMountCallback { ctx =>
bindFeeds(stream, ctx.owner)
}|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a bug where the 'Load more news' button remained visible even when no more news items were available. The introduction of hasMoreVar and hasMoreObserver effectively tracks the availability of more content. The pagination logic for fetching the next page has been improved for correctness, and the button's visibility logic is now robust. Furthermore, the code has been nicely refactored by extracting duplicated feed observation logic into a bindFeeds helper method, which significantly improves code clarity and maintainability. The changes are well-implemented and address the described issues effectively.
This PR fixes a bug in the "Regular mode" where the "More News" button remained visible even after all news items were loaded. It also improves the pagination logic and reduces code duplication.
Changes:
hasMoreVarto the clientModelto track if more items are available.hasMoreObserverinHome.scalato update this state based on the number of items returned in a page.hasMoreVaris false, usingcombineWithfor consistency.Home.scalausing ceiling division to correctly calculate the next page number even when some items are filtered out.bindFeedshelper method.feeds()method by usingonMountCallbackinstead ofonMountBind.