High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(mobile): decouple delete action messages from context (#31093)
Peter Ombodib94afdb46859
diff --git a/mobile/lib/presentation/actions/delete.action.dart b/mobile/lib/presentation/actions/delete.action.dartindex 9f2ca092f9..cfc1d0c794 100644--- a/mobile/lib/presentation/actions/delete.action.dart+++ b/mobile/lib/presentation/actions/delete.action.dart@@ -121,14 +121,11 @@ class DeleteAction extends AssetActionBuilder {required bool isLocalOnly,}) async {final assetService = ref.read(assetServiceProvider);+ final message = context.t.trash_action_prompt(count: remoteIds.length);if (localIds.isNotEmpty) {await _cleanupLocalAssets(context, ref, localIds, isLocalOnly: isLocalOnly);- if (!context.mounted) {- return null;- }}- final message = context.t.trash_action_prompt(count: remoteIds.length);await assetService.trash(remoteIds);return message;}diff --git a/mobile/test/unit/presentation/actions/delete_action_test.dart b/mobile/test/unit/presentation/actions/delete_action_test.dartindex d949e2ae55..df1d9f6e9b 100644--- a/mobile/test/unit/presentation/actions/delete_action_test.dart+++ b/mobile/test/unit/presentation/actions/delete_action_test.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';@@ -106,6 +108,36 @@ void main() {verify(() => assetService.trash([asset.id])).called(1);});+ testWidgets('finishes trashing when the action context is disposed during local cleanup', (tester) async {+ final asset = owned(localId: 'local');+ final cleanupResult = Completer<int>();+ when(() => cleanupService.deleteLocalAssets(['local'])).thenAnswer((_) => cleanupResult.future);+ var showAction = true;+ late StateSetter updateHost;++ await tester.pumpTestWidget(+ context,+ StatefulBuilder(+ builder: (_, setState) {+ updateHost = setState;+ return showAction+ ? const ActionIconButton(action: DeleteAction(source: .timeline))+ : const SizedBox.shrink();+ },+ ),+ overrides: context.selected({asset}),+ );++ await tester.tap(find.byType(ImmichIconButton));+ await tester.pump();+ updateHost(() => showAction = false);+ await tester.pump();+ cleanupResult.complete(1);+ await tester.pumpAndSettle();++ verify(() => assetService.trash([asset.id])).called(1);+ });+testWidgets('offers an undo that restores the trashed assets', (tester) async {final asset = owned();