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));