Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

982 B
Raw Blame
import { useMemo, useRef, type RefObject } from 'react'
import type { TextInput } from 'react-native'
import type { MobileQueuedMessageEdit } from '../../use-mobile-structured-queued-message-controls'

// Focus after a queued Edit actually copies text; empty copies preserve current focus.
export function useMobileNativeChatQueuedEditFocus(onEdit: MobileQueuedMessageEdit | undefined): {
  composerInputRef: RefObject<TextInput | null>
  editQueuedMessage: MobileQueuedMessageEdit | undefined
} {
  const composerInputRef = useRef<TextInput>(null)
  const editQueuedMessage = useMemo<MobileQueuedMessageEdit | undefined>(
    () =>
      onEdit
        ? (messageId) =>
            onEdit(messageId, () =>
              // Next frame, so the copied text has landed in the field before it takes focus.
              requestAnimationFrame(() => composerInputRef.current?.focus())
            )
        : undefined,
    [onEdit]
  )
  return { composerInputRef, editQueuedMessage }
}