Skip to content

Commit 109e8dc

Browse files
committed
home: Show unread counts in main menu
Fixes-partly: #1088
1 parent 7fa3dee commit 109e8dc

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

lib/widgets/home.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'store.dart';
2222
import 'subscription_list.dart';
2323
import 'text.dart';
2424
import 'theme.dart';
25+
import 'unread_count_badge.dart';
2526
import 'user.dart';
2627

2728
enum _HomePageTab {
@@ -351,6 +352,8 @@ abstract class _MenuButton extends StatelessWidget {
351352
color: selected ? designVariables.iconSelected : designVariables.icon);
352353
}
353354

355+
Widget? buildTrailing(BuildContext context) => null;
356+
354357
void onPressed(BuildContext context);
355358

356359
void _handlePress(BuildContext context) {
@@ -391,6 +394,8 @@ abstract class _MenuButton extends StatelessWidget {
391394
~WidgetState.pressed: selected ? borderSideSelected : null,
392395
}));
393396

397+
final trailing = buildTrailing(context);
398+
394399
return AnimatedScaleOnTap(
395400
duration: const Duration(milliseconds: 100),
396401
scaleEnd: 0.95,
@@ -407,6 +412,7 @@ abstract class _MenuButton extends StatelessWidget {
407412
overflow: TextOverflow.ellipsis,
408413
style: const TextStyle(fontSize: 19, height: 26 / 19)
409414
.merge(weightVariableTextStyle(context, wght: selected ? 600 : 400)))),
415+
?trailing,
410416
]))));
411417
}
412418
}
@@ -457,6 +463,18 @@ class _InboxButton extends _NavigationBarMenuButton {
457463
return zulipLocalizations.inboxPageTitle;
458464
}
459465

466+
@override
467+
Widget? buildTrailing(BuildContext context) {
468+
final store = PerAccountStoreWidget.of(context);
469+
final unreadCount = store.unreads.countInCombinedFeedNarrow();
470+
if (unreadCount == 0) return null;
471+
return UnreadCountBadge(
472+
style: UnreadCountBadgeStyle.mainMenu,
473+
count: unreadCount,
474+
channelIdForBackground: null,
475+
);
476+
}
477+
460478
@override
461479
_HomePageTab get navigationTarget => _HomePageTab.inbox;
462480
}
@@ -472,6 +490,18 @@ class _MentionsButton extends _MenuButton {
472490
return zulipLocalizations.mentionsPageTitle;
473491
}
474492

493+
@override
494+
Widget? buildTrailing(BuildContext context) {
495+
final store = PerAccountStoreWidget.of(context);
496+
final unreadCount = store.unreads.countInMentionsNarrow();
497+
if (unreadCount == 0) return null;
498+
return UnreadCountBadge(
499+
style: UnreadCountBadgeStyle.mainMenu,
500+
count: unreadCount,
501+
channelIdForBackground: null,
502+
);
503+
}
504+
475505
@override
476506
void onPressed(BuildContext context) {
477507
Navigator.of(context).push(MessageListPage.buildRoute(
@@ -541,6 +571,18 @@ class _DirectMessagesButton extends _NavigationBarMenuButton {
541571
return zulipLocalizations.recentDmConversationsPageTitle;
542572
}
543573

574+
@override
575+
Widget? buildTrailing(BuildContext context) {
576+
final store = PerAccountStoreWidget.of(context);
577+
final unreadCount = store.unreads.countInAllDms();
578+
if (unreadCount == 0) return null;
579+
return UnreadCountBadge(
580+
style: UnreadCountBadgeStyle.mainMenu,
581+
count: unreadCount,
582+
channelIdForBackground: null,
583+
);
584+
}
585+
544586
@override
545587
_HomePageTab get navigationTarget => _HomePageTab.directMessages;
546588
}

lib/widgets/unread_count_badge.dart

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@ import 'theme.dart';
1010
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2037-186671&m=dev
1111
/// It looks like that component was created for the main menu,
1212
/// then adapted for various other contexts, like the Inbox page.
13+
/// See [UnreadCountBadgeStyle].
1314
///
14-
/// Currently this widget supports only those other contexts (not the main menu)
15-
/// and only the component's "kind=unread" variant (not "kind=quantity").
16-
/// For example, the "Channels" page and the topic-list page:
17-
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6205-26001&m=dev
18-
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6823-37113&m=dev
19-
/// (We use this for the topic-list page even though the Figma makes it a bit
20-
/// more compact there…the inconsistency seems worse and might be accidental.)
21-
// TODO support the main-menu context, update dartdoc
15+
/// Currently this widget supports only the component's "kind=unread" variant,
16+
/// not "kind=quantity".
2217
// TODO support the "kind=quantity" variant, update dartdoc
2318
class UnreadCountBadge extends StatelessWidget {
2419
const UnreadCountBadge({
2520
super.key,
21+
this.style = UnreadCountBadgeStyle.other,
2622
required this.count,
2723
required this.channelIdForBackground,
2824
});
2925

26+
final UnreadCountBadgeStyle style;
3027
final int count;
3128

3229
/// An optional [Subscription.streamId], for a channel-colorized background.
@@ -55,23 +52,52 @@ class UnreadCountBadge extends StatelessWidget {
5552
backgroundColor = designVariables.bgCounterUnread;
5653
}
5754

55+
final padding = switch (style) {
56+
UnreadCountBadgeStyle.mainMenu =>
57+
const EdgeInsets.symmetric(horizontal: 5, vertical: 4),
58+
UnreadCountBadgeStyle.other =>
59+
const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
60+
};
61+
62+
final double wght = switch (style) {
63+
UnreadCountBadgeStyle.mainMenu => 600,
64+
UnreadCountBadgeStyle.other => 500,
65+
};
66+
5867
return DecoratedBox(
5968
decoration: BoxDecoration(
6069
borderRadius: BorderRadius.circular(5),
6170
color: backgroundColor,
6271
),
6372
child: Padding(
64-
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 3),
73+
padding: padding,
6574
child: Text(
6675
style: TextStyle(
6776
fontSize: 16,
6877
height: (16 / 16),
6978
color: textColor,
70-
).merge(weightVariableTextStyle(context, wght: 500)),
79+
).merge(weightVariableTextStyle(context, wght: wght)),
7180
count.toString())));
7281
}
7382
}
7483

84+
enum UnreadCountBadgeStyle {
85+
/// The style to use in the main menu.
86+
///
87+
/// Figma:
88+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2037-185126&m=dev
89+
mainMenu,
90+
91+
/// The style to use in other contexts besides the main menu.
92+
///
93+
/// Other contexts include the "Channels" page and the topic-list page:
94+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6205-26001&m=dev
95+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=6823-37113&m=dev
96+
/// (We use this for the topic-list page even though the Figma makes it a bit
97+
/// more compact there…the inconsistency seems worse and might be accidental.)
98+
other,
99+
}
100+
75101
class MutedUnreadBadge extends StatelessWidget {
76102
const MutedUnreadBadge({super.key});
77103

0 commit comments

Comments
 (0)