Skip to content

Commit

Permalink
fixup! 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 145a3f9 commit d8a9e12
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 35 deletions.
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
Original file line number Diff line number Diff line change
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));
}
}

0 comments on commit d8a9e12

Please sign in to comment.