Skip to content

Commit

Permalink
TF-3372 Handle Empty mailbox success + failure states
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdat committed Dec 30, 2024
1 parent 3efd2ac commit 83f1c02
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 23 deletions.
10 changes: 8 additions & 2 deletions lib/features/base/mixin/mailbox_action_handler_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ mixin MailboxActionHandlerMixin {
..onConfirmAction(AppLocalizations.of(context).delete, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptyTrashFolderAction(trashFolderId: mailbox.id);
dashboardController.emptyTrashFolderAction(
trashFolderId: mailbox.id,
totalEmails: mailbox.countTotalEmails
);
} else {
appToast.showToastWarningMessage(
context,
Expand All @@ -89,7 +92,10 @@ mixin MailboxActionHandlerMixin {
..onConfirmButtonAction(AppLocalizations.of(context).delete, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptyTrashFolderAction(trashFolderId: mailbox.id);
dashboardController.emptyTrashFolderAction(
trashFolderId: mailbox.id,
totalEmails: mailbox.countTotalEmails,
);
} else {
appToast.showToastWarningMessage(
context,
Expand Down
4 changes: 2 additions & 2 deletions lib/features/mailbox/data/network/mailbox_isolate_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_comparator.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_comparator_property.dart';
Expand Down Expand Up @@ -69,7 +69,7 @@ class MailboxIsolateWorker {
),
fun1: _handleMarkAsMailboxReadAction,
notification: (value) {
if (value is List<Email>) {
if (value is List<EmailId>) {
log('MailboxIsolateWorker::markAsMailboxRead(): onUpdateProgress: PERCENT ${value.length / totalEmailUnread}');
onProgressController.add(Right(UpdatingMarkAsMailboxReadState(
mailboxId: mailboxId,
Expand Down
10 changes: 8 additions & 2 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1359,9 +1359,15 @@ class MailboxController extends BaseMailboxController
void emptyMailboxAction(BuildContext context, PresentationMailbox presentationMailbox) {
log('MailboxController::emptyMailboxAction:presentationMailbox: ${presentationMailbox.name}');
if (presentationMailbox.isTrash) {
mailboxDashBoardController.emptyTrashFolderAction(trashFolderId: presentationMailbox.id);
mailboxDashBoardController.emptyTrashFolderAction(
trashFolderId: presentationMailbox.id,
totalEmails: presentationMailbox.countTotalEmails
);
} else if (presentationMailbox.isSpam) {
mailboxDashBoardController.emptySpamFolderAction(spamFolderId: presentationMailbox.id);
mailboxDashBoardController.emptySpamFolderAction(
spamFolderId: presentationMailbox.id,
totalEmails: presentationMailbox.countTotalEmails
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,11 @@ class MailboxDashBoardController extends ReloadableController
_handleRestoreDeletedMessageFailed();
} else if (failure is GetRestoredDeletedMessageFailure) {
_handleRestoreDeletedMessageFailed();
} else if (failure is EmptySpamFolderFailure
|| failure is MoveMultipleEmailToMailboxFailure) {
} else if (failure is EmptySpamFolderFailure) {
_handleEmptySpamFolderFailure(failure);
} else if (failure is EmptyTrashFolderFailure) {
_handleEmptyTrashFolderFailure(failure);
} else if (failure is MoveMultipleEmailToMailboxFailure) {
toastManager.showMessageFailure(failure);
} else if (failure is GetComposerCacheFailure) {
_handleIdentityCache();
Expand Down Expand Up @@ -1385,12 +1388,22 @@ class MailboxDashBoardController extends ReloadableController
}
}

void emptyTrashFolderAction({Function? onCancelSelectionEmail, MailboxId? trashFolderId}) {
void emptyTrashFolderAction({
Function? onCancelSelectionEmail,
MailboxId? trashFolderId,
int totalEmails = 0,
}) {
onCancelSelectionEmail?.call();

final trashMailboxId = trashFolderId ?? mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash];
if (sessionCurrent != null && accountId.value != null && trashMailboxId != null) {
consumeState(_emptyTrashFolderInteractor.execute(sessionCurrent!, accountId.value!, trashMailboxId));
consumeState(_emptyTrashFolderInteractor.execute(
sessionCurrent!,
accountId.value!,
trashMailboxId,
totalEmails,
_progressStateController
));
}
}

Expand Down Expand Up @@ -2371,7 +2384,11 @@ class MailboxDashBoardController extends ReloadableController
consumeState(_storeSessionInteractor.execute(session));
}

void emptySpamFolderAction({Function? onCancelSelectionEmail, MailboxId? spamFolderId}) {
void emptySpamFolderAction({
Function? onCancelSelectionEmail,
MailboxId? spamFolderId,
int totalEmails = 0
}) {
onCancelSelectionEmail?.call();

spamFolderId ??= spamMailboxId;
Expand All @@ -2389,7 +2406,9 @@ class MailboxDashBoardController extends ReloadableController
consumeState(_emptySpamFolderInteractor.execute(
sessionCurrent!,
accountId.value!,
spamFolderId
spamFolderId,
totalEmails,
_progressStateController
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/styles/mark_mailbox_as_read_loading_banner_style.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart';

class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin {
final Either<Failure, Success> viewState;
Expand All @@ -25,13 +26,21 @@ class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin
child: horizontalLoadingWidget);
} else if (success is UpdatingMarkAsMailboxReadState) {
final percent = success.countRead / success.totalUnread;
return Padding(
padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin,
child: horizontalPercentLoadingWidget(percent));
return _buildProgressBanner(percent);
} else if (success is EmptyingFolderState) {
final percent = success.countEmailsDeleted / success.totalEmails;
return _buildProgressBanner(percent);
} else {
return const SizedBox.shrink();
}
}
);
}

Padding _buildProgressBanner(double percent) {
return Padding(
padding: MarkMailboxAsReadLoadingBannerStyle.bannerMargin,
child: horizontalPercentLoadingWidget(percent)
);
}
}
28 changes: 20 additions & 8 deletions lib/features/thread/presentation/thread_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import 'package:tmail_ui_user/features/manage_account/presentation/vacation/widg
import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_banner_widget.dart';
import 'package:tmail_ui_user/features/quotas/presentation/widget/quotas_banner_widget.dart';
import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.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/get_all_email_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/search_email_state.dart';
import 'package:tmail_ui_user/features/thread/presentation/model/delete_action_type.dart';
Expand Down Expand Up @@ -868,7 +870,10 @@ class ThreadView extends GetWidget<ThreadController>
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is MarkAsMailboxReadLoading) {
if (success is MarkAsMailboxReadLoading
|| success is EmptySpamFolderLoading
|| success is EmptyTrashFolderLoading
) {
return Padding(
padding: EdgeInsets.only(
top: controller.responsiveUtils.isDesktop(context) ? 16 : 0,
Expand All @@ -878,16 +883,23 @@ class ThreadView extends GetWidget<ThreadController>
child: horizontalLoadingWidget);
} else if (success is UpdatingMarkAsMailboxReadState) {
final percent = success.countRead / success.totalUnread;
return Padding(
padding: EdgeInsets.only(
top: controller.responsiveUtils.isDesktop(context) ? 16 : 0,
left: 16,
right: 16,
bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16),
child: horizontalPercentLoadingWidget(percent));
return _buildProgressBanner(context, percent);
} else if (success is EmptyingFolderState) {
final percent = success.countEmailsDeleted / success.totalEmails;
return _buildProgressBanner(context, percent);
}
return const SizedBox.shrink();
});
});
}

Padding _buildProgressBanner(BuildContext context, double percent) {
return Padding(
padding: EdgeInsets.only(
top: controller.responsiveUtils.isDesktop(context) ? 16 : 0,
left: 16,
right: 16,
bottom: controller.responsiveUtils.isDesktop(context) ? 0 : 16),
child: horizontalPercentLoadingWidget(percent));
}
}

0 comments on commit 83f1c02

Please sign in to comment.