fix(playlists): keep imported playlist track order (#482)

Playlist tracks were read newest-first (added_at DESC, rowid DESC),
so a batch import - inserted in playlist order with one timestamp -
came back reversed, and the in-memory prepend matched that. Playlists
now use insertion order: snapshot reads ASC, single adds append, and
batch adds append in order. Existing rows were already stored in
playlist order, so old libraries display correctly without migration.
The preview-cover query follows the first visible track.
This commit is contained in:
zarzet
2026-07-14 09:09:53 +07:00
parent 9a205987ee
commit a287d6b815
2 changed files with 8 additions and 4 deletions
@@ -803,7 +803,7 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
final changed = _replacePlaylistById(playlistId, (playlist) {
if (playlist.containsTrackKey(key)) return playlist;
return playlist.copyWith(
tracks: [entry, ...playlist.tracks],
tracks: [...playlist.tracks, entry],
updatedAt: now,
);
});
@@ -864,7 +864,8 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
);
final changed = _replacePlaylistById(playlistId, (current) {
return current.copyWith(
tracks: [...entriesToAdd.reversed, ...current.tracks],
// Append in playlist order, matching the ASC snapshot ordering.
tracks: [...current.tracks, ...entriesToAdd],
updatedAt: now,
);
});