Skip to content

Commit 8b8de79

Browse files
committed
TF-2646 Improvement & optimize code when handle selection all emails
Signed-off-by: dab246 <[email protected]>
1 parent 0f3e5b2 commit 8b8de79

File tree

36 files changed

+639
-1195
lines changed

36 files changed

+639
-1195
lines changed

core/lib/presentation/utils/app_toast.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import 'package:core/presentation/views/toast/tmail_toast.dart';
55
import 'package:core/presentation/views/toast/toast_position.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter_svg/flutter_svg.dart';
8-
import 'package:get/get.dart';
98
import 'package:pointer_interceptor/pointer_interceptor.dart';
109

1110
class AppToast {
1211

12+
final ImagePaths imagePaths;
13+
final ResponsiveUtils responsiveUtils;
14+
15+
const AppToast(this.imagePaths, this.responsiveUtils);
16+
1317
void showToastErrorMessage(
1418
BuildContext context,
1519
String message,
@@ -19,7 +23,6 @@ class AppToast {
1923
Duration? duration,
2024
}
2125
) {
22-
final imagePaths = Get.find<ImagePaths>();
2326
showToastMessage(
2427
context,
2528
message,
@@ -40,7 +43,6 @@ class AppToast {
4043
Duration? duration,
4144
}
4245
) {
43-
final imagePaths = Get.find<ImagePaths>();
4446
showToastMessage(
4547
context,
4648
message,
@@ -61,7 +63,6 @@ class AppToast {
6163
Duration? duration,
6264
}
6365
) {
64-
final imagePaths = Get.find<ImagePaths>();
6566
showToastMessage(
6667
context,
6768
message,
@@ -94,7 +95,6 @@ class AppToast {
9495
Duration? duration,
9596
}
9697
) {
97-
final responsiveUtils = Get.find<ResponsiveUtils>();
9898
Widget? trailingWidget;
9999
if (actionName != null) {
100100
if (actionIcon == null) {

lib/features/base/reloadable/reloadable_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ abstract class ReloadableController extends BaseController {
127127

128128
void handleGetSessionFailure(GetSessionFailure failure) {
129129
if (failure.exception is! BadCredentialsException) {
130-
toastManager.showMessageFailure(failure);
130+
toastManager.show(failure);
131131
}
132132
clearDataAndGoToLoginPage();
133133
}

lib/features/email/data/network/email_api.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ class EmailAPI with HandleSetErrorMixin {
10131013
}
10141014
}
10151015

1016-
Future<List<EmailId>> moveSelectionAllEmailsToFolder(
1016+
Future<(List<EmailId> emailIds, Map<Id, SetError> mapErrors)> moveSelectionAllEmailsToFolder(
10171017
Session session,
10181018
AccountId accountId,
10191019
MailboxId currentMailboxId,
@@ -1042,17 +1042,17 @@ class EmailAPI with HandleSetErrorMixin {
10421042

10431043
final setEmailResponse = response.parse<SetEmailResponse>(
10441044
setEmailInvocation.methodCallId,
1045-
SetEmailResponse.deserialize
1045+
SetEmailResponse.deserialize,
10461046
);
10471047

1048-
final listIdUpdated = setEmailResponse?.updated?.keys.toList();
1048+
final updatedEmailIds = setEmailResponse
1049+
?.updated
1050+
?.keys
1051+
.toEmailIds()
1052+
.toList() ?? [];
1053+
10491054
final mapErrors = handleSetResponse([setEmailResponse]);
10501055

1051-
if (listIdUpdated != null && mapErrors.isEmpty) {
1052-
final listEmailIdUpdated = listIdUpdated.map((id) => EmailId(id)).toList();
1053-
return listEmailIdUpdated;
1054-
} else {
1055-
throw SetMethodException(mapErrors);
1056-
}
1056+
return (updatedEmailIds, mapErrors);
10571057
}
10581058
}

lib/features/email/presentation/controller/single_email_controller.dart

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
328328
} else if (failure is CalendarEventReplyFailure
329329
|| failure is StoreEventAttendanceStatusFailure) {
330330
_calendarEventFailure(failure);
331-
} else if (failure is ParseEmailByBlobIdFailure) {
332-
_handleParseEmailByBlobIdFailure(failure);
333-
} else if (failure is PreviewEmailFromEmlFileFailure) {
334-
_handlePreviewEmailFromEMLFileFailure(failure);
331+
} else if (failure is PreviewEmailFromEmlFileFailure
332+
|| failure is PreviewPDFFileFailure
333+
|| failure is ParseEmailByBlobIdFailure
334+
) {
335+
SmartDialog.dismiss();
336+
toastManager.show(failure);
335337
} else if (failure is GetHtmlContentFromAttachmentFailure) {
336338
_handleGetHtmlContentFromAttachmentFailure(failure);
337-
} else if (failure is PreviewPDFFileFailure) {
338-
_handlePreviewPDFFileFailure(failure);
339339
}
340340
}
341341

@@ -2328,21 +2328,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
23282328
}
23292329
}
23302330

2331-
void _handleParseEmailByBlobIdFailure(ParseEmailByBlobIdFailure failure) {
2332-
SmartDialog.dismiss();
2333-
toastManager.showMessageFailure(failure);
2334-
}
2335-
2336-
void _handlePreviewPDFFileFailure(PreviewPDFFileFailure failure) {
2337-
SmartDialog.dismiss();
2338-
toastManager.showMessageFailure(failure);
2339-
}
2340-
2341-
void _handlePreviewEmailFromEMLFileFailure(PreviewEmailFromEmlFileFailure failure) {
2342-
SmartDialog.dismiss();
2343-
toastManager.showMessageFailure(failure);
2344-
}
2345-
23462331
void _handlePreviewEmailFromEMLFileSuccess(PreviewEmailFromEmlFileSuccess success) {
23472332
SmartDialog.dismiss();
23482333

@@ -2355,11 +2340,11 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
23552340
);
23562341

23572342
if (!isOpen) {
2358-
toastManager.showMessageFailure(PreviewEmailFromEmlFileFailure(CannotOpenNewWindowException()));
2343+
toastManager.show(PreviewEmailFromEmlFileFailure(CannotOpenNewWindowException()));
23592344
}
23602345
} else if (PlatformInfo.isMobile) {
23612346
if (currentContext == null) {
2362-
toastManager.showMessageFailure(PreviewEmailFromEmlFileFailure(NotFoundContextException()));
2347+
toastManager.show(PreviewEmailFromEmlFileFailure(NotFoundContextException()));
23632348
return;
23642349
}
23652350

lib/features/login/presentation/widgets/login_message_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class LoginMessageWidget extends StatelessWidget {
5454
} else if (failure is GetTokenOIDCFailure && failure.exception is NoSuitableBrowserForOIDCException) {
5555
return AppLocalizations.of(context).noSuitableBrowserForOIDC;
5656
} else if (failure is FeatureFailure) {
57-
return _toastManager?.getMessageByException(context, failure.exception)
57+
return _toastManager?.getMessageByException(AppLocalizations.of(context), failure.exception)
5858
?? AppLocalizations.of(context).unknownError;
5959
} else {
6060
return AppLocalizations.of(context).unknownError;

lib/features/mailbox/domain/exceptions/mailbox_exception.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
class NotFoundInboxMailboxException implements Exception {}
33

44
class NotFoundMailboxException implements Exception {}
5+
6+
class NotFoundTrashMailboxException implements Exception {}

lib/features/mailbox/presentation/mailbox_view_web.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:tmail_ui_user/features/mailbox/presentation/widgets/app_grid_vie
1414
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/mailbox_item_widget.dart';
1515
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/mailbox_loading_bar_widget.dart';
1616
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/user_information_widget.dart';
17+
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/handle_action_for_select_all_emails_extension.dart';
1718
import 'package:tmail_ui_user/features/quotas/presentation/quotas_view.dart';
1819
import 'package:tmail_ui_user/features/quotas/presentation/styles/quotas_view_styles.dart';
1920
import 'package:tmail_ui_user/features/thread/presentation/model/draggable_email_data.dart';

0 commit comments

Comments
 (0)