From d373f4c48e0c2bcc520294c9d11ae91223f3e5c5 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 20:15:01 +0100 Subject: [PATCH] feat(app): Runs and Chat tabs badge running runs and unread chats; unread chat rows carry a New badge --- .../ui/sessions/chat_sessions_screen.dart | 12 ++- .../chat/ui/sessions/session_row_content.dart | 31 +++++++- app/lib/features/runs/ui/runs_list.dart | 11 ++- app/lib/shell/adaptive_shell.dart | 20 ++++- app/lib/shell/attention_badge.dart | 66 +++++++++++++++++ app/lib/shell/shell_bar.dart | 73 +++++++++++++++++++ app/test/shell/shell_bar_test.dart | 39 ++++++++++ 7 files changed, 247 insertions(+), 5 deletions(-) diff --git a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart index 7ba10d12..6d83c106 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -251,14 +251,22 @@ class _ChatSessionsScreenState extends State { return ShellBar( active: widget.activeSessionId == null, actions: _actions(), - child: body, + // The Chat tab counts chats with messages not yet seen. + child: ShellBadge( + kind: ShellBadgeKind.unread, + count: _controller.sessions.where(_controller.isUnseen).length, + child: body, + ), ); } return Column( children: [ Align( alignment: AlignmentDirectional.centerEnd, - child: Row(mainAxisSize: MainAxisSize.min, children: _actions()), + child: Row( + mainAxisSize: MainAxisSize.min, + children: _actions(), + ), ), Expanded(child: body), ], diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index 795575c9..42d0d8e3 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -47,7 +47,9 @@ class ChatSessionRowMeta extends StatelessWidget { child: FittedBox( fit: BoxFit.scaleDown, alignment: AlignmentDirectional.centerEnd, - child: Text(status!, maxLines: 1, style: statusStyle), + child: status == 'New' + ? _UnreadBadge(style: statusStyle) + : Text(status!, maxLines: 1, style: statusStyle), ), ), ), @@ -56,3 +58,30 @@ class ChatSessionRowMeta extends StatelessWidget { ); } } + +/// A chat with messages not yet seen: the word in a filled pill. +class _UnreadBadge extends StatelessWidget { + const _UnreadBadge({required this.style}); + + final TextStyle style; + + @override + Widget build(BuildContext context) { + final color = style.color ?? const Color(0xFF0A84FF); + return DecoratedBox( + key: const Key('chat-row-unread'), + decoration: ShapeDecoration(color: color, shape: const StadiumBorder()), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1), + child: Text( + 'New', + maxLines: 1, + style: style.copyWith( + color: const Color(0xFFFFFFFF), + fontWeight: FontWeight.w700, + ), + ), + ), + ); + } +} diff --git a/app/lib/features/runs/ui/runs_list.dart b/app/lib/features/runs/ui/runs_list.dart index 89287e73..5dcda49f 100644 --- a/app/lib/features/runs/ui/runs_list.dart +++ b/app/lib/features/runs/ui/runs_list.dart @@ -84,7 +84,16 @@ class RunsList extends StatelessWidget { ], ); } - return ShellBar(active: active, actions: actions, child: _list(context)); + return ShellBar( + active: active, + actions: actions, + // The Runs tab counts runs still executing. + child: ShellBadge( + kind: ShellBadgeKind.running, + count: controller.runs.where((run) => run['executing'] == true).length, + child: _list(context), + ), + ); } Widget _list(BuildContext context) { diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 76ae06f0..ec39c07d 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -81,8 +81,26 @@ class _AdaptiveShellState extends State { /// The destination's icon; only Runs carries the attention count. Widget _icon(AppDestination destination, IconData data) { - final icon = Icon(data); + Widget icon = Icon(data); + if (destination == AppDestination.chat) { + return ActivityBadge( + key: const ValueKey('shell.badge.chat.unread'), + count: _bar.badge(destination, ShellBadgeKind.unread), + label: 'unread chats', + cupertino: widget.cupertino, + child: icon, + ); + } if (destination != AppDestination.runs) return icon; + // Runs in progress at the bottom, runs that need you at the top. + icon = ActivityBadge( + key: const ValueKey('shell.badge.runs.running'), + count: _bar.badge(destination, ShellBadgeKind.running), + label: 'runs in progress', + cupertino: widget.cupertino, + bottom: true, + child: icon, + ); return AttentionDestinationIcon( count: widget.attentionCount, cupertino: widget.cupertino, diff --git a/app/lib/shell/attention_badge.dart b/app/lib/shell/attention_badge.dart index 6cf21f45..6e88d04e 100644 --- a/app/lib/shell/attention_badge.dart +++ b/app/lib/shell/attention_badge.dart @@ -80,3 +80,69 @@ class _CupertinoCountOverlay extends StatelessWidget { ); } } + +/// A small count on a tab icon: blue for activity (runs in progress, unread +/// chats), so it reads apart from the red needs-you count. +class ActivityBadge extends StatelessWidget { + const ActivityBadge({ + super.key, + required this.count, + required this.label, + required this.cupertino, + required this.child, + this.bottom = false, + }); + + final int count; + final String label; + final bool cupertino; + final bool bottom; + final Widget child; + + @override + Widget build(BuildContext context) { + if (count <= 0) return child; + final color = cupertino + ? CupertinoColors.systemBlue.resolveFrom(context) + : Theme.of(context).colorScheme.primary; + final text = cupertino + ? CupertinoColors.white + : Theme.of(context).colorScheme.onPrimary; + return Semantics( + label: '$count $label', + child: ExcludeSemantics( + child: Stack( + clipBehavior: Clip.none, + children: [ + child, + PositionedDirectional( + top: bottom ? null : -6, + bottom: bottom ? -6 : null, + end: -10, + child: DecoratedBox( + decoration: ShapeDecoration( + color: color, + shape: const StadiumBorder(), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 5, + vertical: 1, + ), + child: Text( + '$count', + style: TextStyle( + color: text, + fontSize: 10, + fontWeight: FontWeight.w700, + ), + ), + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/app/lib/shell/shell_bar.dart b/app/lib/shell/shell_bar.dart index 74185cb4..7d8f3c0d 100644 --- a/app/lib/shell/shell_bar.dart +++ b/app/lib/shell/shell_bar.dart @@ -15,6 +15,18 @@ class ShellBarSpec { /// The bar contents each tab's open screen has published. class ShellBarRegistry extends ChangeNotifier { final Map _specs = {}; + final Map<(AppDestination, ShellBadgeKind), int> _badges = {}; + + /// The count a tab's screen published for [kind], 0 when none. + int badge(AppDestination destination, ShellBadgeKind kind) => + _badges[(destination, kind)] ?? 0; + + void _setBadge(AppDestination destination, ShellBadgeKind kind, int count) { + if (_disposed || badge(destination, kind) == count) return; + _badges[(destination, kind)] = count; + notifyListeners(); + } + bool _disposed = false; @override @@ -138,3 +150,64 @@ class _ShellBarState extends State { return widget.child; } } + +/// What a tab badge counts. +enum ShellBadgeKind { + /// Runs still executing. + running, + + /// Chats with messages not yet seen. + unread, +} + +/// Publishes a count for this tab's badge while [child] is mounted. +class ShellBadge extends StatefulWidget { + const ShellBadge({ + super.key, + required this.kind, + required this.count, + required this.child, + }); + + final ShellBadgeKind kind; + final int count; + final Widget child; + + @override + State createState() => _ShellBadgeState(); +} + +class _ShellBadgeState extends State { + ShellBarScope? _scope; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _scope = ShellBarScope.maybeOf(context); + } + + @override + void dispose() { + final scope = _scope; + final kind = widget.kind; + if (scope != null) { + WidgetsBinding.instance.addPostFrameCallback( + (_) => scope.registry._setBadge(scope.destination, kind, 0), + ); + } + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final scope = _scope; + if (scope != null) { + final count = widget.count; + final kind = widget.kind; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) scope.registry._setBadge(scope.destination, kind, count); + }); + } + return widget.child; + } +} diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index 3f681911..4b7486ae 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -60,4 +60,43 @@ void main() { expect(find.byKey(const ValueKey('shell.search')), findsNothing); }); } + + testWidgets('tabs show the running and unread counts their screens publish', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + home: AdaptiveShell( + destination: AppDestination.runs, + destinationBodies: { + AppDestination.runs: (_) => const ShellBadge( + kind: ShellBadgeKind.running, + count: 2, + child: Text('runs'), + ), + }, + ), + ), + ); + await tester.pump(); + final running = find.byKey(const ValueKey('shell.badge.runs.running')); + expect( + find.descendant(of: running, matching: find.text('2')), + findsOneWidget, + ); + expect( + find.byKey(const ValueKey('shell.badge.chat.unread')), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byKey(const ValueKey('shell.badge.chat.unread')), + matching: find.byType(Text), + ), + findsNothing, + ); + }); }