TF-4233 Show popup menu when click three dot on label item

This commit is contained in:
dab246
2026-01-05 15:20:38 +07:00
committed by Dat H. Pham
parent f9ff9ecde7
commit 0302e09981
12 changed files with 438 additions and 37 deletions
@@ -0,0 +1,20 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/labels/presentation/label_controller.dart';
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
extension HandleLabelActionTypeExtension on LabelController {
void handleLabelActionType({
required LabelActionType actionType,
required AccountId? accountId,
Label? label,
}) {
switch (actionType) {
case LabelActionType.create:
openCreateNewLabelModal(accountId);
break;
case LabelActionType.edit:
break;
}
}
}
@@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/labels/domain/state/get_all_label_state.d
import 'package:tmail_ui_user/features/labels/domain/usecases/create_new_label_interactor.dart';
import 'package:tmail_ui_user/features/labels/domain/usecases/get_all_label_interactor.dart';
import 'package:tmail_ui_user/features/labels/presentation/label_interactor_bindings.dart';
import 'package:tmail_ui_user/features/labels/presentation/mixin/label_context_menu_mixin.dart';
import 'package:tmail_ui_user/features/labels/presentation/widgets/create_new_label_modal.dart';
import 'package:tmail_ui_user/features/manage_account/domain/state/get_label_setting_state.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_label_setting_state_interactor.dart';
@@ -24,7 +25,7 @@ import 'package:tmail_ui_user/main/exceptions/logic_exception.dart';
import 'package:tmail_ui_user/main/routes/dialog_router.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class LabelController extends BaseController {
class LabelController extends BaseController with LabelContextMenuMixin {
final labels = <Label>[].obs;
final labelListExpandMode = Rx(ExpandMode.EXPAND);
final isLabelSettingEnabled = RxBool(false);
@@ -0,0 +1,71 @@
import 'package:core/presentation/resources/image_paths.dart';
import 'package:flutter/material.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/base/mixin/popup_context_menu_action_mixin.dart';
import 'package:tmail_ui_user/features/base/widget/popup_menu/popup_menu_item_action_widget.dart';
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
import 'package:tmail_ui_user/features/labels/presentation/models/popup_menu_item_label_action.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/utils/labels/label_method_action_define.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
mixin LabelContextMenuMixin on PopupContextMenuActionMixin {
Future<void> openLabelContextMenuAction(
BuildContext context,
ImagePaths imagePaths,
Label label,
RelativeRect position,
OnLabelActionTypeCallback onLabelActionTypeCallback,
) async {
final listLabelAction = [LabelActionType.edit];
final popupMenuItems = listLabelAction
.map((actionType) => _buildLabelPopupMenuItem(
label,
actionType,
AppLocalizations.of(context),
imagePaths,
onLabelActionTypeCallback,
))
.toList();
return openPopupMenuAction(
context,
position,
popupMenuItems,
);
}
PopupMenuItem _buildLabelPopupMenuItem(
Label label,
LabelActionType actionType,
AppLocalizations appLocalizations,
ImagePaths imagePaths,
OnLabelActionTypeCallback onLabelActionTypeCallback,
) {
return PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupMenuItemActionWidget(
menuAction: PopupMenuItemLabelAction(
actionType,
appLocalizations,
imagePaths,
),
menuActionClick: (menuAction) => _onPerformLabelActionType(
label,
actionType,
onLabelActionTypeCallback,
),
),
);
}
void _onPerformLabelActionType(
Label label,
LabelActionType actionType,
OnLabelActionTypeCallback onLabelActionTypeCallback,
) {
popBack();
onLabelActionTypeCallback(label, actionType);
}
}
@@ -0,0 +1,46 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
enum LabelActionType {
create,
edit;
String getContextMenuTitle(AppLocalizations appLocalizations) {
switch (this) {
case LabelActionType.create:
return appLocalizations.create;
case LabelActionType.edit:
return appLocalizations.edit;
}
}
String getModalTitle(AppLocalizations appLocalizations) {
switch (this) {
case LabelActionType.create:
return appLocalizations.createANewLabel;
case LabelActionType.edit:
return appLocalizations.updateTheLabelName;
}
}
String getContextMenuIcon(ImagePaths imagePaths) {
switch (this) {
case LabelActionType.create:
return imagePaths.icAddNewFolder;
case LabelActionType.edit:
return imagePaths.icRenameMailbox;
}
}
Color getPopupMenuTitleColor() => Colors.black;
Color getPopupMenuIconColor() => AppColor.steelGrayA540;
Color getContextMenuIconColor() =>
AppColor.gray424244.withValues(alpha: 0.72);
Color getContextMenuTitleColor() =>
AppColor.gray424244.withValues(alpha: 0.9);
}
@@ -0,0 +1,32 @@
import 'package:core/presentation/resources/image_paths.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/base/model/popup_menu_item_action.dart';
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class PopupMenuItemLabelAction
extends PopupMenuItemActionRequiredIcon<LabelActionType> {
final AppLocalizations appLocalizations;
final ImagePaths imagePaths;
PopupMenuItemLabelAction(
super.action,
this.appLocalizations,
this.imagePaths,
);
@override
String get actionIcon => action.getContextMenuIcon(imagePaths);
@override
String get actionName => action.getContextMenuTitle(appLocalizations);
@override
Color get actionIconColor => action.getPopupMenuIconColor();
@override
Color get actionNameColor => action.getPopupMenuTitleColor();
@override
String get hoverIcon => imagePaths.icThumbsUp;
}