mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor(mobile): asset provider (#16159)
* refactor(mobile): asset provider * wip * wip: delete local assets * wip: delete remote assets * wip: deletion logic * refactor * pr feedback
This commit is contained in:
parent
70d08a2b2a
commit
9d4aee36e2
24 changed files with 326 additions and 299 deletions
|
|
@ -200,24 +200,26 @@ class MultiselectGrid extends HookConsumerWidget {
|
|||
}
|
||||
}
|
||||
|
||||
void onDeleteLocal(bool onlyBackedUp) async {
|
||||
void onDeleteLocal(bool isMergedAsset) async {
|
||||
processing.value = true;
|
||||
try {
|
||||
// Select only the local assets from the selection
|
||||
final localIds = selection.value.where((a) => a.isLocal).toList();
|
||||
final localAssets = selection.value.where((a) => a.isLocal).toList();
|
||||
|
||||
final toDelete = isMergedAsset
|
||||
? localAssets.where((e) => e.storage == AssetState.merged)
|
||||
: localAssets;
|
||||
|
||||
if (toDelete.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete only the backed-up assets if 'onlyBackedUp' is true
|
||||
final isDeleted = await ref
|
||||
.read(assetProvider.notifier)
|
||||
.deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp);
|
||||
.deleteLocalAssets(toDelete.toList());
|
||||
|
||||
if (isDeleted) {
|
||||
// Show a toast with the correct number of deleted assets
|
||||
final deletedCount = localIds
|
||||
.where(
|
||||
(e) => !onlyBackedUp || e.isRemote,
|
||||
) // Only count backed-up assets
|
||||
.length;
|
||||
final deletedCount =
|
||||
localAssets.where((e) => !isMergedAsset || e.isRemote).length;
|
||||
|
||||
ImmichToast.show(
|
||||
context: context,
|
||||
|
|
@ -226,7 +228,6 @@ class MultiselectGrid extends HookConsumerWidget {
|
|||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
|
||||
// Reset the selection
|
||||
selectionEnabledHook.value = false;
|
||||
}
|
||||
} finally {
|
||||
|
|
@ -234,7 +235,7 @@ class MultiselectGrid extends HookConsumerWidget {
|
|||
}
|
||||
}
|
||||
|
||||
void onDeleteRemote([bool force = false]) async {
|
||||
void onDeleteRemote([bool shouldDeletePermanently = false]) async {
|
||||
processing.value = true;
|
||||
try {
|
||||
final toDelete = ownedRemoteSelection(
|
||||
|
|
@ -242,13 +243,15 @@ class MultiselectGrid extends HookConsumerWidget {
|
|||
ownerErrorMessage: 'home_page_delete_err_partner'.tr(),
|
||||
).toList();
|
||||
|
||||
final isDeleted = await ref
|
||||
.read(assetProvider.notifier)
|
||||
.deleteRemoteOnlyAssets(toDelete, force: force);
|
||||
final isDeleted =
|
||||
await ref.read(assetProvider.notifier).deleteRemoteAssets(
|
||||
toDelete,
|
||||
shouldDeletePermanently: shouldDeletePermanently,
|
||||
);
|
||||
if (isDeleted) {
|
||||
ImmichToast.show(
|
||||
context: context,
|
||||
msg: force
|
||||
msg: shouldDeletePermanently
|
||||
? 'assets_deleted_permanently_from_server'
|
||||
.tr(args: ["${toDelete.length}"])
|
||||
: 'assets_trashed_from_server'.tr(args: ["${toDelete.length}"]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue