refactor: rename to AlbumSortByOptions

This commit is contained in:
shalong-tanwen 2023-12-06 22:56:18 +05:30
parent 1ce65b39fb
commit 42731000cf
6 changed files with 29 additions and 28 deletions

View file

@ -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:immich_mobile/shared/models/album.dart';
import 'package:riverpod_annotation/riverpod_annotation.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<Album> Function(List<Album> albums, bool isReverse); typedef AlbumSortFn = List<Album> Function(List<Album> albums, bool isReverse);
@ -42,10 +42,10 @@ class _AlbumSortHandlers {
static const AlbumSortFn mostRecent = _sortByMostRecent; static const AlbumSortFn mostRecent = _sortByMostRecent;
static List<Album> _sortByMostRecent(List<Album> albums, bool isReverse) { static List<Album> _sortByMostRecent(List<Album> albums, bool isReverse) {
final sorted = albums final sorted = albums.where((a) => a.isRemote).sorted((a, b) {
.where((a) => a.isRemote) if (a.endDate != null && b.endDate != null) {
.sortedBy((album) => album.endDate ?? DateTime(1000)) return a.endDate!.compareTo(b.endDate!);
.sorted((a, b) { }
if (a.endDate == null) return 1; if (a.endDate == null) return 1;
if (b.endDate == null) return -1; if (b.endDate == null) return -1;
return 0; return 0;
@ -55,10 +55,10 @@ class _AlbumSortHandlers {
static const AlbumSortFn mostOldest = _sortByMostOldest; static const AlbumSortFn mostOldest = _sortByMostOldest;
static List<Album> _sortByMostOldest(List<Album> albums, bool isReverse) { static List<Album> _sortByMostOldest(List<Album> albums, bool isReverse) {
final sorted = albums final sorted = albums.where((a) => a.isRemote).sorted((a, b) {
.where((a) => a.isRemote) if (a.startDate != null && b.startDate != null) {
.sortedBy((album) => album.startDate ?? DateTime.now()) return a.startDate!.compareTo(b.startDate!);
.sorted((a, b) { }
if (a.startDate == null) return 1; if (a.startDate == null) return 1;
if (b.startDate == null) return -1; if (b.startDate == null) return -1;
return 0; return 0;
@ -96,7 +96,7 @@ enum AlbumSortMode {
} }
@riverpod @riverpod
class AlbumSortFunction extends _$AlbumSortFunction { class AlbumSortByOptions extends _$AlbumSortByOptions {
@override @override
AlbumSortMode build() { AlbumSortMode build() {
final sortOpt = ref final sortOpt = ref

View file

@ -1,27 +1,28 @@
// GENERATED CODE - DO NOT MODIFY BY HAND // GENERATED CODE - DO NOT MODIFY BY HAND
part of 'album_sort_options.provider.dart'; part of 'album_sort_by_options.provider.dart';
// ************************************************************************** // **************************************************************************
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$albumSortFunctionHash() => r'2758b7d6274a1adc51e554e99cd6725bd875140f'; String _$albumSortByOptionsHash() =>
r'8d22fa8b7cbca2d3d7ed20a83bf00211dc948004';
/// See also [AlbumSortFunction]. /// See also [AlbumSortByOptions].
@ProviderFor(AlbumSortFunction) @ProviderFor(AlbumSortByOptions)
final albumSortFunctionProvider = final albumSortByOptionsProvider =
AutoDisposeNotifierProvider<AlbumSortFunction, AlbumSortMode>.internal( AutoDisposeNotifierProvider<AlbumSortByOptions, AlbumSortMode>.internal(
AlbumSortFunction.new, AlbumSortByOptions.new,
name: r'albumSortFunctionProvider', name: r'albumSortByOptionsProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null ? null
: _$albumSortFunctionHash, : _$albumSortByOptionsHash,
dependencies: null, dependencies: null,
allTransitiveDependencies: null, allTransitiveDependencies: null,
); );
typedef _$AlbumSortFunction = AutoDisposeNotifier<AlbumSortMode>; typedef _$AlbumSortByOptions = AutoDisposeNotifier<AlbumSortMode>;
String _$albumSortOrderHash() => r'573dea45b4519e69386fc7104c72522e35713440'; String _$albumSortOrderHash() => r'573dea45b4519e69386fc7104c72522e35713440';
/// See also [AlbumSortOrder]. /// See also [AlbumSortOrder].

View file

@ -1,7 +1,7 @@
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.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/modules/album/ui/album_thumbnail_listtile.dart';
import 'package:immich_mobile/shared/models/album.dart'; import 'package:immich_mobile/shared/models/album.dart';
@ -22,7 +22,7 @@ class AddToAlbumSliverList extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final albumSortMode = ref.watch(albumSortFunctionProvider); final albumSortMode = ref.watch(albumSortByOptionsProvider);
final albumSortIsReverse = ref.watch(albumSortOrderProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider);
final sortedAlbums = albumSortMode.sortFn(albums, albumSortIsReverse); final sortedAlbums = albumSortMode.sortFn(albums, albumSortIsReverse);
final sortedSharedAlbums = final sortedSharedAlbums =

View file

@ -4,7 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.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.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/modules/album/ui/album_thumbnail_card.dart';
import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/providers/server_info.provider.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)); ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
final albums = ref.watch(albumProvider); final albums = ref.watch(albumProvider);
final isDarkTheme = context.isDarkTheme; final isDarkTheme = context.isDarkTheme;
final albumSortOption = ref.watch(albumSortFunctionProvider); final albumSortOption = ref.watch(albumSortByOptionsProvider);
final albumSortIsReverse = ref.watch(albumSortOrderProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider);
useEffect( useEffect(
@ -69,7 +69,7 @@ class LibraryPage extends HookConsumerWidget {
.read(albumSortOrderProvider.notifier) .read(albumSortOrderProvider.notifier)
.changeSortDirection(!albumSortIsReverse); .changeSortDirection(!albumSortIsReverse);
} else { } else {
ref.read(albumSortFunctionProvider.notifier).changeSortMode(value); ref.read(albumSortByOptionsProvider.notifier).changeSortMode(value);
} }
}, },
child: Row( child: Row(

View file

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/extensions/build_context_extensions.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/providers/shared_album.provider.dart';
import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart'; import 'package:immich_mobile/modules/album/ui/album_thumbnail_card.dart';
import 'package:immich_mobile/modules/partner/providers/partner.provider.dart'; import 'package:immich_mobile/modules/partner/providers/partner.provider.dart';
@ -18,7 +18,7 @@ class SharingPage extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final albumSortOption = ref.watch(albumSortFunctionProvider); final albumSortOption = ref.watch(albumSortByOptionsProvider);
final albumSortIsReverse = ref.watch(albumSortOrderProvider); final albumSortIsReverse = ref.watch(albumSortOrderProvider);
final albums = ref.watch(sharedAlbumProvider); final albums = ref.watch(sharedAlbumProvider);
final sharedAlbums = albumSortOption.sortFn(albums, albumSortIsReverse); final sharedAlbums = albumSortOption.sortFn(albums, albumSortIsReverse);

View file

@ -1,6 +1,6 @@
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter_test/flutter_test.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/album.dart';
import 'package:immich_mobile/shared/models/asset.dart'; import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/shared/models/user.dart'; import 'package:immich_mobile/shared/models/user.dart';