Restore local chat layouts and add compact or hidden chat sidebar
This commit is contained in:
@@ -13,7 +13,96 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
BuildContext? paneContext,
|
||||
});
|
||||
|
||||
ChatSidebarMode _sidebarMode = ChatSidebarMode.expanded;
|
||||
void _setSidebarMode(ChatSidebarMode mode) {
|
||||
setState(() => _sidebarMode = mode);
|
||||
_workspaceBinding?.changed();
|
||||
}
|
||||
|
||||
Widget _sidebarList(Widget full, String? selected, bool beside) {
|
||||
final mode = selected == null || !beside
|
||||
? ChatSidebarMode.expanded
|
||||
: _sidebarMode;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Offstage(
|
||||
offstage: mode != ChatSidebarMode.expanded,
|
||||
child: ExcludeFocus(
|
||||
excluding: mode != ChatSidebarMode.expanded,
|
||||
child: full,
|
||||
),
|
||||
),
|
||||
if (mode == ChatSidebarMode.compact)
|
||||
ChatCompactSidebar(
|
||||
controller: _sessionsForSidebar,
|
||||
folds: _foldsForSidebar,
|
||||
activeSessionId: selected,
|
||||
onOpen: _openSidebarSession,
|
||||
onExpand: () => _setSidebarMode(ChatSidebarMode.expanded),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
ChatSessionsController get _sessionsForSidebar;
|
||||
ChatSectionFolds get _foldsForSidebar;
|
||||
void _openSidebarSession(JsonMap session);
|
||||
|
||||
final ChatWorkspaceController _workspace = ChatWorkspaceController();
|
||||
ChatWorkspaceBinding? _workspaceBinding;
|
||||
String? _workspaceScope;
|
||||
|
||||
void _bindWorkspacePersistence() {
|
||||
if (!widget.persistWorkspace) return;
|
||||
final scope = serverStorageScope(serverIdentity(widget.gateway));
|
||||
_workspaceScope = scope;
|
||||
_workspaceBinding = ChatWorkspaceBinding(
|
||||
controller: _workspace,
|
||||
store: SharedPreferencesChatWorkspaceStore(serverScope: scope),
|
||||
sidebarMode: () => _sidebarMode.name,
|
||||
onRestored: (snapshot) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_sidebarMode = ChatSidebarMode.values.firstWhere(
|
||||
(mode) => mode.name == snapshot.sidebarMode,
|
||||
);
|
||||
_usedWorkspace = true;
|
||||
_workspaceVisible = _workspace.paneCount > 0;
|
||||
});
|
||||
_publishWorkspaceRoute();
|
||||
},
|
||||
);
|
||||
unawaited(
|
||||
_workspaceBinding!.start(initialSessionId: widget.initialSessionId),
|
||||
);
|
||||
}
|
||||
|
||||
bool _updateWorkspacePersistence(ChatScreen oldWidget) {
|
||||
final scope = serverStorageScope(serverIdentity(widget.gateway));
|
||||
if (oldWidget.persistWorkspace == widget.persistWorkspace &&
|
||||
(!widget.persistWorkspace || scope == _workspaceScope)) {
|
||||
return false;
|
||||
}
|
||||
_workspaceBinding?.dispose();
|
||||
_workspaceBinding = null;
|
||||
if (_workspaceScope != null && scope != _workspaceScope) {
|
||||
_workspace.restoreLayout(ChatWorkspaceSnapshot.fromLayout(null, null)!);
|
||||
_workspaceVisible = false;
|
||||
_usedWorkspace = true;
|
||||
_sidebarMode = ChatSidebarMode.expanded;
|
||||
_publishedWorkspaceSession = null;
|
||||
final initial = widget.initialSessionId;
|
||||
if (initial != null && initial.isNotEmpty) {
|
||||
_workspace.open(initial);
|
||||
_workspaceVisible = true;
|
||||
}
|
||||
}
|
||||
_workspaceScope = null;
|
||||
_bindWorkspacePersistence();
|
||||
return true;
|
||||
}
|
||||
|
||||
final GlobalKey _workspaceKey = GlobalKey();
|
||||
bool _workspaceVisible = false;
|
||||
bool _usedWorkspace = false;
|
||||
@@ -66,7 +155,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
}
|
||||
|
||||
void _workspaceChanged() {
|
||||
if (!mounted) return;
|
||||
if (!mounted || _workspaceBinding?.isRestoring == true) return;
|
||||
final signature =
|
||||
'${_workspace.activePaneId}:${_workspace.panes.map((p) => '${p.id}=${p.sessionId}').join(',')}';
|
||||
if (_workspaceSignature == signature) return;
|
||||
|
||||
Reference in New Issue
Block a user