Skip to content

fix(client): hide 'Load more news' button when no more news available#145

Merged
trett merged 5 commits intomainfrom
fix-load-more-button-visibility
Feb 25, 2026
Merged

fix(client): hide 'Load more news' button when no more news available#145
trett merged 5 commits intomainfrom
fix-load-more-button-visibility

Conversation

@trett
Copy link
Owner

@trett trett commented Feb 25, 2026

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:

  • Added hasMoreVar to the client Model to track if more items are available.
  • Implemented hasMoreObserver in Home.scala to update this state based on the number of items returned in a page.
  • Updated the "More News" button's visibility logic to hide it when hasMoreVar is false, using combineWith for consistency.
  • Improved pagination logic in Home.scala using ceiling division to correctly calculate the next page number even when some items are filtered out.
  • Extracted duplicated feed observation logic into a bindFeeds helper method.
  • Simplified component mount logic in feeds() method by using onMountCallback instead of onMountBind.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • New state variable for more news: Introduced hasMoreVar and hasMoreSignal in client/src/main/scala/client/Models.scala to track whether more news items are available to load.
  • Observer for news availability: Implemented hasMoreObserver in client/src/main/scala/client/Home.scala to update hasMoreVar based on the number of items returned per page, ensuring accurate tracking of available news.
  • Dynamic button visibility: Modified the 'More News' button's hidden property in client/src/main/scala/client/Home.scala to hide it dynamically when no more news is available or the feed is empty, preventing unnecessary display.
Changelog
  • client/src/main/scala/client/Home.scala
    • Added hasMoreObserver to monitor the number of returned feed items and update hasMoreVar.
    • Integrated hasMoreObserver into the data flow for data responses.
    • Updated the hidden attribute of the 'More News' button to combine feedVar.signal and hasMoreVar.signal for its visibility logic.
  • client/src/main/scala/client/Models.scala
    • Introduced hasMoreVar (a Var[Boolean]) initialized to true.
    • Added hasMoreSignal (a StrictSignal[Boolean]) derived from hasMoreVar.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 104 to 107
hidden <-- Signal.combine(feedVar.signal, hasMoreVar.signal).map {
(xs, hasMore) =>
xs.isEmpty || !hasMore
}

Choose a reason for hiding this comment

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

medium

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)

@trett
Copy link
Owner Author

trett commented Feb 25, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +104 to +106
hidden <-- feedSignal.combineWith(hasMoreSignal).map { case (feeds, hasMore) =>
feeds.isEmpty || !hasMore
}

Choose a reason for hiding this comment

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

high

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

Since this issue is on an unchanged line, I'm adding this comment here for visibility.

@trett
Copy link
Owner Author

trett commented Feb 25, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 68 to 70
data.addObserver(feedsObserver)(ctx.owner)
data.addObserver(hasMoreObserver)(ctx.owner)
errors.addObserver(errorObserver)(ctx.owner)

Choose a reason for hiding this comment

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

medium

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.

@trett
Copy link
Owner Author

trett commented Feb 25, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 119 to 121
onMountBind(ctx =>
stream --> (tryFeeds => bindFeeds(EventStream.fromValue(tryFeeds), ctx.owner))
),

Choose a reason for hiding this comment

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

medium

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)
            }

@trett
Copy link
Owner Author

trett commented Feb 25, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

@trett trett merged commit baacaec into main Feb 25, 2026
1 check passed
@trett trett deleted the fix-load-more-button-visibility branch February 25, 2026 20:10
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.

1 participant