mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 06:31:58 +00:00
fix(mobile): album most recent sorting on mobile (#13766)
* Fix album most recent sorting on mobile * fix: format * fix: format --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
ba9b9353bc
commit
411878c0aa
3 changed files with 87 additions and 17 deletions
|
@ -39,12 +39,21 @@ class _AlbumSortHandlers {
|
|||
static const AlbumSortFn mostRecent = _sortByMostRecent;
|
||||
static List<Album> _sortByMostRecent(List<Album> albums, bool isReverse) {
|
||||
final sorted = albums.sorted((a, b) {
|
||||
if (a.endDate != null && b.endDate != null) {
|
||||
return a.endDate!.compareTo(b.endDate!);
|
||||
if (a.endDate == null && b.endDate == null) {
|
||||
return 0;
|
||||
}
|
||||
if (a.endDate == null) return 1;
|
||||
if (b.endDate == null) return -1;
|
||||
return 0;
|
||||
|
||||
if (a.endDate == null) {
|
||||
// Put nulls at the end for recent sorting
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (b.endDate == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Sort by descending recent date
|
||||
return b.endDate!.compareTo(a.endDate!);
|
||||
});
|
||||
return (isReverse ? sorted.reversed : sorted).toList();
|
||||
}
|
||||
|
|
45
mobile/test/fixtures/album.stub.dart
vendored
45
mobile/test/fixtures/album.stub.dart
vendored
|
@ -54,4 +54,49 @@ final class AlbumStub {
|
|||
..assets.addAll([AssetStub.image1, AssetStub.image2])
|
||||
..activityEnabled = true
|
||||
..owner.value = UserStub.admin;
|
||||
|
||||
static final create2020end2020Album = Album(
|
||||
name: "create2020update2020Album",
|
||||
localId: "create2020update2020Album-local",
|
||||
remoteId: "create2020update2020Album-remote",
|
||||
createdAt: DateTime(2020),
|
||||
modifiedAt: DateTime(2020),
|
||||
shared: false,
|
||||
activityEnabled: false,
|
||||
startDate: DateTime(2020),
|
||||
endDate: DateTime(2020),
|
||||
);
|
||||
static final create2020end2022Album = Album(
|
||||
name: "create2020update2021Album",
|
||||
localId: "create2020update2021Album-local",
|
||||
remoteId: "create2020update2021Album-remote",
|
||||
createdAt: DateTime(2020),
|
||||
modifiedAt: DateTime(2022),
|
||||
shared: false,
|
||||
activityEnabled: false,
|
||||
startDate: DateTime(2020),
|
||||
endDate: DateTime(2022),
|
||||
);
|
||||
static final create2020end2024Album = Album(
|
||||
name: "create2020update2022Album",
|
||||
localId: "create2020update2022Album-local",
|
||||
remoteId: "create2020update2022Album-remote",
|
||||
createdAt: DateTime(2020),
|
||||
modifiedAt: DateTime(2024),
|
||||
shared: false,
|
||||
activityEnabled: false,
|
||||
startDate: DateTime(2020),
|
||||
endDate: DateTime(2024),
|
||||
);
|
||||
static final create2020end2026Album = Album(
|
||||
name: "create2020update2023Album",
|
||||
localId: "create2020update2023Album-local",
|
||||
remoteId: "create2020update2023Album-remote",
|
||||
createdAt: DateTime(2020),
|
||||
modifiedAt: DateTime(2026),
|
||||
shared: false,
|
||||
activityEnabled: false,
|
||||
startDate: DateTime(2020),
|
||||
endDate: DateTime(2026),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -147,24 +147,40 @@ void main() {
|
|||
group("Album sort - Most Recent", () {
|
||||
const mostRecent = AlbumSortMode.mostRecent;
|
||||
|
||||
test("Most Recent - ASC", () {
|
||||
final sorted = mostRecent.sortFn(albums, false);
|
||||
test("Most Recent - DESC", () {
|
||||
final sorted = mostRecent.sortFn(
|
||||
[
|
||||
AlbumStub.create2020end2020Album,
|
||||
AlbumStub.create2020end2022Album,
|
||||
AlbumStub.create2020end2024Album,
|
||||
AlbumStub.create2020end2026Album,
|
||||
],
|
||||
false,
|
||||
);
|
||||
final sortedList = [
|
||||
AlbumStub.sharedWithUser,
|
||||
AlbumStub.twoAsset,
|
||||
AlbumStub.oneAsset,
|
||||
AlbumStub.emptyAlbum,
|
||||
AlbumStub.create2020end2026Album,
|
||||
AlbumStub.create2020end2024Album,
|
||||
AlbumStub.create2020end2022Album,
|
||||
AlbumStub.create2020end2020Album,
|
||||
];
|
||||
expect(sorted, orderedEquals(sortedList));
|
||||
});
|
||||
|
||||
test("Most Recent - DESC", () {
|
||||
final sorted = mostRecent.sortFn(albums, true);
|
||||
test("Most Recent - ASC", () {
|
||||
final sorted = mostRecent.sortFn(
|
||||
[
|
||||
AlbumStub.create2020end2020Album,
|
||||
AlbumStub.create2020end2022Album,
|
||||
AlbumStub.create2020end2024Album,
|
||||
AlbumStub.create2020end2026Album,
|
||||
],
|
||||
true,
|
||||
);
|
||||
final sortedList = [
|
||||
AlbumStub.emptyAlbum,
|
||||
AlbumStub.oneAsset,
|
||||
AlbumStub.twoAsset,
|
||||
AlbumStub.sharedWithUser,
|
||||
AlbumStub.create2020end2020Album,
|
||||
AlbumStub.create2020end2022Album,
|
||||
AlbumStub.create2020end2024Album,
|
||||
AlbumStub.create2020end2026Album,
|
||||
];
|
||||
expect(sorted, orderedEquals(sortedList));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue