From d4df1f787c9d6acd3b9a8df07e6a229ef922a38b Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 13:10:14 +0100 Subject: [PATCH] feat(app): chat list toolbar keeps New chat beside search, as the web --- .../chat/ui/sessions/chat_adaptive.dart | 79 ++++++++++++++----- .../ui/sessions/chat_sessions_screen.dart | 35 ++++---- .../chat/ui/sessions/chat_toolbar_test.dart | 38 +++++++++ 3 files changed, 117 insertions(+), 35 deletions(-) create mode 100644 app/test/features/chat/ui/sessions/chat_toolbar_test.dart diff --git a/app/lib/features/chat/ui/sessions/chat_adaptive.dart b/app/lib/features/chat/ui/sessions/chat_adaptive.dart index beedac9f..9a2651e2 100644 --- a/app/lib/features/chat/ui/sessions/chat_adaptive.dart +++ b/app/lib/features/chat/ui/sessions/chat_adaptive.dart @@ -52,38 +52,81 @@ class ChatBarAction extends StatelessWidget { } } +/// The chat toolbar's one primary create action, labelled as on the web +/// (`+ New chat`), not an unlabelled glyph. +class ChatNewChatButton extends StatelessWidget { + const ChatNewChatButton({super.key, required this.onPressed}); + + final VoidCallback onPressed; + + @override + Widget build(BuildContext context) { + if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { + return CupertinoButton.filled( + sizeStyle: CupertinoButtonSize.small, + onPressed: onPressed, + child: const Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(CupertinoIcons.add, size: 16), + SizedBox(width: 4), + Text('New chat'), + ], + ), + ); + } + return FilledButton.icon( + onPressed: onPressed, + icon: const Icon(Icons.add), + label: const Text('New chat'), + ); + } +} + class ChatSearchField extends StatelessWidget { const ChatSearchField({ super.key, required this.controller, required this.onChanged, + this.trailing = const [], }); final TextEditingController controller; final ValueChanged onChanged; + /// Actions on the search row's trailing edge, as the web's chat toolbar + /// keeps New chat beside its search input. + final List trailing; + @override Widget build(BuildContext context) { - if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { - return Padding( - padding: const EdgeInsets.all(16), - child: CupertinoSearchTextField( - controller: controller, - placeholder: 'Search chats', - onChanged: onChanged, - ), - ); - } + final field = chatControlsStyleOf(context) == ChatControlsStyle.cupertino + ? CupertinoSearchTextField( + controller: controller, + placeholder: 'Search chats', + onChanged: onChanged, + ) + : TextField( + controller: controller, + onChanged: onChanged, + decoration: const InputDecoration( + prefixIcon: Icon(Icons.search), + labelText: 'Search chats', + ), + ); return Padding( padding: const EdgeInsets.all(16), - child: TextField( - controller: controller, - onChanged: onChanged, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.search), - labelText: 'Search chats', - ), - ), + child: trailing.isEmpty + ? field + : Row( + children: [ + Expanded(child: field), + for (final action in trailing) ...[ + const SizedBox(width: 8), + action, + ], + ], + ), ); } } 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 4579cf73..16578eb9 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -190,6 +190,23 @@ class _ChatSessionsScreenState extends State { ChatSearchField( controller: _search, onChanged: (_) => setState(() {}), + // Embedded under the shell there is no bar of its own: the + // create action sits beside search, as the web's chat toolbar. + trailing: widget.embedded + ? [ + ChatNewChatButton( + key: const Key('chat-new-chat'), + onPressed: _newChat, + ), + ChatBarAction( + key: const Key('chat-refresh'), + label: 'Refresh', + onPressed: _controller.refresh, + materialIcon: Icons.refresh, + cupertinoIcon: CupertinoIcons.refresh, + ), + ] + : const [], ), if (_controller.error != null) ChatErrorNotice( @@ -247,23 +264,7 @@ class _ChatSessionsScreenState extends State { ], ); - if (widget.embedded) { - return Column( - children: [ - Align( - alignment: AlignmentDirectional.centerEnd, - child: Padding( - padding: const EdgeInsetsDirectional.only(end: 8), - child: Row( - mainAxisSize: MainAxisSize.min, - children: _actions(), - ), - ), - ), - Expanded(child: body), - ], - ); - } + if (widget.embedded) return body; if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { return CupertinoPageScaffold( diff --git a/app/test/features/chat/ui/sessions/chat_toolbar_test.dart b/app/test/features/chat/ui/sessions/chat_toolbar_test.dart new file mode 100644 index 00000000..b8b93a15 --- /dev/null +++ b/app/test/features/chat/ui/sessions/chat_toolbar_test.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; + +import 'chat_test_harness.dart'; +import 'fake_chat_gateway.dart'; + +void main() { + testWidgets('embedded, New chat sits beside search on one toolbar row', ( + tester, + ) async { + final gateway = FakeChatGateway() + ..sessionsReply = {'chat_sessions': sampleSessions()}; + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(platform: TargetPlatform.android), + home: Scaffold( + body: ChatSessionsScreen( + gateway: gateway, + onOpen: (_) {}, + embedded: true, + localStore: MemoryChatSessionLocalStore(), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + final search = tester.getCenter(find.byType(TextField)); + final create = find.byKey(const Key('chat-new-chat')); + expect( + find.descendant(of: create, matching: find.text('New chat')), + findsOneWidget, + ); + expect((tester.getCenter(create).dy - search.dy).abs(), lessThan(4)); + expect(tester.getCenter(create).dx, greaterThan(search.dx)); + }); +}