Open active chat when Chat is reselected
Route destination re-selections through the adaptive shell so Chat can restore its retained workspace and focus the composer. Add shell and phone coverage plus implementation notes for the empty-list behavior and verification limits.
This commit is contained in:
@@ -697,20 +697,29 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
|
||||
void _selectDestination(AppDestination destination) {
|
||||
final current = tabForRoute(_delegate.route);
|
||||
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));
|
||||
_delegate.goTo(last ?? _routeOf(destination));
|
||||
}
|
||||
|
||||
/// A tap on the destination already shown. Chat reopens its retained
|
||||
/// workspace when the list is showing; other tabs select as before.
|
||||
void _reselectDestination(AppDestination destination) {
|
||||
if (destination != AppDestination.chat) {
|
||||
_selectDestination(destination);
|
||||
return;
|
||||
}
|
||||
_delegate.goTo(last ?? _routeOf(destination));
|
||||
final onList = _delegate.shellRoute.chatSessionId == null;
|
||||
final reopened = chatRouteForRetap(
|
||||
_delegate.shellRoute,
|
||||
_chatWorkspaceRoute,
|
||||
isValidSession: (id) =>
|
||||
_availableChatSessionIds == null ||
|
||||
_availableChatSessionIds!.contains(id),
|
||||
);
|
||||
_delegate.goTo(reopened ?? _routeOf(destination));
|
||||
// From the list, the reopened chat's composer takes focus, as Ctrl+K does.
|
||||
// A chat already showing keeps its focus behaviour.
|
||||
if (onList && reopened != null) _focusOpenChatComposer();
|
||||
}
|
||||
|
||||
void _routeChanged() {
|
||||
@@ -832,6 +841,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
runningRunCount: counts.running,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: _selectDestination,
|
||||
onDestinationReselected: _reselectDestination,
|
||||
onOpenChat: _focusOpenChatComposer,
|
||||
onClosePage: () => _delegate.goTo(
|
||||
_bodyRoutes[AppDestination.pipelines] ?? AppRoute.pipelines,
|
||||
|
||||
@@ -21,6 +21,7 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.destinationBodies = const {},
|
||||
this.destination,
|
||||
this.onDestinationSelected,
|
||||
this.onDestinationReselected,
|
||||
this.onClosePage,
|
||||
this.onSearch,
|
||||
this.onOpenChat,
|
||||
@@ -43,6 +44,11 @@ class AdaptiveShell extends StatefulWidget {
|
||||
/// selection, which preserves the plain-shell tests and native composition.
|
||||
final AppDestination? destination;
|
||||
final ValueChanged<AppDestination>? onDestinationSelected;
|
||||
|
||||
/// Runs when a destination's control is tapped while that destination is
|
||||
/// already shown (a re-select). The host decides what it means; Chat reopens
|
||||
/// its active chats. Null keeps re-selects as plain selections.
|
||||
final ValueChanged<AppDestination>? onDestinationReselected;
|
||||
final VoidCallback? onClosePage;
|
||||
|
||||
/// Opens the transient Search page. Null hides the action, so the plain
|
||||
@@ -105,6 +111,18 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The entry every tab control calls when tapped: a destination shown
|
||||
/// already is re-selected (see [AdaptiveShell.onDestinationReselected]), any
|
||||
/// other is selected.
|
||||
void _tapDestination(AppDestination destination) {
|
||||
final reselected = widget.onDestinationReselected;
|
||||
if (destination == _selected && reselected != null) {
|
||||
reselected(destination);
|
||||
return;
|
||||
}
|
||||
_select(destination);
|
||||
}
|
||||
|
||||
void _select(AppDestination destination) {
|
||||
final callback = widget.onDestinationSelected;
|
||||
if (callback != null) {
|
||||
@@ -201,7 +219,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
child: FloatingDestinationBar(
|
||||
showLabels: true,
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(shellTabDestinations[value]),
|
||||
onTap: (value) => _tapDestination(shellTabDestinations[value]),
|
||||
items: _destinationItems(),
|
||||
alignment: split ? AlignmentDirectional.bottomStart : null,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user