mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
fix(mobile): asset state when delete from trash (#6476)
* fix(mobile): handle asset removal state from trash for merged assets * fix(mobile): use appropriate text for trash / delete --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
660b2e908d
commit
04c783f2f0
4 changed files with 47 additions and 14 deletions
|
@ -142,8 +142,9 @@
|
||||||
"control_bottom_app_bar_archive": "Archive",
|
"control_bottom_app_bar_archive": "Archive",
|
||||||
"control_bottom_app_bar_create_new_album": "Create new album",
|
"control_bottom_app_bar_create_new_album": "Create new album",
|
||||||
"control_bottom_app_bar_delete_from_immich": "Delete from Immich",
|
"control_bottom_app_bar_delete_from_immich": "Delete from Immich",
|
||||||
|
"control_bottom_app_bar_trash_from_immich": "Move to Trash",
|
||||||
"control_bottom_app_bar_delete_from_local": "Delete from device",
|
"control_bottom_app_bar_delete_from_local": "Delete from device",
|
||||||
"control_bottom_app_bar_delete": "Delete Everywhere",
|
"control_bottom_app_bar_delete": "Remove Everywhere",
|
||||||
"control_bottom_app_bar_edit_location": "Edit Location",
|
"control_bottom_app_bar_edit_location": "Edit Location",
|
||||||
"control_bottom_app_bar_edit_time": "Edit Date & Time",
|
"control_bottom_app_bar_edit_time": "Edit Date & Time",
|
||||||
"control_bottom_app_bar_favorite": "Favorite",
|
"control_bottom_app_bar_favorite": "Favorite",
|
||||||
|
|
|
@ -122,7 +122,9 @@ class ControlBottomAppBar extends ConsumerWidget {
|
||||||
constraints: const BoxConstraints(maxWidth: 85),
|
constraints: const BoxConstraints(maxWidth: 85),
|
||||||
child: ControlBoxButton(
|
child: ControlBoxButton(
|
||||||
iconData: Icons.cloud_off_outlined,
|
iconData: Icons.cloud_off_outlined,
|
||||||
label: "control_bottom_app_bar_delete_from_immich".tr(),
|
label: trashEnabled
|
||||||
|
? "control_bottom_app_bar_trash_from_immich".tr()
|
||||||
|
: "control_bottom_app_bar_delete_from_immich".tr(),
|
||||||
onPressed: enabled
|
onPressed: enabled
|
||||||
? () => handleRemoteDelete(
|
? () => handleRemoteDelete(
|
||||||
!trashEnabled,
|
!trashEnabled,
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
||||||
import 'package:immich_mobile/modules/trash/services/trash.service.dart';
|
import 'package:immich_mobile/modules/trash/services/trash.service.dart';
|
||||||
import 'package:immich_mobile/shared/models/asset.dart';
|
import 'package:immich_mobile/shared/models/asset.dart';
|
||||||
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
||||||
import 'package:immich_mobile/shared/providers/db.provider.dart';
|
import 'package:immich_mobile/shared/providers/db.provider.dart';
|
||||||
import 'package:immich_mobile/shared/providers/user.provider.dart';
|
import 'package:immich_mobile/shared/providers/user.provider.dart';
|
||||||
import 'package:immich_mobile/shared/services/sync.service.dart';
|
import 'package:immich_mobile/shared/services/sync.service.dart';
|
||||||
|
@ -47,6 +48,33 @@ class TrashNotifier extends StateNotifier<bool> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> removeAssets(Iterable<Asset> assetList) async {
|
||||||
|
try {
|
||||||
|
final user = _ref.read(currentUserProvider);
|
||||||
|
if (user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final isRemoved = await _ref
|
||||||
|
.read(assetProvider.notifier)
|
||||||
|
.deleteRemoteOnlyAssets(assetList, force: true);
|
||||||
|
|
||||||
|
if (isRemoved) {
|
||||||
|
final idsToRemove =
|
||||||
|
assetList.where((a) => a.isRemote).map((a) => a.remoteId!).toList();
|
||||||
|
|
||||||
|
_ref
|
||||||
|
.read(syncServiceProvider)
|
||||||
|
.handleRemoteAssetRemoval(idsToRemove.cast<String>().toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return isRemoved;
|
||||||
|
} catch (error, stack) {
|
||||||
|
_log.severe("Cannot empty trash ${error.toString()}", error, stack);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> restoreAssets(Iterable<Asset> assetList) async {
|
Future<bool> restoreAssets(Iterable<Asset> assetList) async {
|
||||||
try {
|
try {
|
||||||
final result = await _trashService.restoreAssets(assetList);
|
final result = await _trashService.restoreAssets(assetList);
|
||||||
|
|
|
@ -10,7 +10,6 @@ import 'package:immich_mobile/modules/home/ui/asset_grid/immich_asset_grid.dart'
|
||||||
import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
|
import 'package:immich_mobile/modules/home/ui/delete_dialog.dart';
|
||||||
import 'package:immich_mobile/modules/trash/providers/trashed_asset.provider.dart';
|
import 'package:immich_mobile/modules/trash/providers/trashed_asset.provider.dart';
|
||||||
import 'package:immich_mobile/shared/models/asset.dart';
|
import 'package:immich_mobile/shared/models/asset.dart';
|
||||||
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
|
||||||
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
||||||
import 'package:immich_mobile/shared/ui/confirm_dialog.dart';
|
import 'package:immich_mobile/shared/ui/confirm_dialog.dart';
|
||||||
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
||||||
|
@ -67,11 +66,13 @@ class TrashPage extends HookConsumerWidget {
|
||||||
processing.value = true;
|
processing.value = true;
|
||||||
try {
|
try {
|
||||||
if (selection.value.isNotEmpty) {
|
if (selection.value.isNotEmpty) {
|
||||||
await ref
|
final isRemoved = await ref
|
||||||
.read(assetProvider.notifier)
|
.read(trashProvider.notifier)
|
||||||
.deleteAssets(selection.value, force: true);
|
.removeAssets(selection.value);
|
||||||
|
|
||||||
final assetOrAssets = selection.value.length > 1 ? 'assets' : 'asset';
|
if (isRemoved) {
|
||||||
|
final assetOrAssets =
|
||||||
|
selection.value.length > 1 ? 'assets' : 'asset';
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -81,6 +82,7 @@ class TrashPage extends HookConsumerWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
processing.value = false;
|
processing.value = false;
|
||||||
selectionEnabledHook.value = false;
|
selectionEnabledHook.value = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue