From f05be1943e488e282572154cc0cf600e7461be56 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 1 Nov 2026 14:41:20 -0500 Subject: [PATCH 1/9] feat(mobile): answer the Inbox's asks in place Each open ask gets an answer box (#830, part 3 of 4), as on web: the words are delivered as typed, a retry with the same words reuses its request id, an item that closes while the person has typed into it stays with their words and who answered (AC16, AC17), unsent words are dropped when a server's person changes, and answering is off for a read-only connection or a server that is not read. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/j5/inbox/InboxScreen.tsx | 140 ++++++++++++++------ apps/mobile/src/j5/inbox/inboxAnswers.ts | 161 +++++++++++++++++++++++ apps/mobile/src/j5/inbox/inboxSources.ts | 2 + 3 files changed, 264 insertions(+), 39 deletions(-) create mode 100644 apps/mobile/src/j5/inbox/inboxAnswers.ts diff --git a/apps/mobile/src/j5/inbox/InboxScreen.tsx b/apps/mobile/src/j5/inbox/InboxScreen.tsx index 07f8dddd06152..4868c9bf12692 100644 --- a/apps/mobile/src/j5/inbox/InboxScreen.tsx +++ b/apps/mobile/src/j5/inbox/InboxScreen.tsx @@ -1,6 +1,7 @@ import { useAtomValue } from "@effect/atom-react"; import { answeredByLine, + closedLine, j5SourceNotice, mergeHumanInboxSources, type PresentedHumanInboxItem, @@ -12,9 +13,11 @@ import { scopedInboxItemKey } from "@t3tools/contracts/j5"; import { useFocusEffect } from "@react-navigation/native"; import { useCallback, useState } from "react"; import { Pressable, RefreshControl, View } from "react-native"; +import { KeyboardAvoidingView } from "react-native-keyboard-controller"; import { SymbolView } from "../../components/ui/AppSymbol"; -import { AppText as Text } from "../../components/ui/AppText"; +import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; import { EmptyState } from "../../components/ui/EmptyState"; import { ScreenScrollView } from "../../components/ui/ScreenScrollView"; import { useMarkdownPreviewStyles } from "../../features/files/FileMarkdownPreview"; @@ -23,6 +26,8 @@ import { relativeTime } from "../../lib/time"; import { NativeStackScreenOptions } from "../../native/StackHeader"; import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; import { j5Sharing } from "../sharing/guestAccess"; +import { j5Environment } from "../state"; +import { type ClosedItem, useInboxAnswers } from "./inboxAnswers"; import { answeredInboxQueryAtom, answeredInboxSourcesAtom, @@ -61,7 +66,7 @@ function refreshAll() { /** * The person's Inbox: what agents on every connected server have asked them, most urgent first - * (Inbox AC6), and the asks already answered. Read-only here; answering comes with the answer box. + * (Inbox AC6), answered in place, and the asks already answered. */ export function InboxScreen() { const openSources = useAtomValue(openInboxSourcesAtom); @@ -76,6 +81,7 @@ export function InboxScreen() { connected: item.connected, })), ); + const answers = useInboxAnswers({ openSources, items, answeredSources, answered }); // Reads again each time the Inbox comes into view; between visits the server's inbox signal // rereads it. No timer. useFocusEffect(useCallback(() => refreshAll(), [])); @@ -93,42 +99,59 @@ export function InboxScreen() { ), ]; return ( - } - > - - {notices.map((notice) => ( - - {notice} - - ))} - {items.length === 0 ? ( - loading ? ( - Loading your inbox… - ) : ( - - ) - ) : ( - - {items.map((item) => ( - + } + > + + {notices.map((notice) => ( + + {notice} + + ))} + {answers.error === null ? null : ( + + {answers.error} + + )} + {answers.shownItems.length === 0 ? ( + loading ? ( + Loading your inbox… + ) : ( + - ))} - - )} - - + ) + ) : ( + + {answers.shownItems.map((item) => { + const key = scopedInboxItemKey(item); + return ( + answers.setAnswerText(item, text)} + onAnswer={() => void answers.answer(item)} + delivering={answers.pendingKey === key} + anyDelivering={answers.pendingKey !== null} + /> + ); + })} + + )} + + + ); } @@ -159,10 +182,23 @@ function InboxItem(props: { readonly item: PresentedHumanInboxItem; readonly labels: SenderLabels; readonly showEnvironment: boolean; + /** The item closed while the person had typed into it, and stays with their words (AC17). */ + readonly closed: ClosedItem | undefined; + readonly answerText: string; + readonly onChangeAnswer: (text: string) => void; + readonly onAnswer: () => void; + readonly delivering: boolean; + readonly anyDelivering: boolean; }) { const { item } = props; const [expanded, setExpanded] = useState(false); const urgency = URGENCY[item.urgency]; + const ownName = useOwnName(item.environmentId); + const mayAnswer = useAtomValue( + j5Environment.answerHumanExchange.permissionAtom(item.environmentId), + ); + const canAnswer = item.sourceReady && mayAnswer; + const closedText = props.closed === undefined ? null : closedLine({ ...props.closed, ownName }); return ( {expanded ? ( - + + + + {closedText !== null ? ( + {closedText} + ) : ( +