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/ui/AppText";
6import { SymbolView } from "../../components/ui/AppSymbol";
7import { useAssetUrl } from "../../state/assets";
8import { assetImageSource } from "../../lib/assetImageSource";
9
10export function ComposerQueuedEditBanner(props: {
11 readonly saving: boolean;
12 readonly onCancel: () => void;
13}) {
14 return (
15 <View className="flex-row items-center gap-2 px-4 pb-2">
16 <SymbolView name="pencil" size={12} tintColorClassName="accent-foreground-muted" />
17 <Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}>
18 Editing queued message
19 </Text>
20 <Pressable
21 accessibilityRole="button"
22 accessibilityLabel="Cancel editing queued message"
23 disabled={props.saving}
24 onPress={props.onCancel}
25 hitSlop={8}
26 className="min-h-8 justify-center px-1 active:opacity-70 disabled:opacity-40"
27 >
28 <Text className="font-t3-medium text-xs text-primary">Cancel</Text>
29 </Pressable>
30 </View>
31 );
32}
33
34export 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
62function QueuedEditAttachmentChip(props: {
63 readonly environmentId: EnvironmentId;
64 readonly attachment: ChatAttachment;
65 readonly disabled: boolean;
66 readonly onRemove: (attachmentId: string) => void;
67}) {
68 const { attachment } = props;
69 const isImage = attachment.mimeType.startsWith("image/");
70 const resource = {
71 _tag: "attachment",
72 attachmentId: attachment.id,
73 fileName: attachment.name,
74 mimeType: attachment.mimeType,
75 disposition: "inline",
76 } as const;
77 const url = useAssetUrl(props.environmentId, isImage ? resource : null);
78
79 return (
80 <View className="max-w-[180px] flex-row items-center gap-2 rounded-xl border border-border bg-card py-1 pl-1 pr-2">
81 {isImage && url !== null ? (
82 <Image
83 source={assetImageSource(props.environmentId, resource, url)}
84 cachePolicy="memory-disk"
85 contentFit="cover"
86 style={{ width: 24, height: 24, borderRadius: 6 }}
87 accessibilityIgnoresInvertColors
88 />
89 ) : (
90 <View className="h-6 w-6 items-center justify-center rounded-md bg-subtle">
91 <SymbolView
92 name={isImage ? "photo" : "doc"}
93 size={12}
94 tintColorClassName="accent-icon-subtle"
95 />
96 </View>
97 )}
98 <Text className="min-w-0 shrink text-xs text-foreground" numberOfLines={1}>
99 {attachment.name}
100 </Text>
101 <Pressable
102 accessibilityRole="button"
103 accessibilityLabel={`Remove ${attachment.name}`}
104 disabled={props.disabled}
105 hitSlop={8}
106 onPress={() => props.onRemove(attachment.id)}
107 className="active:opacity-70 disabled:opacity-40"
108 >
109 <SymbolView name="xmark.circle.fill" size={14} tintColorClassName="accent-icon-subtle" />
110 </Pressable>
111 </View>
112 );
113}