Skip to content

Commit 53c7f96

Browse files
committed
TF-4179 Add Label bar in sidebar
1 parent f7fe987 commit 53c7f96

File tree

6 files changed

+170
-4
lines changed

6 files changed

+170
-4
lines changed

lib/features/labels/presentation/label_controller.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
55
import 'package:jmap_dart_client/jmap/core/session/session.dart';
66
import 'package:labels/model/label.dart';
77
import 'package:labels/utils/labels_constants.dart';
8+
import 'package:model/mailbox/expand_mode.dart';
89
import 'package:tmail_ui_user/features/base/base_controller.dart';
910
import 'package:tmail_ui_user/features/labels/domain/state/get_all_label_state.dart';
1011
import 'package:tmail_ui_user/features/labels/domain/usecases/get_all_label_interactor.dart';
@@ -14,6 +15,7 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
1415

1516
class LabelController extends BaseController {
1617
final labels = <Label>[].obs;
18+
final labelListExpandMode = Rx(ExpandMode.EXPAND);
1719

1820
GetAllLabelInteractor? _getAllLabelInteractor;
1921

@@ -32,6 +34,12 @@ class LabelController extends BaseController {
3234
consumeState(_getAllLabelInteractor!.execute(accountId));
3335
}
3436

37+
void toggleLabelListState() {
38+
labelListExpandMode.value = labelListExpandMode.value == ExpandMode.COLLAPSE
39+
? ExpandMode.EXPAND
40+
: ExpandMode.COLLAPSE;
41+
}
42+
3543
@override
3644
void handleSuccessViewState(Success success) {
3745
if (success is GetAllLabelSuccess) {

lib/features/mailbox/presentation/base_mailbox_view.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_catego
1717
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
1818
import 'package:tmail_ui_user/features/mailbox/presentation/styles/mailbox_item_widget_styles.dart';
1919
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/folders_bar_widget.dart';
20+
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/labels/labels_bar_widget.dart';
2021
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/mailbox_app_bar.dart';
2122
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/mailbox_category_widget.dart';
2223
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/mailbox_item_widget.dart';
@@ -333,7 +334,34 @@ abstract class BaseMailboxView extends GetWidget<MailboxController>
333334
? buildFolders(context)
334335
: const Offstage(),
335336
)),
337+
buildLabelsBar(context, isDesktop),
336338
]),
337339
);
338340
}
341+
342+
Widget buildLabelsBar(BuildContext context, bool isDesktop) {
343+
return Obx(() {
344+
if (controller.mailboxDashBoardController.isLabelCapabilitySupported) {
345+
final labelController = controller
346+
.mailboxDashBoardController
347+
.labelController;
348+
349+
final labelListExpandMode = labelController.labelListExpandMode.value;
350+
351+
return LabelsBarWidget(
352+
imagePaths: controller.imagePaths,
353+
isDesktop: isDesktop,
354+
height: isDesktop ? 48 : 40,
355+
padding: isDesktop
356+
? null
357+
: const EdgeInsetsDirectional.only(start: 24, end: 12),
358+
labelStyle: isDesktop ? null : ThemeUtils.textStyleInter500(),
359+
expandMode: labelListExpandMode,
360+
onToggleLabelListState: labelController.toggleLabelListState,
361+
);
362+
} else {
363+
return const SizedBox.shrink();
364+
}
365+
});
366+
}
339367
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import 'package:core/presentation/extensions/color_extension.dart';
2+
import 'package:core/presentation/resources/image_paths.dart';
3+
import 'package:core/presentation/utils/theme_utils.dart';
4+
import 'package:core/presentation/views/button/tmail_button_widget.dart';
5+
import 'package:core/utils/direction_utils.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:model/mailbox/expand_mode.dart';
8+
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/expand_mode_extension.dart';
9+
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
10+
11+
class LabelsBarWidget extends StatelessWidget {
12+
final ImagePaths imagePaths;
13+
final bool isDesktop;
14+
final double? height;
15+
final EdgeInsetsGeometry? padding;
16+
final TextStyle? labelStyle;
17+
final ExpandMode? expandMode;
18+
final VoidCallback? onToggleLabelListState;
19+
final VoidCallback? onAddNewLabel;
20+
21+
const LabelsBarWidget({
22+
super.key,
23+
required this.imagePaths,
24+
this.isDesktop = false,
25+
this.height,
26+
this.padding,
27+
this.labelStyle,
28+
this.expandMode,
29+
this.onToggleLabelListState,
30+
this.onAddNewLabel,
31+
});
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
Widget addNewLabelIcon = TMailButtonWidget.fromIcon(
36+
icon: imagePaths.icAddNewFolder,
37+
backgroundColor: Colors.transparent,
38+
iconColor: AppColor.steelGrayA540,
39+
iconSize: 20,
40+
padding: const EdgeInsets.all(5),
41+
tooltipMessage: AppLocalizations.of(context).newLabel,
42+
onTapActionCallback: onAddNewLabel,
43+
);
44+
45+
if (isDesktop) {
46+
addNewLabelIcon = Transform(
47+
transform: Matrix4.translationValues(8, 0, 0),
48+
child: addNewLabelIcon,
49+
);
50+
}
51+
52+
final labelText = Text(
53+
AppLocalizations.of(context).labels,
54+
style: labelStyle ?? ThemeUtils.textStyleInter700(),
55+
maxLines: 1,
56+
overflow: TextOverflow.ellipsis,
57+
);
58+
59+
return Container(
60+
padding: padding ??
61+
EdgeInsetsDirectional.only(
62+
start: isDesktop ? 10 : 26,
63+
end: isDesktop ? 0 : 8,
64+
),
65+
height: height ?? 48,
66+
child: Row(
67+
children: [
68+
if (expandMode != null)
69+
Expanded(
70+
child: Row(
71+
children: [
72+
Flexible(child: labelText),
73+
TMailButtonWidget.fromIcon(
74+
icon: expandMode!.getIcon(
75+
imagePaths,
76+
DirectionUtils.isDirectionRTLByLanguage(context),
77+
),
78+
iconColor: Colors.black,
79+
iconSize: 17,
80+
margin: isDesktop
81+
? const EdgeInsetsDirectional.only(start: 8)
82+
: null,
83+
backgroundColor: Colors.transparent,
84+
padding: const EdgeInsets.all(3),
85+
tooltipMessage: expandMode!
86+
.getTooltipMessage(AppLocalizations.of(context)),
87+
onTapActionCallback: onToggleLabelListState,
88+
),
89+
],
90+
),
91+
)
92+
else
93+
Expanded(child: labelText),
94+
if (onAddNewLabel != null)
95+
addNewLabelIcon,
96+
],
97+
),
98+
);
99+
}
100+
}

lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,19 @@ class MailboxDashBoardController extends ReloadableController
880880
ownEmailAddress: ownEmailAddress.value,
881881
);
882882

883-
final isLabelCapabilitySupported = labelController
884-
.isLabelCapabilitySupported(session, currentAccountId);
885-
886883
if (isLabelCapabilitySupported) {
887884
labelController.injectLabelsBindings();
888885
labelController.getAllLabels(currentAccountId);
889886
}
890887
}
891888

889+
bool get isLabelCapabilitySupported {
890+
if (accountId.value == null || sessionCurrent == null) return false;
891+
892+
return labelController
893+
.isLabelCapabilitySupported(sessionCurrent!, accountId.value!);
894+
}
895+
892896
void _handleMailtoURL(MailtoArguments arguments) {
893897
log('MailboxDashBoardController::_handleMailtoURL:');
894898
routerParameters.value = arguments.toMapRouter();

lib/l10n/intl_messages.arb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"@@last_modified": "2025-11-20T14:48:58.635692",
2+
"@@last_modified": "2025-11-25T16:41:03.318468",
33
"initializing_data": "Initializing data...",
44
"@initializing_data": {
55
"type": "text",
@@ -5129,5 +5129,17 @@
51295129
"type": "text",
51305130
"placeholders_order": [],
51315131
"placeholders": {}
5132+
},
5133+
"labels": "Labels",
5134+
"@labels": {
5135+
"type": "text",
5136+
"placeholders_order": [],
5137+
"placeholders": {}
5138+
},
5139+
"newLabel": "New label",
5140+
"@newLabel": {
5141+
"type": "text",
5142+
"placeholders_order": [],
5143+
"placeholders": {}
51325144
}
51335145
}

lib/main/localizations/app_localizations.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,4 +5436,18 @@ class AppLocalizations {
54365436
name: 'startToAddFavoritesEmails',
54375437
);
54385438
}
5439+
5440+
String get labels {
5441+
return Intl.message(
5442+
'Labels',
5443+
name: 'labels',
5444+
);
5445+
}
5446+
5447+
String get newLabel {
5448+
return Intl.message(
5449+
'New label',
5450+
name: 'newLabel',
5451+
);
5452+
}
54395453
}

0 commit comments

Comments
 (0)