Allow adding chats on phones and keep their native detail route
This commit is contained in:
@@ -6,6 +6,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
|||||||
ChatComposerFocusRequests get _composerFocus;
|
ChatComposerFocusRequests get _composerFocus;
|
||||||
JsonMap? _rowFor(String id);
|
JsonMap? _rowFor(String id);
|
||||||
void _back();
|
void _back();
|
||||||
|
bool get _pageOpen;
|
||||||
Widget _thread(
|
Widget _thread(
|
||||||
String selected,
|
String selected,
|
||||||
VoidCallback onBack, {
|
VoidCallback onBack, {
|
||||||
@@ -193,8 +194,15 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
|||||||
if (id.isEmpty) return;
|
if (id.isEmpty) return;
|
||||||
_openedSessions[id] = session;
|
_openedSessions[id] = session;
|
||||||
_workspaceVisible = true;
|
_workspaceVisible = true;
|
||||||
|
if (!_pageOpen && showsListBesideDetail(context)) _usedWorkspace = true;
|
||||||
_workspace.splitActive(id, axis);
|
_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) =>
|
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(
|
Widget _workspaceView() => ChatWorkspace(
|
||||||
key: _workspaceKey,
|
key: _workspaceKey,
|
||||||
controller: _workspace,
|
controller: _workspace,
|
||||||
shortcutsEnabled: _workspaceVisible,
|
shortcutsEnabled: _workspaceVisible,
|
||||||
singlePane: !showsListBesideDetail(context),
|
singlePane: !showsListBesideDetail(context),
|
||||||
|
mobilePeeks: !showsListBesideDetail(context),
|
||||||
|
paneTitle: (pane) =>
|
||||||
|
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
|
||||||
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
|
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
|
||||||
paneBuilder: (context, pane, active) => Semantics(
|
paneBuilder: (context, pane, active) => Semantics(
|
||||||
selected: active,
|
selected: active,
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ Future<void> showChatPanePicker(
|
|||||||
required List<({String id, String title})> panes,
|
required List<({String id, String title})> panes,
|
||||||
required String? activeId,
|
required String? activeId,
|
||||||
required ValueChanged<String> onSelected,
|
required ValueChanged<String> onSelected,
|
||||||
|
String title = 'Open chats',
|
||||||
}) async {
|
}) async {
|
||||||
final String? selected;
|
final String? selected;
|
||||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||||
selected = await showCupertinoModalPopup<String>(
|
selected = await showCupertinoModalPopup<String>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => CupertinoActionSheet(
|
builder: (context) => CupertinoActionSheet(
|
||||||
title: const Text('Open chats'),
|
title: Text(title),
|
||||||
actions: [
|
actions: [
|
||||||
for (final pane in panes)
|
for (final pane in panes)
|
||||||
CupertinoActionSheetAction(
|
CupertinoActionSheetAction(
|
||||||
@@ -34,7 +35,7 @@ Future<void> showChatPanePicker(
|
|||||||
selected = await showDialog<String>(
|
selected = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => SimpleDialog(
|
builder: (context) => SimpleDialog(
|
||||||
title: const Text('Open chats'),
|
title: Text(title),
|
||||||
children: [
|
children: [
|
||||||
for (final pane in panes)
|
for (final pane in panes)
|
||||||
SimpleDialogOption(
|
SimpleDialogOption(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import 'conversation/composer_selection_focus.dart';
|
|||||||
import 'data/chat_repository.dart';
|
import 'data/chat_repository.dart';
|
||||||
import 'domain/chat_commands.dart';
|
import 'domain/chat_commands.dart';
|
||||||
import 'domain/chat_cycle.dart';
|
import 'domain/chat_cycle.dart';
|
||||||
|
import 'domain/chat_sessions.dart';
|
||||||
import 'ui/sessions/chat_sessions_body.dart';
|
import 'ui/sessions/chat_sessions_body.dart';
|
||||||
import 'ui/sessions/chat_sessions_controller.dart';
|
import 'ui/sessions/chat_sessions_controller.dart';
|
||||||
import 'ui/sessions/chat_sessions_screen.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.
|
/// On a phone the open chat is a real page above the main screen.
|
||||||
final DetailPageHost _page = DetailPageHost();
|
final DetailPageHost _page = DetailPageHost();
|
||||||
|
@override
|
||||||
|
bool get _pageOpen => _page.open;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant ChatScreen oldWidget) {
|
void didUpdateWidget(covariant ChatScreen oldWidget) {
|
||||||
@@ -429,13 +432,22 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
|||||||
onNextChat: _nextAfter(selected) != null
|
onNextChat: _nextAfter(selected) != null
|
||||||
? () => _openNext(selected)
|
? () => _openNext(selected)
|
||||||
: null,
|
: null,
|
||||||
showBackButton: pane == null ? null : !showsListBesideDetail(context),
|
showBackButton: pane == null
|
||||||
sidebarControl: pane == null || !showsListBesideDetail(context)
|
? null
|
||||||
|
: _page.open || !showsListBesideDetail(context),
|
||||||
|
sidebarControl:
|
||||||
|
pane == null || _page.open || !showsListBesideDetail(context)
|
||||||
? null
|
? null
|
||||||
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
|
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
|
||||||
paneControls: pane == null
|
paneControls: pane == null
|
||||||
? const []
|
? const []
|
||||||
: [
|
: [
|
||||||
|
ChatBarAction(
|
||||||
|
label: 'Add chat pane',
|
||||||
|
onPressed: () => _addPane(paneContext ?? context),
|
||||||
|
materialIcon: Icons.add_box_outlined,
|
||||||
|
cupertinoIcon: CupertinoIcons.plus_square,
|
||||||
|
),
|
||||||
if (_workspace.paneCount > 1)
|
if (_workspace.paneCount > 1)
|
||||||
ChatBarAction(
|
ChatBarAction(
|
||||||
label: 'Open chats (${_workspace.paneCount})',
|
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
|
// 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
|
// 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.
|
// 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;
|
if (beside && selected != null) _usedWorkspace = true;
|
||||||
_page.sync(
|
_page.sync(
|
||||||
context,
|
context,
|
||||||
@@ -480,7 +492,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
|||||||
onClosed: _back,
|
onClosed: _back,
|
||||||
builder: (context) => selected == null
|
builder: (context) => selected == null
|
||||||
? const SizedBox.shrink()
|
? 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
|
// 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.
|
// scrolls behind the shell's floating bar like the other lists.
|
||||||
@@ -492,7 +504,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
|||||||
folds: _folds,
|
folds: _folds,
|
||||||
onOpen: _openBySelection,
|
onOpen: _openBySelection,
|
||||||
onOpenBeside: beside ? _openBeside : null,
|
onOpenBeside: beside ? _openBeside : null,
|
||||||
onOpenBelow: beside ? _openBelow : null,
|
onOpenBelow: _openBelow,
|
||||||
onShortcutOpen: _openByShortcut,
|
onShortcutOpen: _openByShortcut,
|
||||||
onSessions: _adoptRows,
|
onSessions: _adoptRows,
|
||||||
activeSessionId: selected,
|
activeSessionId: selected,
|
||||||
@@ -515,6 +527,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
|||||||
child: ShellBar(
|
child: ShellBar(
|
||||||
active: selected != null,
|
active: selected != null,
|
||||||
barless: true,
|
barless: true,
|
||||||
|
hideNavigation: true,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Mobile chat panes
|
||||||
|
|
||||||
|
Phones can add a chat with the header's **Add chat pane** action (in More if space is tight). The session list also offers **Open below** on narrow windows. The native picker lists chats not already open.
|
||||||
|
|
||||||
|
Narrow windows show two retained conversations stacked: the active pane gets80% of the available height and one inactive preview gets20%, separated by6 logical pixels. Tapping a preview animates their heights over220ms. Reduced-motion settings switch immediately. An accessible preview names the chat it will expand. Pointer switching unfocuses inputs and does not request the new composer's keyboard.
|
||||||
|
|
||||||
|
With more than two retained chats, the active pane and previous active pane are visible; **Open chats** accesses every retained pane. The presentation never rewrites stored desktop split ratios. Every thread remains a stable keyed sibling, preserving drafts and transcript state. A small preview clips a full-height layout instead of squeezing its composer into a tiny viewport.
|
||||||
|
|
||||||
|
A chat first opened on a phone stays in its native full-screen detail route while adding panes or unfolding. It already uses the full width; Back returns to the list. The sidebar control is absent on this full-screen route. A chat first opened in the wide list/detail workspace keeps the existing sidebar expanded/compact/hidden control and changes to mobile previews when folded. The destination bar stays hidden while this narrow chat workspace is open, so it cannot overlap either composer or preview.
|
||||||
|
|
||||||
|
Checks: bounded analysis clean;7 real-screen split tests passed, including first-phone-split draft/state identity, exactly one initial Back control, large text with300px keyboard inset and desktop/narrow restoration;23 workspace/controller/persistence tests passed, including intermediate animation geometry, reduced motion and three retained panes;10 list-shortcut tests passed. Tests use the memory watchdog.
|
||||||
|
|
||||||
|
Rendered browser evidence: `/private/tmp/mobile-panes-phone-final/` (Material/light560x1000, Add pane, draft retention, real peek taps, no native input focus after a peek switch, unfold880); `/private/tmp/mobile-panes-unfolded-final/` (Cupertino/dark880x1100 hidden sidebar, fold560x1000, switch). All8 final screenshots/contact sheet were inspected; reports have no errors. The phone film contact sheet and10 frame files show the actual220ms transition, including intermediate frames. Test browsers/servers exited. No physical Fold testing, backend change or deployment was performed in this lane.
|
||||||
@@ -79,6 +79,90 @@ Future<void> _split(WidgetTester tester, String id, String action) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
testWidgets('phone peeks fit a small keyboard viewport at large text', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
tester.view.physicalSize = const Size(560, 700);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||||
|
addTearDown(gateway.close);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
builder: (context, child) => MediaQuery(
|
||||||
|
data: MediaQuery.of(
|
||||||
|
context,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(2)),
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
|
home: Scaffold(body: ChatScreen(gateway: gateway)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Chat a').first);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final controller = tester
|
||||||
|
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||||
|
.controller;
|
||||||
|
controller.splitActive('b', ChatSplitAxis.vertical);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(_thread('a'), findsOneWidget);
|
||||||
|
expect(_thread('b'), findsOneWidget);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
testWidgets('phone can add a second chat without losing its first draft', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
tester.view.physicalSize = const Size(560, 1000);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||||
|
addTearDown(gateway.close);
|
||||||
|
await tester.pumpWidget(_app(gateway));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Chat a').first);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byTooltip('Back').hitTestable(), findsOneWidget);
|
||||||
|
final stateA = tester.state(_thread('a'));
|
||||||
|
await tester.enterText(_input('a'), 'Phone draft A');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final add = find.byTooltip('Add chat pane').hitTestable();
|
||||||
|
if (add.evaluate().isEmpty) {
|
||||||
|
await tester.tap(find.byTooltip('More actions').first);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Add chat pane'));
|
||||||
|
} else {
|
||||||
|
await tester.tap(add);
|
||||||
|
}
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Chat b'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(_thread('a'), findsOneWidget);
|
||||||
|
expect(_thread('b'), findsOneWidget);
|
||||||
|
expect(tester.state(_thread('a')), same(stateA));
|
||||||
|
expect(
|
||||||
|
tester.widget<EditableText>(_input('a')).controller.text,
|
||||||
|
'Phone draft A',
|
||||||
|
);
|
||||||
|
final workspace = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
|
||||||
|
expect(workspace.controller.paneCount, 2);
|
||||||
|
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||||
|
final first = workspace.controller.panes.first.id;
|
||||||
|
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(workspace.controller.activePane?.sessionId, 'a');
|
||||||
|
expect(
|
||||||
|
tester.widget<EditableText>(_input('b')).focusNode.hasFocus,
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(tester.state(_thread('a')), same(stateA));
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('compact and hidden sidebar preserve panes and drafts', (
|
testWidgets('compact and hidden sidebar preserve panes and drafts', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
@@ -147,12 +231,11 @@ void main() {
|
|||||||
tester.view.physicalSize = const Size(560, 1000);
|
tester.view.physicalSize = const Size(560, 1000);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(_thread('c'), findsOneWidget);
|
expect(_thread('c'), findsOneWidget);
|
||||||
expect(_thread('a'), findsNothing);
|
expect(find.byType(ChatThreadView), findsNWidgets(2));
|
||||||
expect(_thread('b'), findsNothing);
|
|
||||||
tester.view.physicalSize = const Size(390, 844);
|
tester.view.physicalSize = const Size(390, 844);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(_thread('c'), findsOneWidget);
|
expect(_thread('c'), findsOneWidget);
|
||||||
expect(_thread('a'), findsNothing);
|
expect(find.byType(ChatThreadView), findsNWidgets(2));
|
||||||
expect(tester.state(_thread('a', offstage: true)), same(stateA));
|
expect(tester.state(_thread('a', offstage: true)), same(stateA));
|
||||||
tester.view.physicalSize = const Size(1800, 1000);
|
tester.view.physicalSize = const Size(1800, 1000);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|||||||
Reference in New Issue
Block a user