()
| 435 | } |
| 436 | |
| 437 | export default function App() { |
| 438 | const [transport, setTransport] = useState<TransportKey>('xhr-http') |
| 439 | const [input, setInput] = useState('15-minute veggie dinner') |
| 440 | const connection = useConnection(transport) |
| 441 | const selectedTransport = |
| 442 | transports.find((item) => item.key === transport) ?? transports[1] |
| 443 | |
| 444 | const { |
| 445 | messages, |
| 446 | sendMessage, |
| 447 | isLoading, |
| 448 | error, |
| 449 | stop, |
| 450 | reload, |
| 451 | clear, |
| 452 | sessionGenerating, |
| 453 | } = useChat({ |
| 454 | id: `rn-recipe-book-${transport}`, |
| 455 | connection, |
| 456 | }) |
| 457 | |
| 458 | async function send(nextPrompt = input) { |
| 459 | const next = nextPrompt.trim() |
| 460 | if (!next || isLoading) return |
| 461 | setInput('') |
| 462 | await sendMessage(next) |
| 463 | } |
| 464 | |
| 465 | async function reloadLast() { |
| 466 | if (isLoading || messages.length === 0) return |
| 467 | await reload() |
| 468 | } |
| 469 | |
| 470 | function clearChat() { |
| 471 | clear() |
| 472 | } |
| 473 | |
| 474 | const latestRecipePart = findLatestRecipePart(messages) |
| 475 | const expectedFetchError = isExpectedFetchStreamingError(error) |
| 476 | const displayedError = expectedFetchError |
| 477 | ? expectedFetchErrorMessage |
| 478 | : error?.message |
| 479 | |
| 480 | return ( |
| 481 | <SafeAreaView style={styles.screen}> |
| 482 | <StatusBar barStyle="dark-content" /> |
| 483 | <View style={styles.backgroundSauce} /> |
| 484 | <View style={styles.backgroundSage} /> |
| 485 | |
| 486 | <ScrollView |
| 487 | style={styles.page} |
| 488 | contentContainerStyle={styles.pageContent} |
| 489 | keyboardShouldPersistTaps="handled" |
| 490 | > |
| 491 | <View style={styles.header}> |
| 492 | <Text style={styles.eyebrow}>TanStack AI recipes</Text> |
| 493 | <Text style={styles.title}>Weeknight Kitchen</Text> |
| 494 | <Text style={styles.subtitle}> |
nothing calls this directly
no test coverage detected