Add New chat to compact sidebar

Expose the existing chat creation flow from the compact rail so users can start chats without expanding the session list. Add focused callback coverage and document the verified behavior.
This commit is contained in:
2026-11-13 12:14:16 +00:00
parent df0614e2f7
commit 0a51add958
7 changed files with 45 additions and 2 deletions
@@ -2,6 +2,8 @@ part of 'screen.dart';
/// Pane layout, focus and route publication for one Chat destination visit.
mixin _ChatScreenWorkspace on State<ChatScreen> {
final _sessionsKey = GlobalKey<ChatSessionsScreenState>();
Map<String, JsonMap> get _openedSessions;
ChatComposerFocusRequests get _composerFocus;
ChatPaneCommands get _paneCommands;
@@ -46,6 +48,10 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
activeSessionId: selected,
visibleSessionIds: _visibleSidebarSessions,
onOpen: _openSidebarSession,
onNewChat: () {
final state = _sessionsKey.currentState;
if (state != null) unawaited(state.newChat());
},
onExpand: () => _setSidebarMode(ChatSidebarMode.expanded),
),
],
+1
View File
@@ -485,6 +485,7 @@ class _ChatScreenState extends State<ChatScreen>
// 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,
@@ -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<String> visibleSessionIds;
final ValueChanged<JsonMap> 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',
@@ -98,10 +98,10 @@ class ChatSessionsScreen extends StatefulWidget {
final ChatSectionFolds? folds;
@override
State<ChatSessionsScreen> createState() => _ChatSessionsScreenState();
ChatSessionsScreenState createState() => ChatSessionsScreenState();
}
class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
class ChatSessionsScreenState extends State<ChatSessionsScreen> {
late final ChatSessionsController _controller =
(widget.controller ??
ChatSessionsController(
@@ -233,6 +233,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
if (session != null && mounted) widget.onOpen(session);
}
/// Starts the same machine picker and create dialog used by the list action.
Future<void> newChat() => _newChat();
void _markOpened(JsonMap session) =>
unawaited(_controller.markOpened(session));
+23
View File
@@ -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/`.
@@ -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: () {},
),
),
@@ -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);