(props: { comment: CommentModel })
| 15 | |
| 16 | const replyTextAtom = atom('') |
| 17 | export const ReplyModal = (props: { comment: CommentModel }) => { |
| 18 | const { author, id, text } = props.comment |
| 19 | |
| 20 | const store = useStore() |
| 21 | const [, getValue, ref] = useUncontrolledInput<HTMLTextAreaElement>( |
| 22 | store.get(replyTextAtom), |
| 23 | ) |
| 24 | |
| 25 | const { dismiss, ref: modalElRef } = useCurrentModal() |
| 26 | |
| 27 | const { mutateAsync: reply } = useReplyCommentMutation() |
| 28 | const handleReply = useEventCallback(async () => { |
| 29 | const text = getValue() |
| 30 | if (!text) { |
| 31 | toast.error('回复内容不能为空') |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | reply({ |
| 36 | id, |
| 37 | content: text, |
| 38 | }) |
| 39 | |
| 40 | dismiss() |
| 41 | |
| 42 | store.set(replyTextAtom, '') |
| 43 | }) |
| 44 | |
| 45 | const handleSubmit = useEventCallback((e: any) => { |
| 46 | e.preventDefault() |
| 47 | }) |
| 48 | |
| 49 | const handleKeyDown = useEventCallback((e: React.KeyboardEvent) => { |
| 50 | // cmd + enter / ctrl + enter |
| 51 | if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { |
| 52 | handleReply() |
| 53 | } |
| 54 | }) |
| 55 | |
| 56 | const isMobile = useIsMobile() |
| 57 | |
| 58 | useEffect(() => { |
| 59 | const $ = ref.current |
| 60 | return () => { |
| 61 | if (!$) return |
| 62 | store.set(replyTextAtom, $.value) |
| 63 | } |
| 64 | }, [store, ref]) |
| 65 | |
| 66 | const [kaomojiPanelOpen, setKaomojiPanelOpen] = useState(false) |
| 67 | |
| 68 | return ( |
| 69 | <form |
| 70 | className="flex w-[500px] max-w-full flex-col" |
| 71 | onSubmit={handleSubmit} |
| 72 | > |
| 73 | <div className="mb-8"> |
| 74 | <Label>回复 {author}:</Label> |
nothing calls this directly
no test coverage detected