Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerQueuedEdit.tsx

111 lines3.6 KB

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