MCPcopy
hub / github.com/Innei/Shiro / ReplyModal

Function ReplyModal

src/components/modules/dashboard/comments/ReplyModal.tsx:17–117  ·  view source on GitHub ↗
(props: { comment: CommentModel })

Source from the content-addressed store, hash-verified

15
16const replyTextAtom = atom('')
17export 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>

Callers

nothing calls this directly

Calls 7

useUncontrolledInputFunction · 0.90
useCurrentModalFunction · 0.90
useReplyCommentMutationFunction · 0.90
useEventCallbackFunction · 0.90
useIsMobileFunction · 0.90
errorMethod · 0.80
dismissFunction · 0.50

Tested by

no test coverage detected