TF-1311: [Presentation]: Handle show toastMsg when hide mailbox
This commit is contained in:
@@ -149,7 +149,8 @@ abstract class BaseMailboxController extends BaseController {
|
||||
personalMailboxTree.value.root.childrenItems?.isNotEmpty ?? false;
|
||||
|
||||
bool get teamMailboxesHasChild =>
|
||||
teamMailboxesTree.value.root.childrenItems?.isNotEmpty ?? false;
|
||||
(teamMailboxesTree.value.root.childrenItems?.isNotEmpty ?? false )
|
||||
&& !teamMailboxesTree.value.root.item.isTeamMailboxes;
|
||||
|
||||
MailboxNode get defaultRootNode => defaultMailboxTree.value.root;
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ class MailboxAPI with HandleSetErrorMixin {
|
||||
Future<bool> subscribeMailbox(AccountId accountId, SubscribeMailboxRequest request) async {
|
||||
final setMailboxMethod = SetMailboxMethod(accountId)
|
||||
..addUpdates({
|
||||
request.mailboxId.id : PatchObject({
|
||||
request.mailbox.id.id : PatchObject({
|
||||
'isSubscribed': request.newState == MailboxSubscribeState.disabled ? false : true
|
||||
})
|
||||
});
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
enum MailboxSubscribeStateAction {
|
||||
subscribing,
|
||||
undo
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.dart';
|
||||
|
||||
class SubscribeMailboxRequest with EquatableMixin {
|
||||
|
||||
final MailboxId mailboxId;
|
||||
final PresentationMailbox mailbox;
|
||||
final MailboxSubscribeState newState;
|
||||
final MailboxSubscribeStateAction mailboxSubscribeStateAction;
|
||||
|
||||
SubscribeMailboxRequest(this.mailboxId, this.newState);
|
||||
SubscribeMailboxRequest(
|
||||
this.mailbox,
|
||||
this.newState,
|
||||
this.mailboxSubscribeStateAction);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mailboxId, newState];
|
||||
List<Object?> get props => [mailbox, newState, mailboxSubscribeStateAction];
|
||||
}
|
||||
|
||||
@@ -1,19 +1,31 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
|
||||
|
||||
class LoadingSubscribeMailbox extends UIState {}
|
||||
|
||||
class SubscribeMailboxSuccess extends UIActionState {
|
||||
final PresentationMailbox mailbox;
|
||||
final MailboxSubscribeStateAction mailboxSubscribeStateAction;
|
||||
|
||||
SubscribeMailboxSuccess({
|
||||
jmap.State? currentEmailState,
|
||||
jmap.State? currentMailboxState,
|
||||
}) : super(currentEmailState, currentMailboxState);
|
||||
SubscribeMailboxSuccess(
|
||||
this.mailbox,
|
||||
this.mailboxSubscribeStateAction,
|
||||
{
|
||||
jmap.State? currentEmailState,
|
||||
jmap.State? currentMailboxState,
|
||||
}
|
||||
) : super(currentEmailState, currentMailboxState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
List<Object?> get props => [
|
||||
mailbox,
|
||||
currentEmailState,
|
||||
currentMailboxState,
|
||||
mailboxSubscribeStateAction
|
||||
];
|
||||
}
|
||||
|
||||
class SubscribeMailboxFailure extends FeatureFailure {
|
||||
|
||||
@@ -20,7 +20,10 @@ class SubscribeMailboxInteractor {
|
||||
final result = await _mailboxRepository.subscribeMailbox(accountId, request);
|
||||
|
||||
if (result) {
|
||||
yield Right<Failure, Success>(SubscribeMailboxSuccess(currentMailboxState: currentMailboxState));
|
||||
yield Right<Failure, Success>(SubscribeMailboxSuccess(
|
||||
request.mailbox,
|
||||
currentMailboxState: currentMailboxState,
|
||||
request.mailboxSubscribeStateAction));
|
||||
} else {
|
||||
yield Left<Failure, Success>(SubscribeMailboxFailure(null));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import 'package:tmail_ui_user/features/email/domain/state/delete_multiple_emails
|
||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/move_to_mailbox_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_action_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/move_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';
|
||||
@@ -198,8 +199,8 @@ class MailboxController extends BaseMailboxController {
|
||||
refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
|
||||
} else if (success is MoveMailboxSuccess) {
|
||||
_moveMailboxSuccess(success);
|
||||
} else if (success is SubscribeMailboxSuccess){
|
||||
refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
|
||||
} else if (success is SubscribeMailboxSuccess) {
|
||||
subscribeMailboxSuccess(success);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1152,7 +1153,10 @@ class MailboxController extends BaseMailboxController {
|
||||
mailboxDashBoardController.storeSpamReportStateAction();
|
||||
break;
|
||||
case MailboxActions.disableMailbox:
|
||||
subscribeMailboxAction(mailbox);
|
||||
subscribeMailboxAction(SubscribeMailboxRequest(
|
||||
mailbox,
|
||||
MailboxSubscribeState.disabled,
|
||||
MailboxSubscribeStateAction.subscribing));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1223,13 +1227,41 @@ class MailboxController extends BaseMailboxController {
|
||||
await refreshTree(_mailboxList);
|
||||
}
|
||||
|
||||
void subscribeMailboxAction(PresentationMailbox mailboxSelected) {
|
||||
void subscribeMailboxAction(SubscribeMailboxRequest subscribeMailboxRequest) {
|
||||
final _accountId = mailboxDashBoardController.accountId.value;
|
||||
if(_accountId != null) {
|
||||
consumeState(_subscribeMailboxInteractor.execute(_accountId, SubscribeMailboxRequest(
|
||||
mailboxSelected.id,
|
||||
MailboxSubscribeState.disabled,
|
||||
)));
|
||||
consumeState(_subscribeMailboxInteractor.execute(
|
||||
_accountId, subscribeMailboxRequest));
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeMailboxSuccess(SubscribeMailboxSuccess subscribeMailboxSuccess) {
|
||||
if(subscribeMailboxSuccess.mailboxSubscribeStateAction == MailboxSubscribeStateAction.subscribing
|
||||
&& currentOverlayContext != null
|
||||
&& currentContext != null) {
|
||||
_appToast.showBottomToast(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).toastMsgHideMailboxSuccess,
|
||||
actionName: AppLocalizations.of(currentContext!).undo,
|
||||
onActionClick: () {
|
||||
subscribeMailboxAction(SubscribeMailboxRequest(
|
||||
subscribeMailboxSuccess.mailbox,
|
||||
MailboxSubscribeState.enabled,
|
||||
MailboxSubscribeStateAction.undo));
|
||||
},
|
||||
leadingIcon: SvgPicture.asset(
|
||||
_imagePaths.icFolderMailbox,
|
||||
width: 24,
|
||||
height: 24,
|
||||
color: Colors.white,
|
||||
fit: BoxFit.fill),
|
||||
backgroundColor: AppColor.toastSuccessBackgroundColor,
|
||||
textColor: Colors.white,
|
||||
textActionColor: Colors.white,
|
||||
actionIcon: SvgPicture.asset(_imagePaths.icUndo),
|
||||
maxWidth: _responsiveUtils.getMaxWidthToast(currentContext!));
|
||||
}
|
||||
|
||||
refreshMailboxChanges(currentMailboxState: subscribeMailboxSuccess.currentMailboxState);
|
||||
}
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: _responsiveUtils.isLandscapeMobile(context) ? 8 : 28,
|
||||
left: 16),
|
||||
left: 4),
|
||||
child: Row(children: [
|
||||
buildIconWeb(
|
||||
minSize: 40,
|
||||
@@ -307,7 +307,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
left: _responsiveUtils.isLandscapeMobile(context) ? 0 : 16,
|
||||
left: _responsiveUtils.isLandscapeMobile(context) ? 0 : 8,
|
||||
right: 16),
|
||||
padding: const EdgeInsets.only(left: 12),
|
||||
child: TreeView(
|
||||
@@ -330,23 +330,23 @@ class MailboxView extends GetWidget<MailboxController> {
|
||||
}
|
||||
|
||||
void _openBottomSheetSpamMenuAction(BuildContext context, PresentationMailbox mailbox) {
|
||||
final _spamActionsSupported = [
|
||||
final _mailboxActionsSupported = [
|
||||
MailboxActions.disableMailbox
|
||||
];
|
||||
|
||||
if (mailbox.isSpam) {
|
||||
_spamActionsSupported.add(controller.mailboxDashBoardController.enableSpamReport
|
||||
_mailboxActionsSupported.add(controller.mailboxDashBoardController.enableSpamReport
|
||||
? MailboxActions.disableSpamReport
|
||||
: MailboxActions.enableSpamReport);
|
||||
}
|
||||
|
||||
final listContextSpamPopupMenuItemAction = _spamActionsSupported
|
||||
final listContextMailboxPopupMenuItemAction = _mailboxActionsSupported
|
||||
.map((action) => ContextMenuItemMailboxAction(action, action.getContextMenuItemState(mailbox)))
|
||||
.toList();
|
||||
|
||||
controller.openContextMenuAction(
|
||||
context,
|
||||
_bottomSheetIdentityActionTiles(context, mailbox, listContextSpamPopupMenuItemAction));
|
||||
_bottomSheetIdentityActionTiles(context, mailbox, listContextMailboxPopupMenuItemAction));
|
||||
}
|
||||
|
||||
List<Widget> _bottomSheetIdentityActionTiles(
|
||||
|
||||
@@ -457,7 +457,7 @@ class MailboxView extends GetWidget<MailboxController> with AppLoaderMixin, Popu
|
||||
MailboxActions.delete,
|
||||
];
|
||||
|
||||
if(mailbox.isShowDisableMailbox) {
|
||||
if (mailbox.isShowDisableMailbox) {
|
||||
mailboxActionsSupported.add(MailboxActions.disableMailbox);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,8 +146,11 @@ extension MailboxActionsExtension on MailboxActions {
|
||||
case MailboxActions.openInNewTab:
|
||||
case MailboxActions.disableSpamReport:
|
||||
case MailboxActions.enableSpamReport:
|
||||
case MailboxActions.disableMailbox:
|
||||
return ContextMenuItemState.activated;
|
||||
case MailboxActions.disableMailbox:
|
||||
return mailbox.hasRole()
|
||||
? ContextMenuItemState.deactivated
|
||||
: ContextMenuItemState.activated;
|
||||
case MailboxActions.markAsRead:
|
||||
return mailbox.getCountUnReadEmails().isNotEmpty
|
||||
? ContextMenuItemState.activated
|
||||
|
||||
@@ -103,7 +103,11 @@ class MailBoxFolderTileBuilder {
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: backgroundColorItem),
|
||||
padding: const EdgeInsets.only(left: 4, right: 4, top: 8, bottom: 8),
|
||||
padding: EdgeInsets.only(
|
||||
left: _mailboxNode.item.hasRole() ? 0 : 4,
|
||||
right: 4,
|
||||
top: 8,
|
||||
bottom: 8),
|
||||
margin: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
crossAxisAlignment: _mailboxNode.item.isTeamMailboxes
|
||||
@@ -195,6 +199,18 @@ class MailBoxFolderTileBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
// double _buildSizedBoxWhenHasNotChildren() {
|
||||
// if (_mailboxNode.item.hasRole()) {
|
||||
// if (!_mailboxNode.item.hasParentId()) {
|
||||
// return 32;
|
||||
// } else {
|
||||
// return 8;
|
||||
// }
|
||||
// } else {
|
||||
// return 32;
|
||||
// }
|
||||
// }
|
||||
|
||||
Widget _buildLeadingMailboxItem() {
|
||||
if (BuildUtils.isWeb) {
|
||||
if (mailboxDisplayed == MailboxDisplayed.mailbox) {
|
||||
@@ -202,7 +218,7 @@ class MailBoxFolderTileBuilder {
|
||||
if (_mailboxNode.hasChildren())
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: _mailboxNode.item.hasRole() ? 0 : 8),
|
||||
const SizedBox(width: 8),
|
||||
buildIconWeb(
|
||||
icon: SvgPicture.asset(
|
||||
_mailboxNode.expandMode == ExpandMode.EXPAND
|
||||
@@ -222,7 +238,7 @@ class MailBoxFolderTileBuilder {
|
||||
],
|
||||
)
|
||||
else
|
||||
SizedBox(width: !_mailboxNode.item.hasRole() ? 32 : 24),
|
||||
const SizedBox(width: 32),
|
||||
Transform(
|
||||
transform: Matrix4.translationValues(-4.0, 0.0, 0.0),
|
||||
child: _buildLeadingIcon()),
|
||||
@@ -236,7 +252,7 @@ class MailBoxFolderTileBuilder {
|
||||
if (_mailboxNode.hasChildren())
|
||||
Row(
|
||||
children: [
|
||||
const SizedBox(width: 12),
|
||||
SizedBox(width: _mailboxNode.item.hasRole() ? 0 : 0),
|
||||
buildIconWeb(
|
||||
icon: SvgPicture.asset(
|
||||
_mailboxNode.expandMode == ExpandMode.EXPAND
|
||||
@@ -256,7 +272,7 @@ class MailBoxFolderTileBuilder {
|
||||
],
|
||||
)
|
||||
else
|
||||
const SizedBox(width: 36),
|
||||
const SizedBox(width: 24),
|
||||
_buildLeadingIcon(),
|
||||
]);
|
||||
} else {
|
||||
@@ -335,7 +351,7 @@ class MailBoxFolderTileBuilder {
|
||||
}
|
||||
|
||||
Widget _buildLeadingIconTeamMailboxes() {
|
||||
if(!_mailboxNode.item.isPersonal) {
|
||||
if (!_mailboxNode.item.isPersonal) {
|
||||
return _buildLeadingIconForChildOfTeamMailboxes();
|
||||
} else {
|
||||
return _buildMailboxIcon();
|
||||
@@ -343,7 +359,7 @@ class MailBoxFolderTileBuilder {
|
||||
}
|
||||
|
||||
Widget _buildLeadingIconForChildOfTeamMailboxes() {
|
||||
if(_mailboxNode.item.hasParentId()) {
|
||||
if (_mailboxNode.item.hasParentId()) {
|
||||
return _buildMailboxIcon();
|
||||
} else {
|
||||
return const SizedBox();
|
||||
|
||||
@@ -2779,4 +2779,10 @@ class AppLocalizations {
|
||||
name: 'thisImageCannotBeAdded'
|
||||
);
|
||||
}
|
||||
|
||||
String get toastMsgHideMailboxSuccess {
|
||||
return Intl.message(
|
||||
'This mailbox has been hidden from your primary mailbox',
|
||||
name: 'toastMsgHideMailboxSuccess');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user