The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { Button } from "../../components/ui/Button"; |
| 2 | import type { ChatAttachment, EnvironmentId } from "@t3tools/contracts"; |
| 3 | import { Image } from "expo-image"; |
| 4 | import { T, useGT } from "gt-react-native"; |
| 5 | import { Pressable, ScrollView, View } from "react-native"; |
| 6 | |
| 7 | import { AppText as Text } from "../../components/ui/AppText"; |
| 8 | import { SymbolView } from "../../components/ui/AppSymbol"; |
| 9 | import { useAssetUrl } from "../../state/assets"; |
| 10 | import { assetImageSource } from "../../lib/assetImageSource"; |
| 11 | |
| 12 | export function ComposerQueuedEditBanner(props: { |
| 13 | readonly saving: boolean; |
| 14 | readonly onCancel: () => void; |
| 15 | }) { |
| 16 | const gt = useGT(); |
| 17 | return ( |
| 18 | <View className="flex-row items-center gap-2 px-4 pb-2"> |
| 19 | <SymbolView name="pencil" size={12} tintColorClassName="accent-foreground-muted" /> |
| 20 | <Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}> |
| 21 | <T>Editing queued message</T> |
| 22 | </Text> |
| 23 | <Button |
| 24 | label={gt("Cancel")} |
| 25 | tone="text" |
| 26 | accessibilityLabel={gt("Cancel editing queued message")} |
| 27 | disabled={props.saving} |
| 28 | onPress={props.onCancel} |
| 29 | /> |
| 30 | </View> |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | export function ComposerQueuedEditAttachments(props: { |
| 35 | readonly environmentId: EnvironmentId; |
| 36 | readonly attachments: ReadonlyArray<ChatAttachment>; |
| 37 | readonly disabled: boolean; |
| 38 | readonly onRemove: (attachmentId: string) => void; |
| 39 | }) { |
| 40 | if (props.attachments.length === 0) return null; |
| 41 | return ( |
| 42 | <ScrollView |
| 43 | horizontal |
| 44 | showsHorizontalScrollIndicator={false} |
| 45 | keyboardShouldPersistTaps="always" |
| 46 | className="grow-0" |
| 47 | contentContainerClassName="flex-row items-center gap-2" |
| 48 | > |
| 49 | {props.attachments.map((attachment) => ( |
| 50 | <QueuedEditAttachmentChip |
| 51 | key={attachment.id} |
| 52 | environmentId={props.environmentId} |
| 53 | attachment={attachment} |
| 54 | disabled={props.disabled} |
| 55 | onRemove={props.onRemove} |
| 56 | /> |
| 57 | ))} |
| 58 | </ScrollView> |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | function QueuedEditAttachmentChip(props: { |
| 63 | readonly environmentId: EnvironmentId; |
| 64 | readonly attachment: ChatAttachment; |
| 65 | readonly disabled: boolean; |
| 66 | readonly onRemove: (attachmentId: string) => void; |
| 67 | }) { |
| 68 | const gt = useGT(); |
| 69 | const { attachment } = props; |
| 70 | const isImage = attachment.mimeType.startsWith("image/"); |
| 71 | const resource = { |
| 72 | _tag: "attachment", |
| 73 | attachmentId: attachment.id, |
| 74 | fileName: attachment.name, |
| 75 | mimeType: attachment.mimeType, |
| 76 | disposition: "inline", |
| 77 | } as const; |
| 78 | const url = useAssetUrl(props.environmentId, isImage ? resource : null); |
| 79 | |
| 80 | return ( |
| 81 | <View className="max-w-[180px] flex-row items-center gap-2 rounded-xl border border-border bg-card py-1 pl-1 pr-2"> |
| 82 | {isImage && url !== null ? ( |
| 83 | <Image |
| 84 | source={assetImageSource(props.environmentId, resource, url)} |
| 85 | cachePolicy="memory-disk" |
| 86 | contentFit="cover" |
| 87 | style={{ width: 24, height: 24, borderRadius: 6 }} |
| 88 | accessibilityIgnoresInvertColors |
| 89 | /> |
| 90 | ) : ( |
| 91 | <View className="h-6 w-6 items-center justify-center rounded-md bg-subtle"> |
| 92 | <SymbolView |
| 93 | name={isImage ? "photo" : "doc"} |
| 94 | size={12} |
| 95 | tintColorClassName="accent-icon-subtle" |
| 96 | /> |
| 97 | </View> |
| 98 | )} |
| 99 | <Text className="min-w-0 shrink text-xs text-foreground" numberOfLines={1}> |
| 100 | {attachment.name} |
| 101 | </Text> |
| 102 | <Pressable |
| 103 | accessibilityRole="button" |
| 104 | accessibilityLabel={gt("Remove {name}", { name: attachment.name })} |
| 105 | disabled={props.disabled} |
| 106 | hitSlop={8} |
| 107 | onPress={() => props.onRemove(attachment.id)} |
| 108 | className="active:opacity-70 disabled:opacity-40" |
| 109 | > |
| 110 | <SymbolView name="xmark.circle.fill" size={14} tintColorClassName="accent-icon-subtle" /> |
| 111 | </Pressable> |
| 112 | </View> |
| 113 | ); |
| 114 | } |