Skip to content

bugfix(playlist): reset page to 1 on playlist change - #1676 #4154

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

Merged
merged 2 commits into from
May 30, 2025

Conversation

strider-
Copy link
Contributor

Reset page to 1 when changing playlists


Closes: #1676, #3225

This PR addresses an issue, where being on page 2 or greater of a playlist, then immediately navigating to a different playlist that has less pages than the current page number will result in an 'empty' page with no songs or pagination options.

This is achieved via the useEffect hook in the PlaylistSongs component, calling setPage(1) whenever the playlist changes. It will also automatically scroll to the top of the page, but this can be removed if it is undesirable.

Signed-off-by: Michael Tighe <strideriidx@gmail.com>
Copy link
Contributor

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

Hello @strider-, 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!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request. This PR addresses a bug where navigating to a different playlist while on a paginated view (page 2 or higher) could result in an empty page if the new playlist had fewer total pages than the current page number. The core fix involves resetting the pagination back to the first page whenever the active playlist changes. Additionally, it includes a smooth scroll to the top of the page upon playlist change.

Highlights

  • Bug Fix: Resolves an issue (#1676, #3225) where switching playlists while on a high page number could lead to an empty song list if the new playlist was shorter.
  • Pagination Reset: Introduces logic to automatically reset the current page back to 1 whenever the playlistId changes.
  • UI Enhancement: Adds a smooth scroll-to-top behavior when switching playlists, improving the user experience.
  • React Hooks: Utilizes the useEffect hook to manage the side effect of resetting the page and scrolling when the playlist changes.

Changelog

  • ui/src/playlist/PlaylistSongs.jsx
    • Imported the useEffect hook (line 1).
    • Destructured setPage from the useListContext hook (line 87).
    • Added a useEffect hook that triggers on playlistId or setPage changes (lines 97-100).
    • Inside the useEffect, called setPage(1) to reset pagination (line 98).
    • Inside the useEffect, added window.scrollTo({ top: 0, behavior: 'smooth' }) to scroll to the top (line 99).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


Playlist changes fast,
Page one again, start anew,
Scrolls up, smooth and quick.

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
Contributor

@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 bug where navigating between playlists could lead to an empty page if the new playlist had fewer pages. Resetting the page to 1 and scrolling to the top upon playlist change is a solid solution. The code changes are clear, concise, and well-targeted. The PR description is also very helpful in understanding the problem and the fix.

Summary of Findings

  • Scroll-to-top Behavior Confirmation: The useEffect hook correctly includes window.scrollTo({ top: 0, behavior: 'smooth' }) to scroll to the top when the playlist changes and the page is reset. This generally enhances user experience. As noted in the PR description, this behavior is considered beneficial but potentially removable if undesirable in specific contexts. This point is of low severity, primarily serving as a reminder to ensure this global scroll behavior is confirmed as ideal across all potential use-cases of the PlaylistSongs component, especially if it might be embedded within layouts where scroll is managed differently by a parent component. Given the component's typical role as a main view, this is likely the intended and correct behavior. Per the review settings, a direct code comment was not added for this low-severity point, and no changes are strictly requested based on it.

Merge Readiness

The pull request is in good shape and addresses the reported issues effectively. The code is clean and the solution is straightforward. After considering the minor point mentioned in the findings summary (which is non-blocking), this PR should be ready for merging. As a reviewer, I cannot approve the pull request myself; please ensure it undergoes any further necessary reviews and approvals before merging.

@deluan
Copy link
Member

deluan commented May 30, 2025

Thanks!

@deluan deluan merged commit 11c9dd4 into navidrome:master May 30, 2025
31 checks passed
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.

Playlist switching doesn't reset pagination state
2 participants