Skip to content

Conversation

@LeLunZ
Copy link
Contributor

@LeLunZ LeLunZ commented Dec 23, 2025

Description

This PR improves the albums selector sorting logic and its visual representation to better match the behaviour of the web interface and to fix inconsistencies in the current mobile implementation.

Background / Problem

Previously, album sorting implicitly assumed a ascending default order for all sort modes. While this makes sense for modes like "Album Title" or "Oldest Photo", it leads to unintuitive behavior for others such as "Album Size" or "Most Recent".

In addition, there was a bug in the Oldest Photo sort mode:

  • The albums were sorted descending instead of ascending
  • This caused the order indicator to be misleading:
    • Arrow up showed newest → oldest (descending)
    • Arrow down showed oldest → newest (ascending)
  • If you go by the logic, arrow up means ascending. The currently implemented behaviour is not right.

What this PR changes

  • Introduces a defaultOrder for each AlbumSortMode
    • Each sort mode now explicitly defines whether its default order is ascending or descending.
    • This removes the assumption that all modes default to ascending.
    • Switching sort modes now results in a more intuitive initial order that matches the mode’s semantics.
  • Fixes the incorrect order indicator for “Oldest Photo”
    • The order indicator (arrow direction) now correctly reflects the actual sorting.
  • Improves sort order indicator logic
    • Previously, the UI assumed:
      • arrow up = isReverse == false
      • arrow down = isReverse == true
    • The indicator now reflects the effective sort order (asc / desc also in conjunction with the reverse flag) instead of relying on the reverse flag alone.
    • This keeps the UI consistent with the actual sort behavior.
  • Resets reverse ordering when switching sort modes
    • When selecting a different sort mode, the reverse state is set to false.
    • This makes switching modes more predictable for the end user.

Please let me know what you think about these changes :)
I myself don't like reflecting ascending/descending in the up/down arrow. But thats just how it's done in the web and I guess how it makes sense to memorise it.

How Has This Been Tested?

  • Clicking through the UI
  • new test in album.service_test.dart
    • should flip order when isReverse is true for all modes

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services/ uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services/)

Please describe to which degree, if any, an LLM was used in creating this pull request.

Partly to generate this documentation.

@immich-push-o-matic
Copy link

immich-push-o-matic bot commented Dec 23, 2025

Label error. Requires exactly 1 of: changelog:.*. Found: 📱mobile. A maintainer will add the required label.

@LeLunZ LeLunZ marked this pull request as ready for review December 23, 2025 23:31
Copilot AI review requested due to automatic review settings December 23, 2025 23:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the album sorting functionality by introducing explicit default sort orders for each sort mode and improving the UI indicators to accurately reflect the effective sort order. The changes address a bug where the "Oldest Photo" sort mode displayed misleading order indicators and ensures that switching between sort modes results in intuitive default behavior.

Key Changes:

  • Added defaultOrder field to AlbumSortMode enum specifying whether each mode defaults to ascending or descending order
  • Introduced effectiveOrder() method that calculates the actual sort order based on the default order and reverse flag
  • Updated album selector widget to reset the reverse flag when switching sort modes and display accurate order indicators

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mobile/lib/extensions/sort_order_extensions.dart Adds utility extension to get the opposite of a SortOrder value
mobile/lib/providers/album/album_sort_by_options.provider.dart Adds defaultOrder field to each AlbumSortMode and implements effectiveOrder method
mobile/lib/domain/services/remote_album.service.dart Updates sorting logic to use defaultOrder and effectiveOrder for consistent behavior
mobile/lib/presentation/widgets/album/album_selector.widget.dart Updates UI to reset reverse state on mode switch and display correct order indicators based on effectiveOrder
mobile/test/domain/services/album.service_test.dart Updates test expectations to match new default sort orders for each mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});

return sorted.reversed.toList();
return sorted.toList();
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

Inconsistency with return type. The _sortByNewestAsset method (line 195) returns sorted directly, which is an Iterable, while this method returns sorted.toList(), which is a List. For consistency, both methods should return List<RemoteAlbum>. Consider adding .toList() to line 195 as well.

Copilot uses AI. Check for mistakes.
AlbumSortMode sortMode, {
bool isReverse = false,
}) async {
// list of albums sorted ascendingly according to the selected sort mode
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The comment states "list of albums sorted ascendingly according to the selected sort mode", but this is misleading. For modes like mostRecent (which calls _sortByNewestAsset), the albums are indeed sorted in ascending order by their newest asset timestamp. However, the defaultOrder for mostRecent is desc, which means the list will be reversed by default to show the most recent albums first. Consider clarifying this comment to explain that the sorted list is in ascending order by the comparison key, and that the defaultOrder and isReverse logic is applied afterwards to determine the final order.

Suggested change
// list of albums sorted ascendingly according to the selected sort mode
// albums sorted in ascending order by the comparison key for the selected sort mode;
// defaultOrder and isReverse are applied below to determine the final returned order

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant