Skip to content

Commit

Permalink
TF-3372 Handling error for empty trash failure
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdat committed Jan 2, 2025
1 parent 7b4f692 commit 2974ca1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/features/base/mixin/mailbox_action_handler_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mixin MailboxActionHandlerMixin {
..onConfirmAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id);
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id, totalEmails: mailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand All @@ -156,7 +156,7 @@ mixin MailboxActionHandlerMixin {
..onConfirmButtonAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id);
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id, totalEmails: mailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,12 +1396,14 @@ class MailboxDashBoardController extends ReloadableController
onCancelSelectionEmail?.call();

final trashMailboxId = trashFolderId ?? mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash];
final trashMailbox = mapMailboxById[trashMailboxId];
final totalEmailsInTrash = totalEmails == 0 ? trashMailbox?.countTotalEmails : totalEmails;
if (sessionCurrent != null && accountId.value != null && trashMailboxId != null) {
consumeState(_emptyTrashFolderInteractor.execute(
sessionCurrent!,
accountId.value!,
trashMailboxId,
totalEmails,
totalEmailsInTrash ?? 0,
_progressStateController
));
}
Expand Down Expand Up @@ -2458,7 +2460,7 @@ class MailboxDashBoardController extends ReloadableController
..onConfirmAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (spamMailbox.countTotalEmails > 0) {
emptySpamFolderAction(spamFolderId: spamMailbox.id);
emptySpamFolderAction(spamFolderId: spamMailbox.id, totalEmails: spamMailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand All @@ -2483,7 +2485,7 @@ class MailboxDashBoardController extends ReloadableController
..onConfirmButtonAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (spamMailbox.countTotalEmails > 0) {
emptySpamFolderAction(spamFolderId: spamMailbox.id);
emptySpamFolderAction(spamFolderId: spamMailbox.id, totalEmails: spamMailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin
padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin,
child: horizontalLoadingWidget);
} else if (success is UpdatingMarkAsMailboxReadState) {
final percent = success.countRead / success.totalUnread;
return _buildProgressBanner(percent);
return _buildProgressBanner(success.countRead, success.totalUnread);
} else if (success is EmptyingFolderState) {
final percent = success.countEmailsDeleted / success.totalEmails;
return _buildProgressBanner(percent);
return _buildProgressBanner(success.countEmailsDeleted, success.totalEmails);
} else {
return const SizedBox.shrink();
}
}
);
}

Padding _buildProgressBanner(double percent) {
Padding _buildProgressBanner(int progress, int total) {
final percent = total > 0 ? progress / total : 0.68;
return Padding(
padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin,
child: horizontalPercentLoadingWidget(percent)
Expand Down
6 changes: 3 additions & 3 deletions lib/features/thread/data/network/thread_isolate_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ThreadIsolateWorker {
fun1: _emptyMailboxFolderAction,
notification: (value) {
if (value is List<EmailId>) {
log('ThreadIsolateWorker::emptyMailboxFolder(): onUpdateProgress ${value.length / totalEmails}');
log('ThreadIsolateWorker::emptyMailboxFolder(): processed ${value.length} - totalEmails $totalEmails');
onProgressController.add(Right<Failure, Success>(EmptyingFolderState(
mailboxId, value.length, totalEmails
)));
Expand Down Expand Up @@ -120,7 +120,7 @@ class ThreadIsolateWorker {
args.accountId,
newEmailList.listEmailIds);
emailListCompleted.addAll(listEmailIdDeleted);
sendPort.send(listEmailIdDeleted);
sendPort.send(emailListCompleted);
} else {
hasEmails = false;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ class ThreadIsolateWorker {
emailListCompleted.addAll(listEmailIdDeleted);

onProgressController.add(Right<Failure, Success>(EmptyingFolderState(
mailboxId, listEmailIdDeleted.length, totalEmails
mailboxId, emailListCompleted.length, totalEmails
)));
} else {
hasEmails = false;
Expand Down
85 changes: 56 additions & 29 deletions lib/features/thread/presentation/thread_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
import 'package:flutter_portal/flutter_portal.dart';
import 'package:flutter_svg/flutter_svg.dart';
Expand Down Expand Up @@ -164,7 +165,7 @@ class ThreadView extends GetWidget<ThreadController>
}
}),
if (!controller.responsiveUtils.isDesktop(context))
_buildMarkAsMailboxReadLoading(context),
_buildMailboxActionProgressBanner(context),
Obx(() => ThreadViewLoadingBarWidget(viewState: controller.viewState.value)),
Expanded(
child: Container(
Expand Down Expand Up @@ -864,42 +865,68 @@ class ThreadView extends GetWidget<ThreadController>
);
}

Widget _buildMarkAsMailboxReadLoading(BuildContext context) {
Widget _buildMailboxActionProgressBanner(BuildContext context) {
return Obx(() {
final viewState = controller.mailboxDashBoardController.viewStateMailboxActionProgress.value;
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is MarkAsMailboxReadLoading
|| success is EmptySpamFolderLoading
|| success is EmptyTrashFolderLoading
) {
return Padding(
padding: EdgeInsets.only(
top: controller.responsiveUtils.isDesktop(context) ? 16 : 0,
left: 16,
right: 16,
bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16),
child: horizontalLoadingWidget);
} else if (success is UpdatingMarkAsMailboxReadState) {
final percent = success.countRead / success.totalUnread;
return _buildProgressBanner(context, percent);
} else if (success is EmptyingFolderState) {
final percent = success.countEmailsDeleted / success.totalEmails;
return _buildProgressBanner(context, percent);
}
return const SizedBox.shrink();
});
return _MailboxActionProgressBanner(
viewState: controller.mailboxDashBoardController.viewStateMailboxActionProgress.value,
responsiveUtils: controller.responsiveUtils,
);
});
}
}

class _MailboxActionProgressBanner extends StatelessWidget with AppLoaderMixin {
final Either<Failure, Success> viewState;
final ResponsiveUtils responsiveUtils;

const _MailboxActionProgressBanner({
required this.viewState,
required this.responsiveUtils,
});

@override
Widget build(BuildContext context) {
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is MarkAsMailboxReadLoading ||
success is EmptySpamFolderLoading ||
success is EmptyTrashFolderLoading) {
return Padding(
padding: EdgeInsets.only(
top: responsiveUtils.isDesktop(context) ? 16 : 0,
left: 16,
right: 16,
bottom: responsiveUtils.isDesktop(context) ? 0 : 16,
),
child: horizontalLoadingWidget,
);
} else if (success is UpdatingMarkAsMailboxReadState) {
return _buildProgressBanner(
context,
success.countRead,
success.totalUnread,
);
} else if (success is EmptyingFolderState) {
return _buildProgressBanner(
context,
success.countEmailsDeleted,
success.totalEmails,
);
}
return const SizedBox.shrink();
},
);
}

Padding _buildProgressBanner(BuildContext context, double percent) {
Padding _buildProgressBanner(BuildContext context, int progress, int total) {
final percent = total > 0 ? progress / total : 0.68;
return Padding(
padding: EdgeInsets.only(
top: controller.responsiveUtils.isDesktop(context) ? 16 : 0,
top: responsiveUtils.isDesktop(context) ? 16 : 0,
left: 16,
right: 16,
bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16),
bottom: responsiveUtils.isDesktop(context) ? 0 : 16),
child: horizontalPercentLoadingWidget(percent));
}
}
8 changes: 7 additions & 1 deletion lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2024-10-31T13:18:32.336494",
"@@last_modified": "2024-12-31T12:11:05.777668",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
Expand Down Expand Up @@ -3970,6 +3970,12 @@
"placeholders_order": [],
"placeholders": {}
},
"emptyTrashFolderFailed": "Empty trash folder failed",
"@emptyTrashFolderFailed": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"markAsSpamFailed": "Mark as spam failed",
"@markAsSpamFailed": {
"type": "text",
Expand Down
6 changes: 6 additions & 0 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,12 @@ class AppLocalizations {
name: 'emptySpamFolderFailed');
}

String get emptyTrashFolderFailed {
return Intl.message(
'Empty trash folder failed',
name: 'emptyTrashFolderFailed');
}

String get markAsSpamFailed {
return Intl.message(
'Mark as spam failed',
Expand Down
3 changes: 3 additions & 0 deletions lib/main/utils/toast_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_ex
import 'package:tmail_ui_user/features/starting_page/domain/state/sign_in_twake_workplace_state.dart';
import 'package:tmail_ui_user/features/starting_page/domain/state/sign_up_twake_workplace_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
Expand Down Expand Up @@ -63,6 +64,8 @@ class ToastManager {
?? AppLocalizations.of(currentContext!).unknownError;
} else if (failure is EmptySpamFolderFailure) {
message = AppLocalizations.of(currentContext!).emptySpamFolderFailed;
} else if (failure is EmptyTrashFolderFailure) {
message = AppLocalizations.of(currentContext!).emptyTrashFolderFailed;
} else if (failure is MoveMultipleEmailToMailboxFailure
&& failure.emailActionType == EmailActionType.moveToSpam
&& failure.moveAction == MoveAction.moving) {
Expand Down

0 comments on commit 2974ca1

Please sign in to comment.