Speed up list display list mailbox in MailboxVisibility

This commit is contained in:
dab246
2023-02-16 12:05:12 +07:00
committed by Dat Vu
parent 66e4d6c5d2
commit 1f871ac8eb
@@ -1,5 +1,7 @@
import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart'; import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/presentation/utils/app_toast.dart'; import 'package:core/presentation/utils/app_toast.dart';
import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/utils/app_logger.dart'; import 'package:core/utils/app_logger.dart';
@@ -74,15 +76,23 @@ class MailboxVisibilityController extends BaseMailboxController {
} }
@override @override
void onDone() { void onData(Either<Failure, Success> newState) {
viewState.value.fold((failure) {}, (success) { super.onData(newState);
newState.fold((failure) => null, (success) {
if (success is GetAllMailboxSuccess) { if (success is GetAllMailboxSuccess) {
_currentMailboxState = success.currentMailboxState; _currentMailboxState = success.currentMailboxState;
_buildMailboxTreeHasSubscribed(success.mailboxList); _handleBuildMailboxTree(success.mailboxList);
} else if (success is RefreshChangesAllMailboxSuccess) { } else if (success is RefreshChangesAllMailboxSuccess) {
_currentMailboxState = success.currentMailboxState; _currentMailboxState = success.currentMailboxState;
_refreshMailboxTreeHasSubscribed(success.mailboxList); refreshTree(success.mailboxList);
} else if (success is SubscribeMailboxSuccess) { }
});
}
@override
void onDone() {
viewState.value.fold((failure) {}, (success) {
if (success is SubscribeMailboxSuccess) {
_subscribeMailboxSuccess(success); _subscribeMailboxSuccess(success);
} else if (success is SubscribeMultipleMailboxAllSuccess) { } else if (success is SubscribeMultipleMailboxAllSuccess) {
_handleUnsubscribeMultipleMailboxAllSuccess(success); _handleUnsubscribeMultipleMailboxAllSuccess(success);
@@ -102,18 +112,12 @@ class MailboxVisibilityController extends BaseMailboxController {
super.onReady(); super.onReady();
} }
void _buildMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async { void _handleBuildMailboxTree(List<PresentationMailbox> mailboxList) async {
dispatchState(Right(LoadingBuildTreeMailboxVisibility())); dispatchState(Right(LoadingBuildTreeMailboxVisibility()));
final _mailboxList = mailboxList; await buildTree(mailboxList);
await buildTree(_mailboxList);
dispatchState(Right(BuildTreeMailboxVisibilitySuccess())); dispatchState(Right(BuildTreeMailboxVisibilitySuccess()));
} }
void _refreshMailboxTreeHasSubscribed(List<PresentationMailbox> mailboxList) async {
final _mailboxList = mailboxList;
await refreshTree(_mailboxList);
}
void subscribeMailbox(MailboxNode mailboxNode) { void subscribeMailbox(MailboxNode mailboxNode) {
final _mailboxSubscribeState = mailboxNode.item.isSubscribedMailbox final _mailboxSubscribeState = mailboxNode.item.isSubscribedMailbox
? MailboxSubscribeState.disabled : MailboxSubscribeState.enabled; ? MailboxSubscribeState.disabled : MailboxSubscribeState.enabled;