Files
pipelines/app/lib/features/chat/conversation/chat_add_pane_picker.dart
T
alan 5fc3c9d3bd Show the mode picker and the add-pane picker as menus on desktop
Phase 2b.2 of docs/plans/floating-windows.md, implemented by pipeline run
303: both use showAppChoiceMenu (a menu anchored to its button on a wide
app, a bottom sheet on a phone).
2026-11-10 23:02:20 +00:00

169 lines
5.2 KiB
Dart

import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/app_popups.dart';
import '../domain/chat_cycle.dart';
import '../ui/sessions/chat_adaptive.dart';
import '../ui/sessions/chat_sessions_body.dart';
import '../ui/sessions/chat_sessions_controller.dart';
/// Pick from exactly the sidebar's visible rows, using its native list rows.
/// Local search only narrows this set; it cannot reveal a hidden/folded chat.
Future<void> showAddChatPanePicker(
BuildContext context, {
required ChatSessionsController controller,
required ChatSectionFolds sidebarFolds,
required Set<String> excludedSessionIds,
required ValueChanged<JsonMap> onSelected,
}) async {
final selected = await showAppChoiceMenu<JsonMap>(
context,
width: 420,
builder: (popupContext) => ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.sizeOf(popupContext).height * 0.85,
),
child: LayoutBuilder(
builder: (context, constraints) => SizedBox(
height: constraints.maxHeight,
child: _AddChatPanePicker(
controller: controller,
sidebarFolds: sidebarFolds,
excludedSessionIds: excludedSessionIds,
),
),
),
),
);
if (selected == null || !context.mounted) return;
final id = '${selected['id'] ?? ''}';
final current =
chatSessionsShown(
controller.sessions,
query: '',
isOpen: sidebarFolds.isOpen,
)
.where(
(row) =>
'${row['id'] ?? ''}' == id && !excludedSessionIds.contains(id),
)
.firstOrNull;
if (current != null) onSelected(current);
}
class _AddChatPanePicker extends StatefulWidget {
const _AddChatPanePicker({
required this.controller,
required this.sidebarFolds,
required this.excludedSessionIds,
});
final ChatSessionsController controller;
final ChatSectionFolds sidebarFolds;
final Set<String> excludedSessionIds;
@override
State<_AddChatPanePicker> createState() => _AddChatPanePickerState();
}
class _AddChatPanePickerState extends State<_AddChatPanePicker> {
final _search = TextEditingController();
final _pickerFolds = ChatSectionFolds()..set('Closed', true);
@override
void dispose() {
_search.dispose();
_pickerFolds.dispose();
super.dispose();
}
void _ignore(JsonMap _) {}
void _clear() {
_search.clear();
setState(() {});
}
@override
Widget build(BuildContext context) {
final list = Column(
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(24, 16, 24, 0),
child: Text(
'Add chat pane',
style: Theme.of(context).textTheme.titleLarge,
),
),
ChatSearchField(
controller: _search,
autofocus: true,
onChanged: (_) => setState(() {}),
),
Expanded(
child: ListenableBuilder(
listenable: Listenable.merge([
widget.controller,
widget.sidebarFolds,
]),
builder: (context, _) {
final controller = widget.controller;
final available =
chatSessionsShown(
controller.sessions,
query: '',
isOpen: widget.sidebarFolds.isOpen,
)
.where(
(row) => !widget.excludedSessionIds.contains(
'${row['id'] ?? ''}',
),
)
.toList();
return Column(
children: [
if (controller.error != null)
ChatErrorNotice(
message: controller.error!,
onRetry: controller.refresh,
),
Expanded(
child: ChatSessionsBody(
sessions: available,
query: _search.text,
loading: controller.loading,
error: controller.error,
emptyMessageOverride:
available.isEmpty && controller.error == null
? 'No other visible chats to add.'
: null,
folds: _pickerFolds,
selectionOnly: true,
onOpen: (row) => Navigator.pop(context, row),
onRename: _ignore,
onClose: _ignore,
onReopen: _ignore,
onStar: _ignore,
onHide: _ignore,
onClearSearch: _clear,
isUnseen: controller.isUnseen,
errorFor: (_) => null,
),
),
],
);
},
),
),
],
);
return Material(
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.viewInsetsOf(context).bottom,
),
child: SafeArea(top: false, child: list),
),
);
}
}