@@ -105,6 +105,13 @@ import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
105105import { resolveProviderOptionDescriptors } from "../../lib/providerOptions" ;
106106import { Menu } from "../../components/ui/Menu" ;
107107import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch" ;
108+ import {
109+ findComposerSendMenuAction ,
110+ resolveComposerSendMenu ,
111+ type ComposerSendMenuAction ,
112+ type ComposerSendMenuItem ,
113+ } from "@t3tools/client-runtime/state/send-menu" ;
114+ import { composerSendMenuActions } from "./composerSendMenu" ;
108115import type { FollowUpBehavior } from "../../lib/followUpBehavior" ;
109116import {
110117 resolveComposerSendPresentation ,
@@ -178,6 +185,15 @@ export interface ThreadComposerProps {
178185 readonly existingAttachments : ReadonlyArray < ChatAttachment > ;
179186 readonly saving : boolean ;
180187 readonly onRemoveExistingAttachment : ( attachmentId : string ) => void ;
188+ readonly onCancel : ( ) => void ;
189+ } | null ;
190+ /** Absent where the server has no drafts or this connection cannot save them. */
191+ readonly messageDrafts ?: {
192+ readonly drafts : ReadonlyArray < { readonly id : string ; readonly text : string } > ;
193+ readonly busy : boolean ;
194+ readonly onSaveDraft : ( ) => void ;
195+ readonly onMoveQueuedEditToDrafts : ( ) => void ;
196+ readonly onOpenDraft : ( draftId : string ) => void ;
181197 } | null ;
182198 readonly followUpBehavior : FollowUpBehavior ;
183199 readonly canSteerActiveTurn : boolean ;
@@ -249,47 +265,36 @@ const FOLLOW_UP_ACTION_LABEL = {
249265 restart : "Restart turn" ,
250266} as const ;
251267
252- const FOLLOW_UP_ACTION_SUBTITLE = {
253- queue : "Run after the current turn" ,
254- steer : "Interrupt what the agent is doing" ,
255- restart : "Start the turn over with this message" ,
256- } as const ;
257-
258268function SendActionButton ( props : {
259269 readonly accessibilityLabel : string ;
260270 readonly presentation : ComposerSendPresentation ;
261271 readonly disabled : boolean ;
262- readonly onSend : ( followUp ?: ActiveTurnComposerAction ) => void ;
272+ readonly menuItems : ReadonlyArray < ComposerSendMenuItem > ;
273+ readonly onSend : ( ) => void ;
274+ readonly onMenuAction : ( action : ComposerSendMenuAction ) => void ;
263275} ) {
264- const { presentation } = props ;
276+ const { presentation, menuItems } = props ;
265277 const button = (
266278 < ComposerActionButton
267279 accessibilityLabel = { props . accessibilityLabel }
268280 icon = { presentation . icon }
269281 variant = "primary"
270282 disabled = { props . disabled }
271- onPress = { ( ) => props . onSend ( ) }
283+ onPress = { props . onSend }
272284 />
273285 ) ;
274- if ( ! presentation . offersFollowUpChoice || presentation . action === null || props . disabled ) {
275- return button ;
276- }
277- const actions = [ presentation . action , presentation . alternate ] . filter (
278- ( action ) : action is ActiveTurnComposerAction => action !== null ,
279- ) ;
286+ if ( menuItems . length === 0 ) return button ;
287+ const menu = composerSendMenuActions ( menuItems , Platform . OS === "ios" ? "ios" : "android" ) ;
280288 return (
281289 < Menu
282290 accessibilityLabel = "Choose how to send this message"
283291 shouldOpenOnLongPress
284- actions = { actions . map ( ( action ) => ( {
285- id : action ,
286- title : FOLLOW_UP_ACTION_LABEL [ action ] ,
287- subtitle : FOLLOW_UP_ACTION_SUBTITLE [ action ] ,
288- state : action === presentation . action ? ( "on" as const ) : ( "off" as const ) ,
289- } ) ) }
290- onPressAction = { ( { nativeEvent } ) =>
291- props . onSend ( nativeEvent . event as ActiveTurnComposerAction )
292- }
292+ { ...( menu . title ? { title : menu . title } : { } ) }
293+ actions = { menu . actions }
294+ onPressAction = { ( { nativeEvent } ) => {
295+ const action = findComposerSendMenuAction ( menuItems , nativeEvent . event ) ;
296+ if ( action ) props . onMenuAction ( action ) ;
297+ } }
293298 >
294299 { button }
295300 </ Menu >
@@ -621,6 +626,49 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
621626 }
622627 onEditorFocusChange ?.( false ) ;
623628 } ;
629+ const messageDrafts = props . messageDrafts ?? null ;
630+ const sendMenuItems =
631+ hasContent && ( ! canSend || messageDrafts ?. busy === true )
632+ ? [ ]
633+ : resolveComposerSendMenu ( {
634+ hasContent,
635+ running : props . activeThreadBusy ,
636+ canSteer : props . canSteerActiveTurn ,
637+ activeTurnDefault : props . followUpBehavior ,
638+ // Mobile has no way to start a sibling thread from the thread composer.
639+ canSendInNewThread : false ,
640+ canSaveDraft : messageDrafts !== null && ! messageDrafts . busy ,
641+ isEditingQueuedMessage : queuedEdit !== null ,
642+ drafts : messageDrafts ?. busy === false ? messageDrafts . drafts : [ ] ,
643+ } ) ;
644+ const handleSendMenuAction = ( action : ComposerSendMenuAction ) => {
645+ switch ( action . type ) {
646+ case "send" :
647+ case "update-queued" :
648+ void handleSend ( ) ;
649+ return ;
650+ case "queue" :
651+ void handleSend ( props . activeThreadBusy && props . canSteerActiveTurn ? "queue" : undefined ) ;
652+ return ;
653+ case "steer" :
654+ void handleSend ( "steer" ) ;
655+ return ;
656+ case "save-draft" :
657+ messageDrafts ?. onSaveDraft ( ) ;
658+ return ;
659+ case "move-to-drafts" :
660+ messageDrafts ?. onMoveQueuedEditToDrafts ( ) ;
661+ return ;
662+ case "cancel-edit" :
663+ queuedEdit ?. onCancel ( ) ;
664+ return ;
665+ case "open-draft" :
666+ messageDrafts ?. onOpenDraft ( action . draftId ) ;
667+ return ;
668+ case "send-in-new-thread" :
669+ return ;
670+ }
671+ } ;
624672 const handleSend = async ( followUp ?: ActiveTurnComposerAction ) => {
625673 if ( voiceInput . blocksSubmission || pendingPastedTextAttachmentCountRef . current > 0 ) return ;
626674 if ( usageLimitsOffered && isUsageLimitsCommand ( draftMessage ) && draftAttachments . length === 0 ) {
@@ -1070,7 +1118,9 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10701118 accessibilityLabel = { sendBlockedReason ?? sendLabel }
10711119 presentation = { sendPresentation }
10721120 disabled = { ! canSend }
1073- onSend = { handleSend }
1121+ menuItems = { sendMenuItems }
1122+ onSend = { ( ) => void handleSend ( ) }
1123+ onMenuAction = { handleSendMenuAction }
10741124 />
10751125 ) }
10761126 </ View >
@@ -1179,7 +1229,9 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
11791229 accessibilityLabel = { sendBlockedReason ?? sendLabel }
11801230 presentation = { sendPresentation }
11811231 disabled = { ! canSend }
1182- onSend = { handleSend }
1232+ menuItems = { sendMenuItems }
1233+ onSend = { ( ) => void handleSend ( ) }
1234+ onMenuAction = { handleSendMenuAction }
11831235 />
11841236 ) : null }
11851237 </ View >
0 commit comments