Restore mobile Chats workspace on tab retap
This commit is contained in:
@@ -59,6 +59,8 @@ class ChatScreen extends StatefulWidget {
|
||||
this.syncToken = 0,
|
||||
this.onSessionSelected,
|
||||
this.onBack,
|
||||
this.onWorkspaceEmpty,
|
||||
this.onAvailableSessionsChanged,
|
||||
this.persistWorkspace = false,
|
||||
});
|
||||
|
||||
@@ -74,6 +76,8 @@ class ChatScreen extends StatefulWidget {
|
||||
|
||||
final ValueChanged<String>? onSessionSelected;
|
||||
final VoidCallback? onBack;
|
||||
final VoidCallback? onWorkspaceEmpty;
|
||||
final ValueChanged<Set<String>>? onAvailableSessionsChanged;
|
||||
|
||||
@override
|
||||
State<ChatScreen> createState() => _ChatScreenState();
|
||||
@@ -157,6 +161,8 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
// Seen from now on, so the press that chooses the first chat counts.
|
||||
LastPointerKind.instance;
|
||||
_sessions.addListener(_nextChanged);
|
||||
_sessions.addListener(_availableSessionsChanged);
|
||||
_availableSessionsChanged();
|
||||
_folds.addListener(_nextChanged);
|
||||
}
|
||||
|
||||
@@ -174,6 +180,15 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
if (next != null) _openBySelection(next);
|
||||
}
|
||||
|
||||
void _availableSessionsChanged() {
|
||||
if (!mounted || _sessions.loading) return;
|
||||
widget.onAvailableSessionsChanged?.call({
|
||||
for (final row in _sessions.sessions)
|
||||
if (row['closed_at'] == null && row['closed'] != true)
|
||||
'${row['id'] ?? ''}',
|
||||
});
|
||||
}
|
||||
|
||||
void _nextChanged() {
|
||||
if (!mounted) return;
|
||||
final id = _selected;
|
||||
@@ -307,6 +322,11 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
/// the list's own build.
|
||||
void _adoptRows(List<JsonMap> rows) {
|
||||
if (!mounted) return;
|
||||
widget.onAvailableSessionsChanged?.call({
|
||||
for (final row in rows)
|
||||
if (row['closed_at'] == null && row['closed'] != true)
|
||||
'${row['id'] ?? ''}',
|
||||
});
|
||||
final selected = _selected;
|
||||
final retained = _workspace.panes.map((pane) => pane.sessionId).toSet();
|
||||
final next = <String, JsonMap>{};
|
||||
@@ -367,6 +387,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_publishedWorkspaceSession = null;
|
||||
_startNotice = null;
|
||||
_composerFocus.cancel();
|
||||
if (_workspace.paneCount == 0) widget.onWorkspaceEmpty?.call();
|
||||
final back = widget.onBack;
|
||||
if (back != null) {
|
||||
back();
|
||||
@@ -408,6 +429,8 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_workspaceBinding?.dispose();
|
||||
_workspace.removeListener(_workspaceChanged);
|
||||
_workspace.dispose();
|
||||
_sessions.removeListener(_nextChanged);
|
||||
_sessions.removeListener(_availableSessionsChanged);
|
||||
_sessions.dispose();
|
||||
_folds.dispose();
|
||||
_composerFocus.dispose();
|
||||
|
||||
Reference in New Issue
Block a user