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;
|
personalMailboxTree.value.root.childrenItems?.isNotEmpty ?? false;
|
||||||
|
|
||||||
bool get teamMailboxesHasChild =>
|
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;
|
MailboxNode get defaultRootNode => defaultMailboxTree.value.root;
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ class MailboxAPI with HandleSetErrorMixin {
|
|||||||
Future<bool> subscribeMailbox(AccountId accountId, SubscribeMailboxRequest request) async {
|
Future<bool> subscribeMailbox(AccountId accountId, SubscribeMailboxRequest request) async {
|
||||||
final setMailboxMethod = SetMailboxMethod(accountId)
|
final setMailboxMethod = SetMailboxMethod(accountId)
|
||||||
..addUpdates({
|
..addUpdates({
|
||||||
request.mailboxId.id : PatchObject({
|
request.mailbox.id.id : PatchObject({
|
||||||
'isSubscribed': request.newState == MailboxSubscribeState.disabled ? false : true
|
'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: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';
|
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_subscribe_state.dart';
|
||||||
|
|
||||||
class SubscribeMailboxRequest with EquatableMixin {
|
class SubscribeMailboxRequest with EquatableMixin {
|
||||||
|
|
||||||
final MailboxId mailboxId;
|
final PresentationMailbox mailbox;
|
||||||
final MailboxSubscribeState newState;
|
final MailboxSubscribeState newState;
|
||||||
|
final MailboxSubscribeStateAction mailboxSubscribeStateAction;
|
||||||
|
|
||||||
SubscribeMailboxRequest(this.mailboxId, this.newState);
|
SubscribeMailboxRequest(
|
||||||
|
this.mailbox,
|
||||||
|
this.newState,
|
||||||
|
this.mailboxSubscribeStateAction);
|
||||||
|
|
||||||
@override
|
@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:core/core.dart';
|
||||||
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||||
import 'package:tmail_ui_user/features/base/state/ui_action_state.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: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 LoadingSubscribeMailbox extends UIState {}
|
||||||
|
|
||||||
class SubscribeMailboxSuccess extends UIActionState {
|
class SubscribeMailboxSuccess extends UIActionState {
|
||||||
|
final PresentationMailbox mailbox;
|
||||||
|
final MailboxSubscribeStateAction mailboxSubscribeStateAction;
|
||||||
|
|
||||||
SubscribeMailboxSuccess({
|
SubscribeMailboxSuccess(
|
||||||
jmap.State? currentEmailState,
|
this.mailbox,
|
||||||
jmap.State? currentMailboxState,
|
this.mailboxSubscribeStateAction,
|
||||||
}) : super(currentEmailState, currentMailboxState);
|
{
|
||||||
|
jmap.State? currentEmailState,
|
||||||
|
jmap.State? currentMailboxState,
|
||||||
|
}
|
||||||
|
) : super(currentEmailState, currentMailboxState);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [];
|
List<Object?> get props => [
|
||||||
|
mailbox,
|
||||||
|
currentEmailState,
|
||||||
|
currentMailboxState,
|
||||||
|
mailboxSubscribeStateAction
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SubscribeMailboxFailure extends FeatureFailure {
|
class SubscribeMailboxFailure extends FeatureFailure {
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ class SubscribeMailboxInteractor {
|
|||||||
final result = await _mailboxRepository.subscribeMailbox(accountId, request);
|
final result = await _mailboxRepository.subscribeMailbox(accountId, request);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
yield Right<Failure, Success>(SubscribeMailboxSuccess(currentMailboxState: currentMailboxState));
|
yield Right<Failure, Success>(SubscribeMailboxSuccess(
|
||||||
|
request.mailbox,
|
||||||
|
currentMailboxState: currentMailboxState,
|
||||||
|
request.mailboxSubscribeStateAction));
|
||||||
} else {
|
} else {
|
||||||
yield Left<Failure, Success>(SubscribeMailboxFailure(null));
|
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/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/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/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/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/move_mailbox_request.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_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);
|
refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
|
||||||
} else if (success is MoveMailboxSuccess) {
|
} else if (success is MoveMailboxSuccess) {
|
||||||
_moveMailboxSuccess(success);
|
_moveMailboxSuccess(success);
|
||||||
} else if (success is SubscribeMailboxSuccess){
|
} else if (success is SubscribeMailboxSuccess) {
|
||||||
refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
|
subscribeMailboxSuccess(success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -1152,7 +1153,10 @@ class MailboxController extends BaseMailboxController {
|
|||||||
mailboxDashBoardController.storeSpamReportStateAction();
|
mailboxDashBoardController.storeSpamReportStateAction();
|
||||||
break;
|
break;
|
||||||
case MailboxActions.disableMailbox:
|
case MailboxActions.disableMailbox:
|
||||||
subscribeMailboxAction(mailbox);
|
subscribeMailboxAction(SubscribeMailboxRequest(
|
||||||
|
mailbox,
|
||||||
|
MailboxSubscribeState.disabled,
|
||||||
|
MailboxSubscribeStateAction.subscribing));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1223,13 +1227,41 @@ class MailboxController extends BaseMailboxController {
|
|||||||
await refreshTree(_mailboxList);
|
await refreshTree(_mailboxList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subscribeMailboxAction(PresentationMailbox mailboxSelected) {
|
void subscribeMailboxAction(SubscribeMailboxRequest subscribeMailboxRequest) {
|
||||||
final _accountId = mailboxDashBoardController.accountId.value;
|
final _accountId = mailboxDashBoardController.accountId.value;
|
||||||
if(_accountId != null) {
|
if(_accountId != null) {
|
||||||
consumeState(_subscribeMailboxInteractor.execute(_accountId, SubscribeMailboxRequest(
|
consumeState(_subscribeMailboxInteractor.execute(
|
||||||
mailboxSelected.id,
|
_accountId, subscribeMailboxRequest));
|
||||||
MailboxSubscribeState.disabled,
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
return Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
right: _responsiveUtils.isLandscapeMobile(context) ? 8 : 28,
|
right: _responsiveUtils.isLandscapeMobile(context) ? 8 : 28,
|
||||||
left: 16),
|
left: 4),
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
buildIconWeb(
|
buildIconWeb(
|
||||||
minSize: 40,
|
minSize: 40,
|
||||||
@@ -307,7 +307,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
|||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(
|
||||||
left: _responsiveUtils.isLandscapeMobile(context) ? 0 : 16,
|
left: _responsiveUtils.isLandscapeMobile(context) ? 0 : 8,
|
||||||
right: 16),
|
right: 16),
|
||||||
padding: const EdgeInsets.only(left: 12),
|
padding: const EdgeInsets.only(left: 12),
|
||||||
child: TreeView(
|
child: TreeView(
|
||||||
@@ -330,23 +330,23 @@ class MailboxView extends GetWidget<MailboxController> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _openBottomSheetSpamMenuAction(BuildContext context, PresentationMailbox mailbox) {
|
void _openBottomSheetSpamMenuAction(BuildContext context, PresentationMailbox mailbox) {
|
||||||
final _spamActionsSupported = [
|
final _mailboxActionsSupported = [
|
||||||
MailboxActions.disableMailbox
|
MailboxActions.disableMailbox
|
||||||
];
|
];
|
||||||
|
|
||||||
if (mailbox.isSpam) {
|
if (mailbox.isSpam) {
|
||||||
_spamActionsSupported.add(controller.mailboxDashBoardController.enableSpamReport
|
_mailboxActionsSupported.add(controller.mailboxDashBoardController.enableSpamReport
|
||||||
? MailboxActions.disableSpamReport
|
? MailboxActions.disableSpamReport
|
||||||
: MailboxActions.enableSpamReport);
|
: MailboxActions.enableSpamReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
final listContextSpamPopupMenuItemAction = _spamActionsSupported
|
final listContextMailboxPopupMenuItemAction = _mailboxActionsSupported
|
||||||
.map((action) => ContextMenuItemMailboxAction(action, action.getContextMenuItemState(mailbox)))
|
.map((action) => ContextMenuItemMailboxAction(action, action.getContextMenuItemState(mailbox)))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
controller.openContextMenuAction(
|
controller.openContextMenuAction(
|
||||||
context,
|
context,
|
||||||
_bottomSheetIdentityActionTiles(context, mailbox, listContextSpamPopupMenuItemAction));
|
_bottomSheetIdentityActionTiles(context, mailbox, listContextMailboxPopupMenuItemAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _bottomSheetIdentityActionTiles(
|
List<Widget> _bottomSheetIdentityActionTiles(
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ class MailboxView extends GetWidget<MailboxController> with AppLoaderMixin, Popu
|
|||||||
MailboxActions.delete,
|
MailboxActions.delete,
|
||||||
];
|
];
|
||||||
|
|
||||||
if(mailbox.isShowDisableMailbox) {
|
if (mailbox.isShowDisableMailbox) {
|
||||||
mailboxActionsSupported.add(MailboxActions.disableMailbox);
|
mailboxActionsSupported.add(MailboxActions.disableMailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,8 +146,11 @@ extension MailboxActionsExtension on MailboxActions {
|
|||||||
case MailboxActions.openInNewTab:
|
case MailboxActions.openInNewTab:
|
||||||
case MailboxActions.disableSpamReport:
|
case MailboxActions.disableSpamReport:
|
||||||
case MailboxActions.enableSpamReport:
|
case MailboxActions.enableSpamReport:
|
||||||
case MailboxActions.disableMailbox:
|
|
||||||
return ContextMenuItemState.activated;
|
return ContextMenuItemState.activated;
|
||||||
|
case MailboxActions.disableMailbox:
|
||||||
|
return mailbox.hasRole()
|
||||||
|
? ContextMenuItemState.deactivated
|
||||||
|
: ContextMenuItemState.activated;
|
||||||
case MailboxActions.markAsRead:
|
case MailboxActions.markAsRead:
|
||||||
return mailbox.getCountUnReadEmails().isNotEmpty
|
return mailbox.getCountUnReadEmails().isNotEmpty
|
||||||
? ContextMenuItemState.activated
|
? ContextMenuItemState.activated
|
||||||
|
|||||||
@@ -103,7 +103,11 @@ class MailBoxFolderTileBuilder {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
color: backgroundColorItem),
|
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),
|
margin: const EdgeInsets.only(bottom: 4),
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: _mailboxNode.item.isTeamMailboxes
|
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() {
|
Widget _buildLeadingMailboxItem() {
|
||||||
if (BuildUtils.isWeb) {
|
if (BuildUtils.isWeb) {
|
||||||
if (mailboxDisplayed == MailboxDisplayed.mailbox) {
|
if (mailboxDisplayed == MailboxDisplayed.mailbox) {
|
||||||
@@ -202,7 +218,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
if (_mailboxNode.hasChildren())
|
if (_mailboxNode.hasChildren())
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: _mailboxNode.item.hasRole() ? 0 : 8),
|
const SizedBox(width: 8),
|
||||||
buildIconWeb(
|
buildIconWeb(
|
||||||
icon: SvgPicture.asset(
|
icon: SvgPicture.asset(
|
||||||
_mailboxNode.expandMode == ExpandMode.EXPAND
|
_mailboxNode.expandMode == ExpandMode.EXPAND
|
||||||
@@ -222,7 +238,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
SizedBox(width: !_mailboxNode.item.hasRole() ? 32 : 24),
|
const SizedBox(width: 32),
|
||||||
Transform(
|
Transform(
|
||||||
transform: Matrix4.translationValues(-4.0, 0.0, 0.0),
|
transform: Matrix4.translationValues(-4.0, 0.0, 0.0),
|
||||||
child: _buildLeadingIcon()),
|
child: _buildLeadingIcon()),
|
||||||
@@ -236,7 +252,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
if (_mailboxNode.hasChildren())
|
if (_mailboxNode.hasChildren())
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 12),
|
SizedBox(width: _mailboxNode.item.hasRole() ? 0 : 0),
|
||||||
buildIconWeb(
|
buildIconWeb(
|
||||||
icon: SvgPicture.asset(
|
icon: SvgPicture.asset(
|
||||||
_mailboxNode.expandMode == ExpandMode.EXPAND
|
_mailboxNode.expandMode == ExpandMode.EXPAND
|
||||||
@@ -256,7 +272,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
const SizedBox(width: 36),
|
const SizedBox(width: 24),
|
||||||
_buildLeadingIcon(),
|
_buildLeadingIcon(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
@@ -335,7 +351,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildLeadingIconTeamMailboxes() {
|
Widget _buildLeadingIconTeamMailboxes() {
|
||||||
if(!_mailboxNode.item.isPersonal) {
|
if (!_mailboxNode.item.isPersonal) {
|
||||||
return _buildLeadingIconForChildOfTeamMailboxes();
|
return _buildLeadingIconForChildOfTeamMailboxes();
|
||||||
} else {
|
} else {
|
||||||
return _buildMailboxIcon();
|
return _buildMailboxIcon();
|
||||||
@@ -343,7 +359,7 @@ class MailBoxFolderTileBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildLeadingIconForChildOfTeamMailboxes() {
|
Widget _buildLeadingIconForChildOfTeamMailboxes() {
|
||||||
if(_mailboxNode.item.hasParentId()) {
|
if (_mailboxNode.item.hasParentId()) {
|
||||||
return _buildMailboxIcon();
|
return _buildMailboxIcon();
|
||||||
} else {
|
} else {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
|
|||||||
@@ -2779,4 +2779,10 @@ class AppLocalizations {
|
|||||||
name: 'thisImageCannotBeAdded'
|
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