1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-09 23:17:29 +02:00

refactor(mobile): asset stack provider (#16100)

* refactor(mobile): asset stack provider

* remove file from ignore list
This commit is contained in:
Alex
2025-02-14 13:23:14 -06:00
committed by GitHub
parent 8ab87a8803
commit 47203d2760
6 changed files with 33 additions and 23 deletions

View File

@@ -1,16 +1,15 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/providers/db.provider.dart';
import 'package:isar/isar.dart';
import 'package:immich_mobile/services/asset.service.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'asset_stack.provider.g.dart';
class AssetStackNotifier extends StateNotifier<List<Asset>> {
final AssetService assetService;
final String _stackId;
final Ref _ref;
AssetStackNotifier(this._stackId, this._ref) : super([]) {
AssetStackNotifier(this.assetService, this._stackId) : super([]) {
_fetchStack(_stackId);
}
@@ -19,7 +18,7 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
return;
}
final stack = await _ref.read(assetStackProvider(stackId).future);
final stack = await assetService.getStackAssets(stackId);
if (stack.isNotEmpty) {
state = stack;
}
@@ -35,24 +34,10 @@ class AssetStackNotifier extends StateNotifier<List<Asset>> {
final assetStackStateProvider = StateNotifierProvider.autoDispose
.family<AssetStackNotifier, List<Asset>, String>(
(ref, stackId) => AssetStackNotifier(stackId, ref),
(ref, stackId) =>
AssetStackNotifier(ref.watch(assetServiceProvider), stackId),
);
final assetStackProvider =
FutureProvider.autoDispose.family<List<Asset>, String>((ref, stackId) {
return ref
.watch(dbProvider)
.assets
.filter()
.isArchivedEqualTo(false)
.isTrashedEqualTo(false)
.stackIdEqualTo(stackId)
// orders primary asset first as its ID is null
.sortByStackPrimaryAssetId()
.thenByFileCreatedAtDesc()
.findAll();
});
@riverpod
int assetStackIndex(AssetStackIndexRef ref, Asset asset) {
return -1;