From d8a9e129f1873b7dfe9994cbfd7ecdc2a297034e Mon Sep 17 00:00:00 2001 From: Dat PHAM HOANG Date: Thu, 2 Jan 2025 12:43:29 +0700 Subject: [PATCH] fixup! TF-3372 Handling error for empty trash failure --- .../mark_mailbox_as_read_loading_banner.dart | 9 +- .../data/network/thread_isolate_worker.dart | 2 +- .../thread/presentation/thread_view.dart | 85 ++++++++++++------- 3 files changed, 61 insertions(+), 35 deletions(-) diff --git a/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart b/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart index 806a063cf3..083f353b9c 100644 --- a/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart +++ b/lib/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart @@ -25,11 +25,9 @@ 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(); } @@ -37,7 +35,8 @@ class MarkMailboxAsReadLoadingBanner extends StatelessWidget with AppLoaderMixin ); } - 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) diff --git a/lib/features/thread/data/network/thread_isolate_worker.dart b/lib/features/thread/data/network/thread_isolate_worker.dart index b241b2e397..f342e0c8d5 100644 --- a/lib/features/thread/data/network/thread_isolate_worker.dart +++ b/lib/features/thread/data/network/thread_isolate_worker.dart @@ -176,7 +176,7 @@ class ThreadIsolateWorker { emailListCompleted.addAll(listEmailIdDeleted); onProgressController.add(Right(EmptyingFolderState( - mailboxId, listEmailIdDeleted.length, totalEmails + mailboxId, emailListCompleted.length, totalEmails ))); } else { hasEmails = false; diff --git a/lib/features/thread/presentation/thread_view.dart b/lib/features/thread/presentation/thread_view.dart index 21eb085388..5d8924ac2f 100644 --- a/lib/features/thread/presentation/thread_view.dart +++ b/lib/features/thread/presentation/thread_view.dart @@ -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'; @@ -164,7 +165,7 @@ class ThreadView extends GetWidget } }), if (!controller.responsiveUtils.isDesktop(context)) - _buildMarkAsMailboxReadLoading(context), + _buildMailboxActionProgressBanner(context), Obx(() => ThreadViewLoadingBarWidget(viewState: controller.viewState.value)), Expanded( child: Container( @@ -864,42 +865,68 @@ class ThreadView extends GetWidget ); } - 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 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)); } } \ No newline at end of file