mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
refactor(mobile): subscribe the pill only while it shows and trim the session dictation hook
This commit is contained in:
@@ -36,8 +36,13 @@ const TOAST_MS = 4000
|
||||
const TOAST_WITH_OPEN_MS = 6000
|
||||
|
||||
// The meter needs a live recording; finishing and failures show words instead.
|
||||
function PillStatus({ dictation }: { dictation: UseMobileDictationResult }) {
|
||||
const { elapsedSeconds } = useMobileDictationElapsed(dictation.meter)
|
||||
function PillStatus({
|
||||
dictation,
|
||||
elapsedSeconds
|
||||
}: {
|
||||
dictation: UseMobileDictationResult
|
||||
elapsedSeconds: number
|
||||
}) {
|
||||
if (dictation.failure) {
|
||||
return (
|
||||
<Text style={styles.sub} numberOfLines={1}>
|
||||
@@ -74,16 +79,16 @@ function PillStatus({ dictation }: { dictation: UseMobileDictationResult }) {
|
||||
|
||||
// The dictation whose target is off screen: tap to go back, ✕ and Stop work from here; a failure stays until Retry or ✕.
|
||||
function MobileDictationPill({
|
||||
dictation,
|
||||
title,
|
||||
onOpen,
|
||||
onStop
|
||||
}: {
|
||||
dictation: UseMobileDictationResult
|
||||
title: string
|
||||
onOpen: () => void
|
||||
onStop: () => void
|
||||
}) {
|
||||
// Subscribed only while the pill shows, so a hidden pill never re-renders on the dictation's ticks.
|
||||
const dictation = useMobileDictationHostLive(useMobileDictationHost())
|
||||
const { elapsedSeconds } = useMobileDictationElapsed(dictation.meter)
|
||||
const failed = dictation.failure !== null
|
||||
return (
|
||||
@@ -108,7 +113,7 @@ function MobileDictationPill({
|
||||
<Text style={styles.title} numberOfLines={1}>
|
||||
{failed ? dictationAwayCopy.stopped() : title}
|
||||
</Text>
|
||||
<PillStatus dictation={dictation} />
|
||||
<PillStatus dictation={dictation} elapsedSeconds={elapsedSeconds} />
|
||||
</View>
|
||||
</Pressable>
|
||||
<MobileDictationCancelButton onCancel={() => void dictation.cancel()} discards={failed} />
|
||||
@@ -193,9 +198,7 @@ export function MobileDictationPillLayer(): React.JSX.Element | null {
|
||||
useMobileColorScheme()
|
||||
useMobileTranslation()
|
||||
const insets = useSafeAreaInsets()
|
||||
const host = useMobileDictationHost()
|
||||
const dictation = useMobileDictationHostLive(host)
|
||||
const { stop } = host
|
||||
const { stop } = useMobileDictationHost()
|
||||
const pill = useContext(MobileDictationPillContext)
|
||||
if (!pill) {
|
||||
return null
|
||||
@@ -206,12 +209,7 @@ export function MobileDictationPillLayer(): React.JSX.Element | null {
|
||||
<>
|
||||
{pill.away ? (
|
||||
<View style={[styles.layer, { bottom: pillBottom }]} pointerEvents="box-none">
|
||||
<MobileDictationPill
|
||||
dictation={dictation}
|
||||
title={pill.title}
|
||||
onOpen={pill.open}
|
||||
onStop={stop}
|
||||
/>
|
||||
<MobileDictationPill title={pill.title} onOpen={pill.open} onStop={stop} />
|
||||
</View>
|
||||
) : null}
|
||||
<MobileDictationToast
|
||||
|
||||
@@ -20,11 +20,7 @@ import {
|
||||
type MobileDictationScreen
|
||||
} from './mobile-dictation-host-context'
|
||||
|
||||
export {
|
||||
useMobileDictationHost,
|
||||
type MobileDictationOwner,
|
||||
type MobileDictationScreen
|
||||
} from './mobile-dictation-host-context'
|
||||
export { useMobileDictationHost } from './mobile-dictation-host-context'
|
||||
|
||||
// The owner's screen; startingOnly asks only for the screen that started it.
|
||||
function screenFor(
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '../session/native-chat/composer/mobile-native-chat-draft-inputs'
|
||||
import { editMobileNativeChatDraft } from '../session/native-chat/composer/mobile-native-chat-draft-store'
|
||||
|
||||
export type MobileDictationTarget =
|
||||
type MobileDictationTarget =
|
||||
| { field: 'chat'; scope: string | null; anchor: MobileDictationAnchor | null }
|
||||
// Live terminal input: the words show on that terminal's status row.
|
||||
| { field: 'live'; handle: string }
|
||||
|
||||
@@ -54,6 +54,7 @@ export function useMobileSessionDictation(
|
||||
} = scope
|
||||
const { showNativeChat, showNativeChatRef } = nativeChatController
|
||||
const host = useMobileDictationHost()
|
||||
const { start: startHost } = host
|
||||
const executionHost = useWorkspaceExecutionHost()
|
||||
const sessionKey = JSON.stringify([hostId, executionHost ?? null, worktreeId])
|
||||
const [instance] = useState(() => ({}))
|
||||
@@ -193,7 +194,8 @@ export function useMobileSessionDictation(
|
||||
? connState === 'connected' || phoneDictation.ready
|
||||
: canSend
|
||||
|
||||
const dictationLeaveHold = useMobileDictationLeaveHold(dictation, () => router.canGoBack())
|
||||
const leaveKeepsPage = useCallback(() => router.canGoBack(), [router])
|
||||
const dictationLeaveHold = useMobileDictationLeaveHold(dictation, leaveKeepsPage)
|
||||
const previews = useMobileDictationPreviews(destination, dictation, activeHandle)
|
||||
|
||||
const startDictation = useCallback(() => {
|
||||
@@ -215,7 +217,7 @@ export function useMobileSessionDictation(
|
||||
const target = destination.captureDestination(showNativeChat, activeHandle)
|
||||
const paneKey = mobileSessionTabPaneKey(activeSessionTab)
|
||||
// A refused start comes back through this screen's reportFailure while it is shown, or the host's toast.
|
||||
void host.start({
|
||||
void startHost({
|
||||
instance,
|
||||
sessionKey,
|
||||
client,
|
||||
@@ -243,12 +245,11 @@ export function useMobileSessionDictation(
|
||||
dictationCanStart,
|
||||
dictationRouteContextRef,
|
||||
executionHost,
|
||||
host,
|
||||
hostId,
|
||||
startHost,
|
||||
instance,
|
||||
phoneDictation.readyRef,
|
||||
removeFillerWords,
|
||||
reportDictationFailure,
|
||||
scope.dictationMode,
|
||||
sessionKey,
|
||||
setShowDictationSetup,
|
||||
|
||||
Reference in New Issue
Block a user