Repository navigation
feat(mobile): select, cite, and comment on assistant text #29386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jakeleventhal
wants to merge
6
commits into
pingdotgg:main
from
jakeleventhal:t3/mobile-text-selection-citing
+352
−27
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4dc0742
feat(mobile): select, cite, and comment on assistant text
jakeleventhal 56a25fd
docs(mobile): name Go to message for opening a quote's source
jakeleventhal 72a0bfa
fix(mobile): keep voice drafts locked when citing text
jakeleventhal f29b84f
merge: sync mobile citations with main
maria-rcks 0af5909
fix(mobile): hide cite while voice input blocks drafts
maria-rcks 23abe41
merge: sync mobile citations with main
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { ASSISTANT_CITATION_MAX_COMMENT_LENGTH, type AssistantCitation } from "@t3tools/contracts"; | ||
| import { scopedThreadKey } from "@t3tools/client-runtime/environment"; | ||
| import { useState } from "react"; | ||
| import { Platform, ScrollView, TextInput, View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
| import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread"; | ||
| import { requestThreadMessageJump } from "../features/threads/threadMessageJump"; | ||
| import { copyTextWithHaptic } from "../lib/copyTextWithHaptic"; | ||
| import { AppText as Text } from "./ui/AppText"; | ||
| import { ListActionRow } from "./ui/ListActionRow"; | ||
| import { ListSection } from "./ui/ListSection"; | ||
| import { Sheet } from "./ui/Sheet"; | ||
|
|
||
| const CONTEXT_CHARS = 80; | ||
|
|
||
| function contextBefore(prefix: string) { | ||
| const flat = prefix.replace(/\s+/g, " "); | ||
| if (flat.length <= CONTEXT_CHARS) return flat.trimStart(); | ||
| const cut = flat.slice(-CONTEXT_CHARS); | ||
| return `…${cut.slice(cut.indexOf(" ") + 1)}`; | ||
| } | ||
|
|
||
| function contextAfter(suffix: string) { | ||
| const flat = suffix.replace(/\s+/g, " "); | ||
| if (flat.length <= CONTEXT_CHARS) return flat.trimEnd(); | ||
| const cut = flat.slice(0, CONTEXT_CHARS); | ||
| return `${cut.slice(0, cut.lastIndexOf(" "))}…`; | ||
| } | ||
|
|
||
| export function AssistantCitationSheet(props: { | ||
| readonly citation: AssistantCitation; | ||
| readonly onClose: () => void; | ||
| readonly onRemove?: () => void; | ||
| readonly onCommentChange?: (comment: string) => void; | ||
| }) { | ||
| const openLinkedThread = useOpenLinkedThread(); | ||
| const insets = useSafeAreaInsets(); | ||
| const citation = props.citation; | ||
| const [comment, setComment] = useState(citation.comment ?? ""); | ||
| const close = () => { | ||
| if (props.onCommentChange && comment.trim() !== (citation.comment ?? "")) { | ||
| props.onCommentChange(comment); | ||
| } | ||
| props.onClose(); | ||
| }; | ||
| return ( | ||
| <Sheet title="Quote" onClose={close}> | ||
| <ScrollView | ||
| contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"} | ||
| contentContainerStyle={{ | ||
| paddingHorizontal: 20, | ||
| paddingTop: 12, | ||
| gap: 24, | ||
| paddingBottom: Math.max(20, insets.bottom), | ||
| }} | ||
| > | ||
| <View className="flex-row gap-3 rounded-2xl bg-grouped-card p-4"> | ||
| <View className="w-1 rounded-full bg-primary" /> | ||
| <Text selectable textRole="body" className="min-w-0 flex-1 text-foreground-muted"> | ||
| {contextBefore(citation.prefix)} | ||
| <Text className="font-t3-medium text-foreground">{citation.text}</Text> | ||
| {contextAfter(citation.suffix)} | ||
| </Text> | ||
| </View> | ||
| {props.onCommentChange ? ( | ||
| <ListSection title="Comment"> | ||
| <TextInput | ||
| accessibilityLabel="Comment on quote" | ||
| placeholder="Add an optional comment…" | ||
| placeholderTextColorClassName="accent-foreground-muted" | ||
| multiline | ||
| maxLength={ASSISTANT_CITATION_MAX_COMMENT_LENGTH} | ||
| value={comment} | ||
| onChangeText={setComment} | ||
| className="min-h-24 px-4 py-3 text-base text-foreground" | ||
| style={{ textAlignVertical: "top" }} | ||
| /> | ||
| </ListSection> | ||
| ) : citation.comment ? ( | ||
| <ListSection title="Comment"> | ||
| <Text selectable textRole="body" className="px-4 py-3 text-foreground"> | ||
| {citation.comment} | ||
| </Text> | ||
| </ListSection> | ||
| ) : null} | ||
| <ListSection> | ||
| <ListActionRow | ||
| icon="arrow.up.right" | ||
| label="Go to message" | ||
| onPress={() => { | ||
| close(); | ||
| requestThreadMessageJump(scopedThreadKey(citation), citation.messageId); | ||
| openLinkedThread(citation); | ||
| }} | ||
| /> | ||
| <ListActionRow | ||
| icon="doc.on.doc" | ||
| label="Copy quote" | ||
| onPress={() => copyTextWithHaptic(citation.text)} | ||
| /> | ||
| {props.onRemove ? ( | ||
| <ListActionRow | ||
| icon="trash" | ||
| label="Remove from draft" | ||
| tone="danger" | ||
| onPress={props.onRemove} | ||
| /> | ||
| ) : null} | ||
| </ListSection> | ||
| </ScrollView> | ||
| </Sheet> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.