Restore mobile Chats workspace on tab retap
This commit is contained in:
@@ -176,6 +176,27 @@ class AppRoute {
|
||||
String toString() => path;
|
||||
}
|
||||
|
||||
/// Chooses what an already-selected Chats tab should show when it is tapped
|
||||
/// again. A detail route is left alone; only the list can use the retained
|
||||
/// workspace route, and an absent/invalid retained route stays at the list.
|
||||
AppRoute? chatRouteForRetap(
|
||||
AppRoute current,
|
||||
AppRoute? retainedWorkspace, {
|
||||
bool Function(String sessionId)? isValidSession,
|
||||
}) {
|
||||
if (current.kind != AppRouteKind.chat || current.chatSessionId != null) {
|
||||
return current.kind == AppRouteKind.chat ? current : null;
|
||||
}
|
||||
final retained = retainedWorkspace;
|
||||
return retained != null &&
|
||||
retained.kind == AppRouteKind.chat &&
|
||||
retained.chatSessionId != null &&
|
||||
retained.chatSessionId!.isNotEmpty &&
|
||||
(isValidSession == null || isValidSession(retained.chatSessionId!))
|
||||
? retained
|
||||
: null;
|
||||
}
|
||||
|
||||
/// `AppRoute.run(3)` reads better than a constructor named after a field.
|
||||
class _RunRouteFactory {
|
||||
const _RunRouteFactory();
|
||||
|
||||
@@ -21,6 +21,8 @@ class ChatDestination extends StatelessWidget {
|
||||
this.initialSessionId,
|
||||
this.onSessionSelected,
|
||||
this.onBack,
|
||||
this.onWorkspaceEmpty,
|
||||
this.onAvailableSessionsChanged,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -28,6 +30,8 @@ class ChatDestination extends StatelessWidget {
|
||||
final String? initialSessionId;
|
||||
final ValueChanged<String>? onSessionSelected;
|
||||
final VoidCallback? onBack;
|
||||
final VoidCallback? onWorkspaceEmpty;
|
||||
final ValueChanged<Set<String>>? onAvailableSessionsChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
@@ -70,5 +74,7 @@ class ChatDestination extends StatelessWidget {
|
||||
syncToken: session.connectionEpoch,
|
||||
onSessionSelected: onSessionSelected,
|
||||
onBack: onBack,
|
||||
onWorkspaceEmpty: onWorkspaceEmpty,
|
||||
onAvailableSessionsChanged: onAvailableSessionsChanged,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -414,10 +414,23 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
/// The last route each tab showed, so switching tabs returns to where the
|
||||
/// operator left it; tapping the open tab again goes to its root.
|
||||
final Map<AppDestination, AppRoute> _tabRoutes = {};
|
||||
AppRoute? _chatWorkspaceRoute;
|
||||
Set<String>? _availableChatSessionIds;
|
||||
|
||||
void _selectDestination(AppDestination destination) {
|
||||
final current = _destinationOf(_delegate.shellRoute.kind);
|
||||
final last = _tabRoutes[destination];
|
||||
if (destination == AppDestination.chat && current == destination) {
|
||||
final reopened = chatRouteForRetap(
|
||||
_delegate.shellRoute,
|
||||
_chatWorkspaceRoute,
|
||||
isValidSession: (id) =>
|
||||
_availableChatSessionIds == null ||
|
||||
_availableChatSessionIds!.contains(id),
|
||||
);
|
||||
_delegate.goTo(reopened ?? _routeOf(destination));
|
||||
return;
|
||||
}
|
||||
_delegate.goTo(
|
||||
destination == current || last == null ? _routeOf(destination) : last,
|
||||
);
|
||||
@@ -426,6 +439,9 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
void _routeChanged() {
|
||||
final shown = _delegate.shellRoute;
|
||||
_tabRoutes[_destinationOf(shown.kind)] = shown;
|
||||
if (shown.kind == AppRouteKind.chat && shown.chatSessionId != null) {
|
||||
_chatWorkspaceRoute = shown;
|
||||
}
|
||||
final pending = _pendingRunSearch;
|
||||
if (!mounted || pending == null) return;
|
||||
final route = _delegate.shellRoute;
|
||||
@@ -562,6 +578,14 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
initialSessionId: chatRoute.chatSessionId,
|
||||
onSessionSelected: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
onBack: () => _delegate.goTo(AppRoute.chat),
|
||||
onWorkspaceEmpty: () => _chatWorkspaceRoute = null,
|
||||
onAvailableSessionsChanged: (ids) {
|
||||
_availableChatSessionIds = ids;
|
||||
final retained = _chatWorkspaceRoute?.chatSessionId;
|
||||
if (retained != null && !ids.contains(retained)) {
|
||||
_chatWorkspaceRoute = null;
|
||||
}
|
||||
},
|
||||
),
|
||||
// Search is the fourth tab; a result opens its destination.
|
||||
AppDestination.search: (_) => SearchDestination(
|
||||
|
||||
Reference in New Issue
Block a user