1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-28 06:32:44 +01:00

fix(mobile): do not removed not backup asset when selecting the correspond options ()

* fixed the local ids selecting issue

* code: updated impl inside deleteLocalOnlyAssets

* fix: used png instead of jpg to maintain picture quality

* Revert "fix: used png instead of jpg to maintain picture quality"

This reverts commit 04f2ed54e4.

* fix: update logic from code-review perspective

* refractor (mobile) : Dart fix applied

* fix (mobile) : Updated multi grid as per requirement

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Yashraj Jain 2024-11-01 19:33:03 +05:30 committed by GitHub
parent b9096f3e99
commit b95bc32310
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 5 deletions
mobile/lib
providers
widgets/asset_grid

View file

@ -84,34 +84,48 @@ class AssetNotifier extends StateNotifier<bool> {
_deleteInProgress = true; _deleteInProgress = true;
state = true; state = true;
try { try {
// Filter the assets based on the backed-up status
final assets = onlyBackedUp final assets = onlyBackedUp
? deleteAssets.where((e) => e.storage == AssetState.merged) ? deleteAssets.where((e) => e.storage == AssetState.merged)
: deleteAssets; : deleteAssets;
if (assets.isEmpty) {
return false; // No assets to delete
}
// Proceed with local deletion of the filtered assets
final localDeleted = await _deleteLocalAssets(assets); final localDeleted = await _deleteLocalAssets(assets);
if (localDeleted.isNotEmpty) { if (localDeleted.isNotEmpty) {
final localOnlyIds = deleteAssets final localOnlyIds = assets
.where((e) => e.storage == AssetState.local) .where((e) => e.storage == AssetState.local)
.map((e) => e.id) .map((e) => e.id)
.toList(); .toList();
// Update merged assets to remote only
// Update merged assets to remote-only
final mergedAssets = final mergedAssets =
deleteAssets.where((e) => e.storage == AssetState.merged).map((e) { assets.where((e) => e.storage == AssetState.merged).map((e) {
e.localId = null; e.localId = null;
return e; return e;
}).toList(); }).toList();
// Update the local database
await _db.writeTxn(() async { await _db.writeTxn(() async {
if (mergedAssets.isNotEmpty) { if (mergedAssets.isNotEmpty) {
await _db.assets.putAll(mergedAssets); await _db.assets
.putAll(mergedAssets); // Use the filtered merged assets
} }
await _db.exifInfos.deleteAll(localOnlyIds); await _db.exifInfos.deleteAll(localOnlyIds);
await _db.assets.deleteAll(localOnlyIds); await _db.assets.deleteAll(localOnlyIds);
}); });
return true; return true;
} }
} finally { } finally {
_deleteInProgress = false; _deleteInProgress = false;
state = false; state = false;
} }
return false; return false;
} }

View file

@ -203,18 +203,30 @@ class MultiselectGrid extends HookConsumerWidget {
void onDeleteLocal(bool onlyBackedUp) async { void onDeleteLocal(bool onlyBackedUp) async {
processing.value = true; processing.value = true;
try { try {
// Select only the local assets from the selection
final localIds = selection.value.where((a) => a.isLocal).toList(); final localIds = selection.value.where((a) => a.isLocal).toList();
// Delete only the backed-up assets if 'onlyBackedUp' is true
final isDeleted = await ref final isDeleted = await ref
.read(assetProvider.notifier) .read(assetProvider.notifier)
.deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp); .deleteLocalOnlyAssets(localIds, onlyBackedUp: onlyBackedUp);
if (isDeleted) { 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;
ImmichToast.show( ImmichToast.show(
context: context, context: context,
msg: 'assets_removed_permanently_from_device' msg: 'assets_removed_permanently_from_device'
.tr(args: ["${localIds.length}"]), .tr(args: ["$deletedCount"]),
gravity: ToastGravity.BOTTOM, gravity: ToastGravity.BOTTOM,
); );
// Reset the selection
selectionEnabledHook.value = false; selectionEnabledHook.value = false;
} }
} finally { } finally {