Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_bu
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.state.dart';
import 'package:immich_mobile/providers/infrastructure/action.provider.dart';
import 'package:immich_mobile/providers/timeline/multiselect.provider.dart';
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
import 'package:immich_mobile/widgets/common/immich_toast.dart';

/// This delete action has the following behavior:
Expand All @@ -23,17 +22,11 @@ class DeleteLocalActionButton extends ConsumerWidget {
return;
}

bool? backedUpOnly = await showDialog<bool>(
context: context,
builder: (BuildContext context) => DeleteLocalOnlyDialog(onDeleteLocal: (_) {}),
);

if (backedUpOnly == null) {
// User cancelled the dialog
final result = await ref.read(actionProvider.notifier).deleteLocal(source, context);
if (result == null) {
return;
}

final result = await ref.read(actionProvider.notifier).deleteLocal(source, backedUpOnly);
ref.read(multiSelectProvider.notifier).reset();

if (source == ActionSource.viewer) {
Expand Down
18 changes: 16 additions & 2 deletions mobile/lib/providers/infrastructure/action.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:immich_mobile/services/action.service.dart';
import 'package:immich_mobile/services/download.service.dart';
import 'package:immich_mobile/services/timeline.service.dart';
import 'package:immich_mobile/services/upload.service.dart';
import 'package:immich_mobile/widgets/asset_grid/delete_dialog.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand Down Expand Up @@ -260,10 +261,23 @@ class ActionNotifier extends Notifier<void> {
}
}

Future<ActionResult> deleteLocal(ActionSource source, bool backedUpOnly) async {
Future<ActionResult?> deleteLocal(ActionSource source, BuildContext context) async {
// Always perform the operation if there is only one merged asset
final assets = _getAssets(source);
bool? backedUpOnly = assets.length == 1 && assets.first.storage == AssetState.merged
? true
: await showDialog<bool>(
context: context,
builder: (BuildContext context) => DeleteLocalOnlyDialog(onDeleteLocal: (_) {}),
);

if (backedUpOnly == null) {
// User cancelled the dialog
return null;
}

final List<String> ids;
if (backedUpOnly) {
final assets = _getAssets(source);
ids = assets.where((asset) => asset.storage == AssetState.merged).map((asset) => asset.localId!).toList();
} else {
ids = _getLocalIdsForSource(source);
Expand Down
Loading