Skip to content

Conversation

CostelXD
Copy link
Contributor

@CostelXD CostelXD commented Mar 24, 2025

Resolves #473

Added functionality to sort items by alphabetical or recently added in the library page.

Copy link
Owner

@aome510 aome510 left a comment

Choose a reason for hiding this comment

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

the commands are awkward to use cause you need to focus the right window to initiate the command.

A better way might be defining sort commands for the whole library page. The order can be based on what available in the official app (maybe exclude Creator):

image

This also helps avoid confusion cause the command name/description implies users can use it to sort albums/playlists in other pages

@CostelXD
Copy link
Contributor Author

I have done this: ,,A better way might be defining sort commands for the whole library page. The order can be based on what available in the official app", but I can't sort exactly like in the app because the API doesn't provide sufficient information. I hope you find this helpful.

Copy link
Owner

@aome510 aome510 left a comment

Choose a reason for hiding this comment

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

thanks for updating. Looks much better

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think you need to change this file. The new field should be handled in the conversion functions defined in spotify_player/src/state/model.rs

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 had to change the way it converts from album because it was seen as FullAlbum and not as SavedAlbums, but in rest I reverted it back and migrated the logic to model.rs

data.user_data.playlists.sort_by(|a, b| {
match (a, b) {
(PlaylistFolderItem::Playlist(p1), PlaylistFolderItem::Playlist(p2)) => {
p1.snapshot_id.cmp(&p2.snapshot_id) // Sort ascending by `snapshot_id`
Copy link
Owner

Choose a reason for hiding this comment

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

I think the correct ordering logic for playlists is comparing current_folder_id and if two playlists are in different folder, sort them accordingly, e.g

if p1.current_folder_id != p2. current_folder_id {
  p1.current_folder_id.cmp(&p2.current_folder_id)
} else {
  p1.snapshot_id.cmp(&p2.snapshot_id)
}

@CostelXD
Copy link
Contributor Author

I tried implementing your suggestions. Tell me if it needs other changes. Thank you

Copy link
Owner

@aome510 aome510 left a comment

Choose a reason for hiding this comment

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

Thanks for updating, LGTM! I pushed a cleanup commit myself. Also update the keybinds to s l a and s l r for consistency with other commands.

@aome510 aome510 merged commit 3c2d26c into aome510:master Mar 30, 2025
5 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.

Library can only be sorted by "recently played"
2 participants