Files
orca/mobile/app/voice-settings.tsx
Neil dc9a7abfc1 refactor(mobile): group host catalog credentials and descriptors (#40739)
* refactor(mobile): group host catalog credentials descriptors and connection history

* refactor(mobile): import RPC sender and result types from defining owners

* refactor(mobile): colocate push delivery with registration operations

* refactor(mobile): point push recordings at delivery owner
2026-11-10 02:52:14 -08:00

48 lines
1.9 KiB
TypeScript

import { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'expo-router'
import { loadHosts, peekHosts } from '../src/host-catalog/host-store'
import type { HostProfile } from '../src/host-catalog/host-profile'
import { useFocusedSettingsHostClients } from '../src/settings/settings-host-client-connections'
import VoiceSettingsScreen from '../src/settings/voice-settings-screen'
import { nativeVoiceSettingsOperations } from '../src/settings/native-voice-settings-operations'
export default function NativeVoiceSettingsRoute() {
const router = useRouter()
// Null until the first read, so a paired phone never flashes "connect a desktop".
const [hosts, setHosts] = useState<HostProfile[] | null>(() => peekHosts())
useEffect(() => {
void loadHosts().then(setHosts)
}, [])
const hostIds = useMemo(() => (hosts ?? []).map((host) => host.id), [hosts])
const { clients, focused } = useFocusedSettingsHostClients(hostIds)
const connected = clients.find((entry) => entry.state === 'connected')
const client = connected?.client ?? null
const connecting =
!connected &&
(hosts === null ||
(hosts.length > 0 &&
(clients.length === 0 ||
clients.some(
(entry) => entry.state !== 'disconnected' && entry.state !== 'auth-failed'
))))
// Keep the last desktop through reconnects; a different desktop remounts the screen.
const [screenHostId, setScreenHostId] = useState(connected?.hostId)
if (connected && connected.hostId !== screenHostId) {
setScreenHostId(connected.hostId)
}
const operations = useMemo(
() => (client ? nativeVoiceSettingsOperations(client) : null),
[client]
)
return (
// Remount per desktop so a late reply from the previous one cannot land on this screen.
<VoiceSettingsScreen
key={screenHostId}
operations={operations}
connecting={connecting}
focused={focused}
onBack={() => router.back()}
/>
)
}