Restore local chat layouts and add compact or hidden chat sidebar

This commit is contained in:
2026-11-06 19:16:18 +00:00
parent 8a7b704940
commit 9a0d5de26a
9 changed files with 834 additions and 16 deletions
+55 -15
View File
@@ -11,8 +11,14 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_scope.dart';
import 'workspace/chat_workspace_binding.dart';
import 'workspace/chat_workspace_snapshot.dart';
import 'workspace/chat_workspace_store.dart';
import 'conversation/chat_models.dart';
import 'conversation/chat_pane_picker.dart';
import 'conversation/chat_sidebar_controls.dart';
import 'ui/sessions/chat_compact_sidebar.dart';
import 'workspace/chat_workspace.dart';
import 'ui/sessions/chat_adaptive.dart';
import 'conversation/chat_row_widgets.dart';
@@ -46,9 +52,11 @@ class ChatScreen extends StatefulWidget {
this.syncToken = 0,
this.onSessionSelected,
this.onBack,
this.persistWorkspace = false,
});
final ApiGateway gateway;
final bool persistWorkspace;
/// The chat session the current route names, or null for the list.
final String? initialSessionId;
@@ -117,6 +125,13 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
/// when that changes.
bool _offeredNext = false;
@override
ChatSessionsController get _sessionsForSidebar => _sessions;
@override
ChatSectionFolds get _foldsForSidebar => _folds;
@override
void _openSidebarSession(JsonMap session) => _openBySelection(session);
@override
void initState() {
super.initState();
@@ -127,6 +142,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
_publishedWorkspaceSession = initial;
}
_workspace.addListener(_workspaceChanged);
_bindWorkspacePersistence();
HardwareKeyboard.instance.addHandler(_cycleChatKey);
// Seen from now on, so the press that chooses the first chat counts.
LastPointerKind.instance;
@@ -351,7 +367,10 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
@override
void didUpdateWidget(covariant ChatScreen oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.initialSessionId != widget.initialSessionId) {
final reboundWorkspace = _updateWorkspacePersistence(oldWidget);
if (!reboundWorkspace &&
oldWidget.initialSessionId != widget.initialSessionId) {
_workspaceBinding?.changed();
final id = widget.initialSessionId;
if (id != null && id.isNotEmpty) {
_workspaceVisible = true;
@@ -369,6 +388,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
void dispose() {
HardwareKeyboard.instance.removeHandler(_cycleChatKey);
_page.dispose();
_workspaceBinding?.dispose();
_workspace.removeListener(_workspaceChanged);
_workspace.dispose();
_sessions.dispose();
@@ -409,6 +429,9 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
? () => _openNext(selected)
: null,
showBackButton: pane == null ? null : !showsListBesideDetail(context),
sidebarControl: pane == null || !showsListBesideDetail(context)
? null
: ChatSidebarButton(mode: _sidebarMode, onChanged: _setSidebarMode),
paneControls: pane == null
? const []
: [
@@ -460,7 +483,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
);
// 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 list = ChatSessionsScreen(
final fullList = ChatSessionsScreen(
gateway: widget.gateway,
embedded: true,
syncToken: widget.syncToken,
@@ -472,8 +495,13 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
onShortcutOpen: _openByShortcut,
onSessions: _adoptRows,
activeSessionId: selected,
publishShellBar: beside || !_usedWorkspace || selected == null,
publishShellBar:
(selected == null ||
!beside ||
_sidebarMode == ChatSidebarMode.expanded) &&
(beside || !_usedWorkspace || selected == null),
);
final list = _sidebarList(fullList, selected, beside);
if (!beside) {
if (!_usedWorkspace) return list;
final media = MediaQuery.of(context);
@@ -510,18 +538,30 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
),
);
}
return ListDetailPanes(
list: list,
detailIdentity: selected,
detail: selected == null
? const EmptyDetailPane(
destination: AppDestination.chat,
message: 'Select a chat to open it here.',
)
: SizedBox.expand(
key: const ValueKey('chat-detail-pane'),
child: _workspaceView(),
),
return ShellBar(
active: selected != null && _sidebarMode != ChatSidebarMode.expanded,
barless: true,
hideNavigation: true,
child: ListDetailPanes(
list: list,
listWidthOverride: selected == null
? null
: switch (_sidebarMode) {
ChatSidebarMode.expanded => null,
ChatSidebarMode.compact => ChatCompactSidebar.width,
ChatSidebarMode.hidden => 0,
},
detailIdentity: selected,
detail: selected == null
? const EmptyDetailPane(
destination: AppDestination.chat,
message: 'Select a chat to open it here.',
)
: SizedBox.expand(
key: const ValueKey('chat-detail-pane'),
child: _workspaceView(),
),
),
);
}
}