Allow adding chats on phones and keep their native detail route

This commit is contained in:
2026-11-06 21:46:45 +00:00
parent 6bba6cf8d8
commit 2cd8003e3a
5 changed files with 152 additions and 11 deletions
@@ -6,6 +6,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
ChatComposerFocusRequests get _composerFocus;
JsonMap? _rowFor(String id);
void _back();
bool get _pageOpen;
Widget _thread(
String selected,
VoidCallback onBack, {
@@ -193,8 +194,15 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
if (id.isEmpty) return;
_openedSessions[id] = session;
_workspaceVisible = true;
if (!_pageOpen && showsListBesideDetail(context)) _usedWorkspace = true;
_workspace.splitActive(id, axis);
_composerFocus.request(id);
if (showsListBesideDetail(context) ||
chatSelectionFocusesComposer(const {})) {
_composerFocus.request(id);
} else {
_composerFocus.cancel();
FocusManager.instance.primaryFocus?.unfocus();
}
}
void _openBeside(JsonMap session) =>
@@ -225,11 +233,34 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
},
);
void _addPane(BuildContext context) {
final opened = _workspace.panes.map((pane) => pane.sessionId).toSet();
final available = _sessionsForSidebar.sessions
.where((row) => !opened.contains('${row['id'] ?? ''}'))
.toList();
showChatPanePicker(
context,
title: available.isEmpty
? 'All available chats are already open'
: 'Add chat pane',
panes: [
for (final row in available)
(id: '${row['id']}', title: chatSessionTitle(row)),
],
activeId: null,
onSelected: (id) =>
_openBelow(available.firstWhere((row) => row['id'] == id)),
);
}
Widget _workspaceView() => ChatWorkspace(
key: _workspaceKey,
controller: _workspace,
shortcutsEnabled: _workspaceVisible,
singlePane: !showsListBesideDetail(context),
mobilePeeks: !showsListBesideDetail(context),
paneTitle: (pane) =>
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
paneBuilder: (context, pane, active) => Semantics(
selected: active,
@@ -9,13 +9,14 @@ Future<void> showChatPanePicker(
required List<({String id, String title})> panes,
required String? activeId,
required ValueChanged<String> onSelected,
String title = 'Open chats',
}) async {
final String? selected;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
selected = await showCupertinoModalPopup<String>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Open chats'),
title: Text(title),
actions: [
for (final pane in panes)
CupertinoActionSheetAction(
@@ -34,7 +35,7 @@ Future<void> showChatPanePicker(
selected = await showDialog<String>(
context: context,
builder: (context) => SimpleDialog(
title: const Text('Open chats'),
title: Text(title),
children: [
for (final pane in panes)
SimpleDialogOption(
+18 -5
View File
@@ -30,6 +30,7 @@ import 'conversation/composer_selection_focus.dart';
import 'data/chat_repository.dart';
import 'domain/chat_commands.dart';
import 'domain/chat_cycle.dart';
import 'domain/chat_sessions.dart';
import 'ui/sessions/chat_sessions_body.dart';
import 'ui/sessions/chat_sessions_controller.dart';
import 'ui/sessions/chat_sessions_screen.dart';
@@ -364,6 +365,8 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
/// On a phone the open chat is a real page above the main screen.
final DetailPageHost _page = DetailPageHost();
@override
bool get _pageOpen => _page.open;
@override
void didUpdateWidget(covariant ChatScreen oldWidget) {
@@ -429,13 +432,22 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
onNextChat: _nextAfter(selected) != null
? () => _openNext(selected)
: null,
showBackButton: pane == null ? null : !showsListBesideDetail(context),
sidebarControl: pane == null || !showsListBesideDetail(context)
showBackButton: pane == null
? null
: _page.open || !showsListBesideDetail(context),
sidebarControl:
pane == null || _page.open || !showsListBesideDetail(context)
? null
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
paneControls: pane == null
? const []
: [
ChatBarAction(
label: 'Add chat pane',
onPressed: () => _addPane(paneContext ?? context),
materialIcon: Icons.add_box_outlined,
cupertinoIcon: CupertinoIcons.plus_square,
),
if (_workspace.paneCount > 1)
ChatBarAction(
label: 'Open chats (${_workspace.paneCount})',
@@ -471,7 +483,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
// A phone opens a chat as a real Navigator page with stock Back. A wide
// window keeps the destination rail and the chat list beside the open
// chat, which has no Back: another row, `/close` or a route change swaps it.
final beside = showsListBesideDetail(context);
final beside = !_page.open && showsListBesideDetail(context);
if (beside && selected != null) _usedWorkspace = true;
_page.sync(
context,
@@ -480,7 +492,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
onClosed: _back,
builder: (context) => selected == null
? const SizedBox.shrink()
: _thread(selected, () => Navigator.of(context).maybePop()),
: ShellBar(barless: true, child: _workspaceView()),
);
// 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.
@@ -492,7 +504,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
folds: _folds,
onOpen: _openBySelection,
onOpenBeside: beside ? _openBeside : null,
onOpenBelow: beside ? _openBelow : null,
onOpenBelow: _openBelow,
onShortcutOpen: _openByShortcut,
onSessions: _adoptRows,
activeSessionId: selected,
@@ -515,6 +527,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
child: ShellBar(
active: selected != null,
barless: true,
hideNavigation: true,
child: Stack(
fit: StackFit.expand,
children: [