Skip to content

Commit 72f172d

Browse files
committed
home: Show unread counts in main menu
Fixes-partly: #1088
1 parent d5cc7fc commit 72f172d

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
@@ -23,6 +23,7 @@ import 'store.dart';
2323
import 'subscription_list.dart';
2424
import 'text.dart';
2525
import 'theme.dart';
26+
import 'unread_count_badge.dart';
2627
import 'user.dart';
2728

2829
enum _HomePageTab {
@@ -419,6 +420,8 @@ abstract class _MenuButton extends StatelessWidget {
419420
color: selected ? designVariables.iconSelected : designVariables.icon);
420421
}
421422

423+
Widget? buildTrailing(BuildContext context) => null;
424+
422425
void onPressed(BuildContext context);
423426

424427
void _handlePress(BuildContext context) {
@@ -459,6 +462,8 @@ abstract class _MenuButton extends StatelessWidget {
459462
~WidgetState.pressed: selected ? borderSideSelected : null,
460463
}));
461464

465+
final trailing = buildTrailing(context);
466+
462467
return AnimatedScaleOnTap(
463468
duration: const Duration(milliseconds: 100),
464469
scaleEnd: 0.95,
@@ -475,6 +480,7 @@ abstract class _MenuButton extends StatelessWidget {
475480
overflow: TextOverflow.ellipsis,
476481
style: const TextStyle(fontSize: 19, height: 26 / 19)
477482
.merge(weightVariableTextStyle(context, wght: selected ? 600 : 400)))),
483+
?trailing,
478484
]))));
479485
}
480486
}
@@ -525,6 +531,18 @@ class _InboxButton extends _NavigationBarMenuButton {
525531
return zulipLocalizations.inboxPageTitle;
526532
}
527533

534+
@override
535+
Widget? buildTrailing(BuildContext context) {
536+
final store = PerAccountStoreWidget.of(context);
537+
final unreadCount = store.unreads.countInCombinedFeedNarrow();
538+
if (unreadCount == 0) return null;
539+
return UnreadCountBadge(
540+
style: UnreadCountBadgeStyle.mainMenu,
541+
count: unreadCount,
542+
channelIdForBackground: null,
543+
);
544+
}
545+
528546
@override
529547
_HomePageTab get navigationTarget => _HomePageTab.inbox;
530548
}
@@ -540,6 +558,18 @@ class _MentionsButton extends _MenuButton {
540558
return zulipLocalizations.mentionsPageTitle;
541559
}
542560

561+
@override
562+
Widget? buildTrailing(BuildContext context) {
563+
final store = PerAccountStoreWidget.of(context);
564+
final unreadCount = store.unreads.countInMentionsNarrow();
565+
if (unreadCount == 0) return null;
566+
return UnreadCountBadge(
567+
style: UnreadCountBadgeStyle.mainMenu,
568+
count: unreadCount,
569+
channelIdForBackground: null,
570+
);
571+
}
572+
543573
@override
544574
void onPressed(BuildContext context) {
545575
Navigator.of(context).push(MessageListPage.buildRoute(
@@ -609,6 +639,18 @@ class _DirectMessagesButton extends _NavigationBarMenuButton {
609639
return zulipLocalizations.recentDmConversationsPageTitle;
610640
}
611641

642+
@override
643+
Widget? buildTrailing(BuildContext context) {
644+
final store = PerAccountStoreWidget.of(context);
645+
final unreadCount = store.unreads.countInDms();
646+
if (unreadCount == 0) return null;
647+
return UnreadCountBadge(
648+
style: UnreadCountBadgeStyle.mainMenu,
649+
count: unreadCount,
650+
channelIdForBackground: null,
651+
);
652+
}
653+
612654
@override
613655
_HomePageTab get navigationTarget => _HomePageTab.directMessages;
614656
}

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)