Open History to see the last commit
1import type { ChatAttachment, EnvironmentId } from "@t3tools/contracts";
2import { Image } from "expo-image";
3import { Pressable, ScrollView, View } from "react-native";
4
5import { AppText as Text } from "../../components/AppText";
6import { SymbolView } from "../../components/AppSymbol";
7import { useAssetUrl } from "../../state/assets";
8
9/**
10 * The composer is shared, so editing a queued message needs a visible way back
11 * out. This is that way out, and the only place the edit announces itself.
12 */
13export function ComposerQueuedEditBanner(props: {
14 readonly saving: boolean;
15 readonly onCancel: () => void;
16}) {
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 Editing queued message
22 </Text>
23 <Pressable
24 accessibilityRole="button"
25 accessibilityLabel="Cancel editing queued message"
26 disabled={props.saving}
27 onPress={props.onCancel}
28 hitSlop={8}
29 className="min-h-8 justify-center px-1 active:opacity-70 disabled:opacity-40"
30 >
31 <Text className="font-t3-medium text-xs text-primary">Cancel</Text>
32 </Pressable>
33 </View>
34 );
35}
36
37/**
38 * Attachments already on the queued message. They live on the server rather
39 * than in the draft, so they get their own row: removing one here drops it
40 * from the replacement list the edit sends.
41 */
42export function ComposerQueuedEditAttachments(props: {
43 readonly environmentId: EnvironmentId;
44 readonly attachments: ReadonlyArray<ChatAttachment>;
45 readonly disabled: boolean;
46 readonly onRemove: (attachmentId: string) => void;
47}) {
48 if (props.attachments.length === 0) return null;
49 return (
50 <ScrollView
51 horizontal
52 showsHorizontalScrollIndicator={false}
53 keyboardShouldPersistTaps="always"
54 className="grow-0"
55 contentContainerClassName="flex-row items-center gap-2"
56 >
57 {props.attachments.map((attachment) => (
58 <QueuedEditAttachmentChip
59 key={attachment.id}
60 environmentId={props.environmentId}
61 attachment={attachment}
62 disabled={props.disabled}
63 onRemove={props.onRemove}
64 />
65 ))}
66 </ScrollView>
67 );
68}
69
70function QueuedEditAttachmentChip(props: {
71 readonly environmentId: EnvironmentId;
72 readonly attachment: ChatAttachment;
73 readonly disabled: boolean;
74 readonly onRemove: (attachmentId: string) => void;
75}) {
76 const { attachment } = props;
77 const isImage = attachment.mimeType.startsWith("image/");
78 const url = useAssetUrl(
79 props.environmentId,
80 isImage
81 ? {
82 _tag: "attachment",
83 attachmentId: attachment.id,
84 fileName: attachment.name,
85 mimeType: attachment.mimeType,
86 disposition: "inline",
87 }
88 : null,
89 );
90
91 return (
92 <View className="max-w-[180px] flex-row items-center gap-2 rounded-xl border border-border bg-card py-1 pl-1 pr-2">
93 {isImage && url !== null ? (
94 <Image
95 source={{ uri: url }}
96 contentFit="cover"
97 style={{ width: 24, height: 24, borderRadius: 6 }}
98 accessibilityIgnoresInvertColors
99 />
100 ) : (
101 <View className="h-6 w-6 items-center justify-center rounded-md bg-subtle">
102 <SymbolView
103 name={isImage ? "photo" : "doc"}
104 size={12}
105 tintColorClassName="accent-icon-subtle"
106 />
107 </View>
108 )}
109 <Text className="min-w-0 shrink text-xs text-foreground" numberOfLines={1}>
110 {attachment.name}
111 </Text>
112 <Pressable
113 accessibilityRole="button"
114 accessibilityLabel={`Remove ${attachment.name}`}
115 disabled={props.disabled}
116 hitSlop={8}
117 onPress={() => props.onRemove(attachment.id)}
118 className="active:opacity-70 disabled:opacity-40"
119 >
120 <SymbolView name="xmark.circle.fill" size={14} tintColorClassName="accent-icon-subtle" />
121 </Pressable>
122 </View>
123 );
124}