-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathComposer.tsx
45 lines (41 loc) · 1.1 KB
/
Composer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Button, Flex, TextInput } from "@mantine/core";
import type { Conversation } from "@xmtp/browser-sdk";
import { useState } from "react";
import { useConversation } from "@/hooks/useConversation";
export type ComposerProps = {
conversation: Conversation;
};
export const Composer: React.FC<ComposerProps> = ({ conversation }) => {
const { send, sending } = useConversation(conversation);
const [message, setMessage] = useState("");
const handleSend = async () => {
await send(message);
setMessage("");
};
return (
<Flex align="center" gap="xs" p="md">
<TextInput
disabled={sending}
size="md"
placeholder="Type a message..."
flex={1}
value={message}
onKeyDown={(event) => {
if (event.key === "Enter") {
void handleSend();
}
}}
onChange={(e) => {
setMessage(e.target.value);
}}
/>
<Button
disabled={message.length === 0}
loading={sending}
size="md"
onClick={() => void handleSend()}>
Send
</Button>
</Flex>
);
};