Files
archived-orca/mobile/src/session/MobileQueuedMessageCardRow.tsx
T
Brennan Benson c6f07596ad Phone chat: empty Cmd/Ctrl+Enter steers the first queued message, and holding Cmd/Ctrl shows what it will do (#39215)
* fix(mobile): Cmd/Ctrl+Enter on an empty chat composer steers the first queued message

Matches desktop (#38732) in the paired web page: with nothing typed, the
chord steers the head waiting card through that card's own Steer, only
where its other way is steer.

* fix(mobile): empty Cmd/Ctrl+Enter sends the first queued card after a Stop, as desktop does

Desktop's rule (#38877) also sends the head card when no turn runs, and
goal mode keeps the empty chord inert. The queue list's handle now runs the
head card's own Send when idle, and steers mid-turn only where the chord's
other way is steer.

* test(mobile): type the queued-card handle refusal cases

* feat(mobile): holding Cmd/Ctrl in the phone chat composer shows what Cmd/Ctrl+Enter will do, as desktop does

Desktop's held-modifier preview moves into src/shared so the phone web
composer runs the same rule: Send becomes Queue, Steer or Steer queued
and the head queued card lights while the chord's modifier is held
alone on a hardware keyboard. The queue's empty-chord rule is one
function the preview and the press both read.

* fix(mobile): build the held-chord preview with the phone's own React, and offer only presses that act

The shared hook now takes its React hooks from the caller, as the shared
attachment preview does: the phone bundle resolves a different React copy
than the repo root, so importing react from src/shared broke every phone
web composer (Invalid hook call).

The preview also matches what a press does: one pill press per hold (a
double-click can't send a card after the draft went), a picked /plan-style
skill counts as a message, a head card whose own action is on its way shows
no Steer queued, and the lit state lives in the tray so a chat switch keeps it.

* fix(mobile): held-chord pill takes one click like desktop, keeps busy state per chat, lights only the head row

- The pill ignores a click whose detail is above 1, as desktop does, so a
  deliberate later click in the same hold still acts.
- In-flight card ids are kept per chat with functional updates, so a chat
  settling after a switch can't clear the current chat's record.
- The lit state is a small store only the head row subscribes to, so a hold
  re-renders one row, not the whole queue.
- The desktop preview test moves back beside the desktop wrapper it drives.

* refactor(mobile): one owner for queued-card actions, read by both the list and the held-chord cue

The queue list owned its in-flight guard per mount and the tray mirrored it
for the composer's Steer queued cue; each mirror leaked (cross-chat and
same-chat remount overwrites, an all-chats copy per change). As desktop's
queued-messages controller does, the tray now owns one action store: pending
keys per chat, admitted synchronously, released per action, published by
copying only the changed chat. The list takes those actions as a prop (it
keeps its own only when mounted alone), and the empty chord presses the head
through the same run, so the cue and the press can't disagree. The list's
imperative handle goes away.

Also replaces a type assertion on the pill's click detail with an in guard.

* test(native-chat): desktop chord-preview wrapper re-exports the hold delay its test reads
2026-11-06 18:17:24 -08:00

219 lines
7.8 KiB
TypeScript

import type { ReactNode } from 'react'
import { useState, useSyncExternalStore } from 'react'
import { Pressable, Text, View, type LayoutRectangle } from 'react-native'
import {
AlertCircle,
CornerDownRight,
ListEnd,
Image as ImageIcon,
MoreHorizontal,
Send,
Trash2
} from 'lucide-react-native'
import { colors, pressedStyle } from '../theme/mobile-theme'
import { queuedMessageCardSteers } from '../../../src/shared/agent-session/view/structured-agent-session-queued-cards'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
import type { MobileQueuedMessageCard } from './mobile-structured-queued-message-cards'
import type { MobileQueuedMessageInlineEditor } from './use-mobile-structured-queued-edit'
import { MobileQueuedMessageComposer } from './MobileQueuedMessageComposer'
import { MobileQueuedCardText } from './MobileQueuedCardText'
import type { MobileQueuedHeadLight } from './native-chat/input/mobile-queued-head-light'
const subscribeNever = () => () => undefined
import { MobileAgentMessageSenders } from './native-chat/transcript/MobileAgentMessageSenders'
import { queuedMessageStyles as styles } from './native-chat/input/mobile-native-chat-queued-message-styles'
import { useMobileTranslation } from '../i18n/use-mobile-translation'
type QueuedMessageCardRowProps = {
dragHandle?: ReactNode
card: MobileQueuedMessageCard
editor?: MobileQueuedMessageInlineEditor
busy: boolean
/** Set on the card the composer's Steer queued preview would send. */
headLight?: MobileQueuedHeadLight
editBlocked: boolean
steerHeld: boolean
/** Steer only into a running turn; an idle agent's card reads Send. */
agentWorking: boolean
onSend: () => void
onDelete: () => void
onMore: () => void
onEditorLayout: (row: LayoutRectangle) => void
}
export function MobileQueuedMessageCardRow({
card,
editor,
onEditorLayout,
...actions
}: QueuedMessageCardRowProps): React.JSX.Element {
useMobileColorScheme()
if (editor) {
return (
<View
testID="queued-card-row"
style={styles.divided}
onLayout={(event) => onEditorLayout(event.nativeEvent.layout)}
>
<MobileQueuedMessageComposer editor={editor} from={card.from} />
</View>
)
}
return <QueuedMessageCardContents card={card} {...actions} />
}
function QueuedMessageCardContents({
card,
busy,
headLight,
editBlocked,
steerHeld,
agentWorking,
onSend,
onDelete,
onMore,
dragHandle
}: Omit<QueuedMessageCardRowProps, 'editor' | 'onEditorLayout'>): React.JSX.Element {
useMobileColorScheme()
const t = useMobileTranslation()
const [expanded, setExpanded] = useState(false)
const returned = card.state === 'returned'
const steers = agentWorking && queuedMessageCardSteers(card)
const count = card.images?.length ?? 0
const lit = useSyncExternalStore(
headLight?.subscribe ?? subscribeNever,
() => headLight?.get() === true
)
return (
<View testID="queued-card-row" style={[styles.card, styles.divided, lit && styles.pressed]}>
<View style={styles.row}>
{dragHandle}
{card.needsAttention ? (
<AlertCircle size={14} color={colors.statusRed} strokeWidth={2} />
) : (
<ListEnd size={14} color={colors.textMuted} strokeWidth={2} />
)}
<View style={styles.textColumn}>
{card.from ? <MobileAgentMessageSenders queued from={card.from} /> : null}
<MobileQueuedCardText
text={card.line}
expanded={expanded}
onToggle={() => setExpanded(!expanded)}
/>
{card.caption && !returned ? (
<Text style={styles.caption} numberOfLines={1}>
{card.caption}
</Text>
) : null}
</View>
<View style={styles.actions}>
{card.images ? (
<View
style={styles.actions}
accessible
accessibilityLabel={
count === 1
? t('session.queuedMessageCardRow.images_one', '{{count}} image', { count })
: t('session.queuedMessageCardRow.images_other', '{{count}} images', { count })
}
>
<ImageIcon size={12} color={colors.textMuted} strokeWidth={2} />
<Text style={styles.caption}>{card.images.length}</Text>
</View>
) : null}
{card.waitsForAgent ? null : (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: busy || steerHeld }}
accessibilityLabel={
returned
? t('session.queuedMessageCardRow.sendAgainHint', 'Send this message again')
: steers
? t(
'session.queuedMessageCardRow.steerHint',
'Submit without interrupting the model'
)
: t('session.queuedMessageCardRow.sendHint', 'Send this message')
}
style={({ pressed }) => [
styles.textAction,
pressed && styles.pressed,
(busy || steerHeld) && styles.disabled
]}
disabled={busy || steerHeld}
onPress={onSend}
>
{steers ? (
<CornerDownRight size={12} color={colors.textPrimary} strokeWidth={2} />
) : (
<Send size={12} color={colors.textPrimary} strokeWidth={2} />
)}
<Text style={styles.actionLabel}>
{steers
? t('session.queuedMessageCardRow.steer', 'Steer')
: t('session.queuedMessageCardRow.send', 'Send')}
</Text>
</Pressable>
)}
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: busy }}
accessibilityLabel={t(
'session.queuedMessageCardRow.deleteHint',
'Delete this queued message'
)}
style={({ pressed }) => [
styles.iconAction,
card.command && styles.lastIconAction,
pressed && styles.pressed,
busy && styles.disabled
]}
disabled={busy}
onPress={onDelete}
>
<Trash2 size={14} color={colors.textPrimary} strokeWidth={2} />
</Pressable>
{card.command ? null : (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: editBlocked }}
accessibilityLabel={t('session.queuedMessageCardRow.moreActions', 'More actions')}
style={({ pressed }) => [
styles.iconAction,
styles.lastIconAction,
pressed && styles.pressed,
editBlocked && styles.disabled
]}
disabled={editBlocked}
onPress={onMore}
>
<MoreHorizontal size={14} color={colors.textPrimary} strokeWidth={2} />
</Pressable>
)}
</View>
</View>
{expanded || (returned && card.caption) ? (
<View style={styles.expandedBody}>
{expanded ? (
<Pressable
style={({ pressed }) => pressed && pressedStyle}
accessibilityRole="button"
accessibilityState={{ expanded: true }}
accessibilityHint={t(
'session.queuedMessageCardRow.showLessHint',
'Shows less of the message'
)}
onPress={() => setExpanded(false)}
>
<Text style={styles.bodyText}>{card.line}</Text>
</Pressable>
) : null}
{returned && card.caption ? (
<Text style={[styles.caption, styles.captionReturned]}>{card.caption}</Text>
) : null}
</View>
) : null}
</View>
)
}