diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 827051fd..bc08935d 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -2,6 +2,8 @@ part of 'screen.dart'; /// Pane layout, focus and route publication for one Chat destination visit. mixin _ChatScreenWorkspace on State { + final _sessionsKey = GlobalKey(); + Map get _openedSessions; ChatComposerFocusRequests get _composerFocus; ChatPaneCommands get _paneCommands; @@ -46,6 +48,10 @@ mixin _ChatScreenWorkspace on State { activeSessionId: selected, visibleSessionIds: _visibleSidebarSessions, onOpen: _openSidebarSession, + onNewChat: () { + final state = _sessionsKey.currentState; + if (state != null) unawaited(state.newChat()); + }, onExpand: () => _setSidebarMode(ChatSidebarMode.expanded), ), ], diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index dadd1888..9f8d91d3 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -485,6 +485,7 @@ class _ChatScreenState extends State // The session list pads its first row by the bar's height itself, so it // scrolls behind the shell's floating bar like the other lists. final sessions = ChatSessionsScreen( + key: _sessionsKey, gateway: widget.gateway, embedded: true, syncToken: widget.syncToken, diff --git a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart index 587e205c..0fcefb8b 100644 --- a/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart +++ b/app/lib/features/chat/ui/sessions/chat_compact_sidebar.dart @@ -23,6 +23,7 @@ class ChatCompactSidebar extends StatelessWidget { required this.activeSessionId, this.visibleSessionIds = const {}, required this.onOpen, + required this.onNewChat, required this.onExpand, this.navigation, }); @@ -31,6 +32,7 @@ class ChatCompactSidebar extends StatelessWidget { final String? activeSessionId; final Set visibleSessionIds; final ValueChanged onOpen; + final VoidCallback onNewChat; final VoidCallback onExpand; final Widget? navigation; static const width = 72.0; @@ -135,6 +137,7 @@ class ChatCompactSidebar extends StatelessWidget { width: width, child: Column( children: [ + _button(context, 'New chat', const Icon(Icons.add), onNewChat), _button( context, 'Expand chat list', 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 d789d670..3238a49f 100644 --- a/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart +++ b/app/lib/features/chat/ui/sessions/chat_sessions_screen.dart @@ -98,10 +98,10 @@ class ChatSessionsScreen extends StatefulWidget { final ChatSectionFolds? folds; @override - State createState() => _ChatSessionsScreenState(); + ChatSessionsScreenState createState() => ChatSessionsScreenState(); } -class _ChatSessionsScreenState extends State { +class ChatSessionsScreenState extends State { late final ChatSessionsController _controller = (widget.controller ?? ChatSessionsController( @@ -233,6 +233,9 @@ class _ChatSessionsScreenState extends State { if (session != null && mounted) widget.onOpen(session); } + /// Starts the same machine picker and create dialog used by the list action. + Future newChat() => _newChat(); + void _markOpened(JsonMap session) => unawaited(_controller.markOpened(session)); diff --git a/app/notes/chat-compact-new-chat.md b/app/notes/chat-compact-new-chat.md new file mode 100644 index 00000000..54f0f0ea --- /dev/null +++ b/app/notes/chat-compact-new-chat.md @@ -0,0 +1,23 @@ +# Compact sidebar New chat + +The compact chat rail now keeps a Material `+` action above its scrolling +session list. Its callback reaches the mounted `ChatSessionsScreenState` and +invokes the existing `_newChat` flow, so machine selection, harness discovery, +and the create dialog remain shared with the expanded list action. + +## Regression coverage + +- `test/features/chat/ui/sessions/chat_visibility_marker_test.dart`: the rail + exposes the `New chat` tooltip and invokes its callback. +- `test/features/chat/ui/sessions/chat_machine_creation_test.dart`: the + existing expanded-list flow still selects a machine before harness discovery. +- `test/features/chat/ui/sessions/chat_sessions_floating_bar_test.dart`: the + expanded list still has exactly one New chat action in its bar. + +## Verification + +- `tool/memwatch/full.sh 'test/features/chat/ui/sessions/chat_visibility_marker_test.dart test/features/chat/ui/sessions/chat_state_legibility_test.dart test/features/chat/ui/sessions/chat_machine_creation_test.dart test/features/chat/ui/sessions/chat_sessions_floating_bar_test.dart'`: 10 passed. +- `tool/analyze.sh`: clean. +- Browser captures: desktop 1600x1000 compact rail in light and dark themes, + including the New chat tooltip, are in the shared artifact + `public/chat-compact-sidebar/`. diff --git a/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart b/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart index d6855d17..6540c66c 100644 --- a/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart +++ b/app/test/features/chat/ui/sessions/chat_state_legibility_test.dart @@ -85,6 +85,7 @@ void main() { activeSessionId: null, visibleSessionIds: const {'a'}, onOpen: (_) {}, + onNewChat: () {}, onExpand: () {}, navigation: const Text('Destinations'), ), @@ -139,6 +140,7 @@ void main() { activeSessionId: 'a', visibleSessionIds: const {'a', 'b'}, onOpen: (_) {}, + onNewChat: () {}, onExpand: () {}, ), ), diff --git a/app/test/features/chat/ui/sessions/chat_visibility_marker_test.dart b/app/test/features/chat/ui/sessions/chat_visibility_marker_test.dart index 7642e111..ab8b569b 100644 --- a/app/test/features/chat/ui/sessions/chat_visibility_marker_test.dart +++ b/app/test/features/chat/ui/sessions/chat_visibility_marker_test.dart @@ -107,6 +107,7 @@ void main() { await controller.refresh(); final folds = ChatSectionFolds(); addTearDown(folds.dispose); + var newChatPressed = false; await tester.pumpWidget( MaterialApp( home: Scaffold( @@ -116,12 +117,16 @@ void main() { activeSessionId: 'a', visibleSessionIds: const {'a', 'b'}, onOpen: (_) {}, + onNewChat: () => newChatPressed = true, onExpand: () {}, ), ), ), ); await tester.pumpAndSettle(); + expect(find.byTooltip('New chat'), findsOneWidget); + await tester.tap(find.byTooltip('New chat')); + expect(newChatPressed, isTrue); expect(find.byTooltip('Expand chat list'), findsOneWidget); expect(edge(tester, 'a').width, 10); expect(edge(tester, 'b').width, 3);