Files
pipelines/app/lib/features/chat/conversation/chat_send_later_menu.dart
T
alan b1fcdcf2c3 Chat: unnamed chats take the harness title, harness default per folder, word-safe tables, Send later
- New chat: a cleared Name creates the chat without an operator title; the
  list shows the harness's own title, or the default name until it has one.
  The server no longer records "New chat" for a blank title and OpenCode
  is created without a title so it names the session itself.
- New chat harness defaults to the one last used in the chosen folder,
  else anywhere, else OpenCode; remembered on the device per server.
- Markdown tables wrap at word boundaries and never go below a column's
  longest word (tokens over ~40 characters may break); a table whose words
  cannot fit scrolls sideways with the code block affordance.
- Composer: right-click, long-press, Shift+F10 or the context menu key on
  Send opens Send later... (30 min, 1 h, tomorrow 9:00, usage reset, pick a
  time), sent through the same path with send_at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:55:40 +00:00

146 lines
4.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart';
import '../domain/chat_send_later.dart';
import 'chat_schedule_time.dart';
const String chatSendLaterLabel = 'Send later…';
const String chatSendLaterPickLabel = 'Pick a time…';
/// The send button's secondary action: right-click, long-press, the context
/// menu key or Shift+F10 on it (or the screen reader's custom action) opens
/// "Send later…" with quick times and a time picker. A chosen time is handed
/// to [onSchedule]; the message takes the ordinary send path with `send_at`.
///
/// On touch the long-press opens this menu instead of the button's tooltip,
/// so the tooltip's account and usage line ([info]) heads the menu.
class ChatSendLaterMenu extends StatefulWidget {
const ChatSendLaterMenu({
super.key,
required this.enabled,
required this.onSchedule,
required this.builder,
this.info,
this.usageReset,
this.now = DateTime.now,
});
/// Whether the draft is a message that can be scheduled.
final bool enabled;
final String? info;
final DateTime? Function(DateTime now)? usageReset;
final void Function(DateTime at) onSchedule;
/// Builds the send button, given the callback that opens the menu.
final Widget Function(BuildContext context, VoidCallback open) builder;
final DateTime Function() now;
@override
State<ChatSendLaterMenu> createState() => _ChatSendLaterMenuState();
}
class _ChatSendLaterMenuState extends State<ChatSendLaterMenu> {
final _menu = MenuController();
void _open([Offset? position]) {
if (_menu.isOpen) _menu.close();
setState(() {});
_menu.open(position: position);
}
Future<void> _pickTime() async {
final now = widget.now();
final initial = TimeOfDay.fromDateTime(now.add(const Duration(hours: 1)));
final picked = await showTimePicker(
context: context,
initialTime: TimeOfDay(hour: initial.hour, minute: 0),
helpText: 'Send at',
);
if (!mounted || picked == null || !widget.enabled) return;
widget.onSchedule(
chatSendLaterAt(widget.now(), picked.hour, picked.minute),
);
}
String _label(BuildContext context, ChatSendLaterChoice choice) {
final time = chatScheduleTime(context, choice.at, now: widget.now);
return switch (choice.kind) {
ChatSendLaterKind.halfHour => 'In 30 minutes · $time',
ChatSendLaterKind.hour => 'In 1 hour · $time',
ChatSendLaterKind.tomorrowMorning => 'Tomorrow at 9:00',
ChatSendLaterKind.usageReset => 'At usage reset · $time',
};
}
@override
Widget build(BuildContext context) {
final now = widget.now();
final choices = chatSendLaterChoices(
now,
usageReset: widget.usageReset?.call(now),
);
final theme = Theme.of(context);
final info = widget.info;
return MenuAnchor(
controller: _menu,
menuChildren: [
if (info != null && info.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Text(
info,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
),
Padding(
key: const Key('chat-send-later-title'),
padding: const EdgeInsets.fromLTRB(12, 8, 12, 4),
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 12,
children: [
Icon(
Icons.schedule_send,
color: theme.colorScheme.onSurfaceVariant,
),
Text(chatSendLaterLabel, style: theme.textTheme.titleSmall),
],
),
),
for (final choice in choices)
MenuItemButton(
key: Key('chat-send-later-${choice.kind.name}'),
onPressed: widget.enabled
? () => widget.onSchedule(choice.at)
: null,
child: Text(_label(context, choice)),
),
MenuItemButton(
key: const Key('chat-send-later-pick'),
leadingIcon: const Icon(Icons.access_time),
onPressed: widget.enabled ? _pickTime : null,
child: const Text(chatSendLaterPickLabel),
),
],
child: CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.contextMenu): _open,
const SingleActivator(LogicalKeyboardKey.f10, shift: true): _open,
},
child: GestureDetector(
onSecondaryTapUp: (details) => _open(details.localPosition),
child: Semantics(
customSemanticsActions: {
const CustomSemanticsAction(label: chatSendLaterLabel): _open,
},
child: widget.builder(context, _open),
),
),
),
);
}
}