diff --git a/mobile/lib/modules/album/providers/album_sort_options.provider.dart b/mobile/lib/modules/album/providers/album_sort_by_options.provider.dart similarity index 89% rename from mobile/lib/modules/album/providers/album_sort_options.provider.dart rename to mobile/lib/modules/album/providers/album_sort_by_options.provider.dart index 49f86b23d..c335be48c 100644 --- a/mobile/lib/modules/album/providers/album_sort_options.provider.dart +++ b/mobile/lib/modules/album/providers/album_sort_by_options.provider.dart @@ -4,7 +4,7 @@ import 'package:immich_mobile/modules/settings/services/app_settings.service.dar import 'package:immich_mobile/shared/models/album.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; -part 'album_sort_options.provider.g.dart'; +part 'album_sort_by_options.provider.g.dart'; typedef AlbumSortFn = List Function(List albums, bool isReverse); @@ -42,10 +42,10 @@ class _AlbumSortHandlers { static const AlbumSortFn mostRecent = _sortByMostRecent; static List _sortByMostRecent(List albums, bool isReverse) { - final sorted = albums - .where((a) => a.isRemote) - .sortedBy((album) => album.endDate ?? DateTime(1000)) - .sorted((a, b) { + final sorted = albums.where((a) => a.isRemote).sorted((a, b) { + if (a.endDate != null && b.endDate != null) { + return a.endDate!.compareTo(b.endDate!); + } if (a.endDate == null) return 1; if (b.endDate == null) return -1; return 0; @@ -55,10 +55,10 @@ class _AlbumSortHandlers { static const AlbumSortFn mostOldest = _sortByMostOldest; static List _sortByMostOldest(List albums, bool isReverse) { - final sorted = albums - .where((a) => a.isRemote) - .sortedBy((album) => album.startDate ?? DateTime.now()) - .sorted((a, b) { + final sorted = albums.where((a) => a.isRemote).sorted((a, b) { + if (a.startDate != null && b.startDate != null) { + return a.startDate!.compareTo(b.startDate!); + } if (a.startDate == null) return 1; if (b.startDate == null) return -1; return 0; @@ -96,7 +96,7 @@ enum AlbumSortMode { } @riverpod -class AlbumSortFunction extends _$AlbumSortFunction { +class AlbumSortByOptions extends _$AlbumSortByOptions { @override AlbumSortMode build() { final sortOpt = ref diff --git a/mobile/lib/modules/album/providers/album_sort_options.provider.g.dart b/mobile/lib/modules/album/providers/album_sort_by_options.provider.g.dart similarity index 68% rename from mobile/lib/modules/album/providers/album_sort_options.provider.g.dart rename to mobile/lib/modules/album/providers/album_sort_by_options.provider.g.dart index ff852d055..d97057ebd 100644 --- a/mobile/lib/modules/album/providers/album_sort_options.provider.g.dart +++ b/mobile/lib/modules/album/providers/album_sort_by_options.provider.g.dart @@ -1,27 +1,28 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'album_sort_options.provider.dart'; +part of 'album_sort_by_options.provider.dart'; // ************************************************************************** // RiverpodGenerator // ************************************************************************** -String _$albumSortFunctionHash() => r'2758b7d6274a1adc51e554e99cd6725bd875140f'; +String _$albumSortByOptionsHash() => + r'8d22fa8b7cbca2d3d7ed20a83bf00211dc948004'; -/// See also [AlbumSortFunction]. -@ProviderFor(AlbumSortFunction) -final albumSortFunctionProvider = - AutoDisposeNotifierProvider.internal( - AlbumSortFunction.new, - name: r'albumSortFunctionProvider', +/// See also [AlbumSortByOptions]. +@ProviderFor(AlbumSortByOptions) +final albumSortByOptionsProvider = + AutoDisposeNotifierProvider.internal( + AlbumSortByOptions.new, + name: r'albumSortByOptionsProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') ? null - : _$albumSortFunctionHash, + : _$albumSortByOptionsHash, dependencies: null, allTransitiveDependencies: null, ); -typedef _$AlbumSortFunction = AutoDisposeNotifier; +typedef _$AlbumSortByOptions = AutoDisposeNotifier; String _$albumSortOrderHash() => r'573dea45b4519e69386fc7104c72522e35713440'; /// See also [AlbumSortOrder]. diff --git a/mobile/lib/modules/album/ui/add_to_album_sliverlist.dart b/mobile/lib/modules/album/ui/add_to_album_sliverlist.dart index caa798a90..d948afcd8 100644 --- a/mobile/lib/modules/album/ui/add_to_album_sliverlist.dart +++ b/mobile/lib/modules/album/ui/add_to_album_sliverlist.dart @@ -1,7 +1,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:immich_mobile/modules/album/providers/album_sort_options.provider.dart'; +import 'package:immich_mobile/modules/album/providers/album_sort_by_options.provider.dart'; import 'package:immich_mobile/modules/album/ui/album_thumbnail_listtile.dart'; import 'package:immich_mobile/shared/models/album.dart'; @@ -22,7 +22,7 @@ class AddToAlbumSliverList extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final albumSortMode = ref.watch(albumSortFunctionProvider); + final albumSortMode = ref.watch(albumSortByOptionsProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider); final sortedAlbums = albumSortMode.sortFn(albums, albumSortIsReverse); final sortedSharedAlbums = diff --git a/mobile/lib/modules/album/views/library_page.dart b/mobile/lib/modules/album/views/library_page.dart index ece57d139..413c53d40 100644 --- a/mobile/lib/modules/album/views/library_page.dart +++ b/mobile/lib/modules/album/views/library_page.dart @@ -4,7 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/extensions/build_context_extensions.dart'; import 'package:immich_mobile/modules/album/providers/album.provider.dart'; -import 'package:immich_mobile/modules/album/providers/album_sort_options.provider.dart'; +import 'package:immich_mobile/modules/album/providers/album_sort_by_options.provider.dart'; import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart'; import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/shared/providers/server_info.provider.dart'; @@ -19,7 +19,7 @@ class LibraryPage extends HookConsumerWidget { ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash)); final albums = ref.watch(albumProvider); final isDarkTheme = context.isDarkTheme; - final albumSortOption = ref.watch(albumSortFunctionProvider); + final albumSortOption = ref.watch(albumSortByOptionsProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider); useEffect( @@ -69,7 +69,7 @@ class LibraryPage extends HookConsumerWidget { .read(albumSortOrderProvider.notifier) .changeSortDirection(!albumSortIsReverse); } else { - ref.read(albumSortFunctionProvider.notifier).changeSortMode(value); + ref.read(albumSortByOptionsProvider.notifier).changeSortMode(value); } }, child: Row( diff --git a/mobile/lib/modules/album/views/sharing_page.dart b/mobile/lib/modules/album/views/sharing_page.dart index 0bc0feefa..9defb19bd 100644 --- a/mobile/lib/modules/album/views/sharing_page.dart +++ b/mobile/lib/modules/album/views/sharing_page.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/extensions/build_context_extensions.dart'; -import 'package:immich_mobile/modules/album/providers/album_sort_options.provider.dart'; +import 'package:immich_mobile/modules/album/providers/album_sort_by_options.provider.dart'; import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart'; import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart'; import 'package:immich_mobile/modules/partner/providers/partner.provider.dart'; @@ -18,7 +18,7 @@ class SharingPage extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final albumSortOption = ref.watch(albumSortFunctionProvider); + final albumSortOption = ref.watch(albumSortByOptionsProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider); final albums = ref.watch(sharedAlbumProvider); final sharedAlbums = albumSortOption.sortFn(albums, albumSortIsReverse); diff --git a/mobile/test/album_sort_options_provider_test.dart b/mobile/test/album_sort_by_options_provider_test.dart similarity index 99% rename from mobile/test/album_sort_options_provider_test.dart rename to mobile/test/album_sort_by_options_provider_test.dart index 8064f6d29..18efc5b42 100644 --- a/mobile/test/album_sort_options_provider_test.dart +++ b/mobile/test/album_sort_by_options_provider_test.dart @@ -1,6 +1,6 @@ import 'package:collection/collection.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:immich_mobile/modules/album/providers/album_sort_options.provider.dart'; +import 'package:immich_mobile/modules/album/providers/album_sort_by_options.provider.dart'; import 'package:immich_mobile/shared/models/album.dart'; import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/models/user.dart';