forked from pointer-gg/comments-with-polygon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentEditor.tsx
58 lines (54 loc) · 1.41 KB
/
CommentEditor.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
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as React from "react";
import { HStack, Stack, Textarea } from "@chakra-ui/react";
import { constants } from "ethers";
import Avatar from "@davatar/react";
import AuthButton from "./AuthButton";
import { useAccount } from "wagmi";
import useAddComment from "../hooks/useAddComment";
interface CommentEditorProps {
topic: string;
}
const CommentEditor: React.FunctionComponent<CommentEditorProps> = ({
topic,
}) => {
const [message, setMessage] = React.useState("");
const mutation = useAddComment();
const [accountQuery] = useAccount();
return (
<Stack spacing={3}>
<HStack spacing={3} alignItems="start">
<Avatar
size={48}
address={accountQuery.data?.address || constants.AddressZero}
/>
<Textarea
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder="Write a message.."
p={3}
flex={1}
bg="whiteAlpha.100"
rounded="2xl"
fontSize="lg"
/>
</HStack>
<AuthButton
size="sm"
colorScheme="pink"
alignSelf="flex-end"
onClick={() => {
mutation
.mutateAsync({
message,
topic,
})
.then(() => setMessage(""));
}}
isLoading={mutation.isLoading}
>
Submit
</AuthButton>
</Stack>
);
};
export default CommentEditor;