TF-4236 Implement remove a label from an email when click on the cross on a tag in the opened mail
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
||||
@@ -115,4 +116,14 @@ class TriggerMailViewKeyboardShortcutAction extends EmailUIAction {
|
||||
|
||||
@override
|
||||
List<Object?> get props => [actionType, email];
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveLabelFromEmailAction extends EmailUIAction {
|
||||
RemoveLabelFromEmailAction(this.emailId, this.label);
|
||||
|
||||
final EmailId emailId;
|
||||
final Label label;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [emailId, label];
|
||||
}
|
||||
|
||||
@@ -357,6 +357,13 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
actionType: action.actionType,
|
||||
email: action.email,
|
||||
);
|
||||
} else if (action is RemoveLabelFromEmailAction) {
|
||||
mailboxDashBoardController.clearEmailUIAction();
|
||||
if (_currentEmailId == null ||
|
||||
action.emailId != _currentEmailId) {
|
||||
return;
|
||||
}
|
||||
toggleLabelToEmail(action.emailId, action.label, false);
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -275,8 +275,14 @@ class EmailView extends GetWidget<SingleEmailController> {
|
||||
presentationEmail: presentationEmail.copyWith(
|
||||
subject: threadSubject,
|
||||
),
|
||||
imagePaths: controller.imagePaths,
|
||||
isMobileResponsive: isMobileResponsive,
|
||||
labels: emailLabels,
|
||||
onDeleteLabelAction: (label) => controller.toggleLabelToEmail(
|
||||
presentationEmail.id!,
|
||||
label,
|
||||
false,
|
||||
),
|
||||
);
|
||||
}),
|
||||
Obx(() => InformationSenderAndReceiverBuilder(
|
||||
|
||||
@@ -1,28 +1,49 @@
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/views/button/tmail_button_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/styles/email_subject_styles.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_widget.dart';
|
||||
|
||||
class EmailSubjectWidget extends StatelessWidget {
|
||||
typedef OnDeleteLabelAction = void Function(Label label);
|
||||
|
||||
class EmailSubjectWidget extends StatefulWidget {
|
||||
final PresentationEmail presentationEmail;
|
||||
final ImagePaths imagePaths;
|
||||
final bool isMobileResponsive;
|
||||
final List<Label>? labels;
|
||||
final OnDeleteLabelAction? onDeleteLabelAction;
|
||||
|
||||
const EmailSubjectWidget({
|
||||
super.key,
|
||||
required this.presentationEmail,
|
||||
required this.imagePaths,
|
||||
this.isMobileResponsive = false,
|
||||
this.labels,
|
||||
this.onDeleteLabelAction,
|
||||
});
|
||||
|
||||
String get _title => presentationEmail.getEmailTitle();
|
||||
@override
|
||||
State<EmailSubjectWidget> createState() => _EmailSubjectWidgetState();
|
||||
}
|
||||
|
||||
bool get _hasLabels => labels?.isNotEmpty == true;
|
||||
class _EmailSubjectWidgetState extends State<EmailSubjectWidget> {
|
||||
String get _title => widget.presentationEmail.getEmailTitle();
|
||||
|
||||
bool get _hasLabels => _currentLabels?.isNotEmpty == true;
|
||||
|
||||
List<Label>? _currentLabels;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentLabels = widget.labels;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final padding = isMobileResponsive
|
||||
final padding = widget.isMobileResponsive
|
||||
? EmailSubjectStyles.mobilePadding
|
||||
: EmailSubjectStyles.padding;
|
||||
|
||||
@@ -77,6 +98,35 @@ class EmailSubjectWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
List<Widget> _buildLabelWidgets() {
|
||||
return labels?.map(LabelWidget.create).toList() ?? const [];
|
||||
return _currentLabels
|
||||
?.map((label) => LabelWidget.create(
|
||||
label: label,
|
||||
removeLabelAction: _buildRemoveLabelWidget(label),
|
||||
padding: const EdgeInsetsDirectional.only(start: 4, end: 2),
|
||||
))
|
||||
.toList() ??
|
||||
const [];
|
||||
}
|
||||
|
||||
Widget _buildRemoveLabelWidget(Label label) {
|
||||
return TMailButtonWidget.fromIcon(
|
||||
icon: widget.imagePaths.icDeleteSelection,
|
||||
iconSize: 8,
|
||||
iconColor: Colors.white,
|
||||
padding: const EdgeInsets.all(6),
|
||||
backgroundColor: Colors.transparent,
|
||||
onTapActionCallback: () => _onDeleteLabelAction(label),
|
||||
);
|
||||
}
|
||||
|
||||
void _onDeleteLabelAction(Label labelRemoved) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_currentLabels = _currentLabels
|
||||
?.where((label) => label.id != labelRemoved.id)
|
||||
.toList();
|
||||
});
|
||||
widget.onDeleteLabelAction?.call(labelRemoved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user