diff --git a/apps/mobile/src/j5/inbox/InboxScreen.tsx b/apps/mobile/src/j5/inbox/InboxScreen.tsx index 07f8dddd06152..9b3b7613db063 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, @@ -11,10 +12,12 @@ import type { EnvironmentId } from "@t3tools/contracts"; 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 { Platform, Pressable, RefreshControl, View } from "react-native"; +import { KeyboardAwareScrollView } 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(), [])); @@ -92,20 +98,15 @@ export function InboxScreen() { }), ), ]; - return ( - } - > + const content = ( + <> {notices.map((notice) => ( {notice} ))} - {items.length === 0 ? ( + {answers.shownItems.length === 0 ? ( loading ? ( Loading your inbox… ) : ( @@ -117,18 +118,56 @@ export function InboxScreen() { ) ) : ( - {items.map((item) => ( - - ))} + {answers.shownItems.map((item) => { + const key = scopedInboxItemKey(item); + return ( + answers.setAnswerText(item, text)} + onAnswer={() => void answers.answer(item)} + delivering={answers.pendingKey === key} + error={answers.errorFor(item)} + anyDelivering={answers.pendingKey !== null} + /> + ); + })} )} + + ); + const refreshControl = ; + // iOS keeps upstream's scroll view, which registers with the native header, and lets it move the + // focused answer box above the keyboard, as upstream's commit sheet does. Android has no header + // marker, so keyboard-controller's scroll view brings the box being typed in clear of the keyboard. + return Platform.OS === "ios" ? ( + + {content} + ) : ( + + {content} + ); } @@ -159,10 +198,25 @@ 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; + /** Why this ask's last answer was not delivered, or a stale list after it was. */ + readonly error: string | null; }) { 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 ? ( - + {/* Above the answer box, so it stays in view whenever the box is: iOS scrolls only the + focused box itself clear of the keyboard. */} + + + {closedText !== null ? ( + {closedText} + ) : ( +