({
extensionId,
parentId,
onSuccess,
onCancel,
placeholder = "Write a comment... (Markdown supported)",
autoFocus = false,
}: CommentFormProps)
| 17 | } |
| 18 | |
| 19 | export function CommentForm({ |
| 20 | extensionId, |
| 21 | parentId, |
| 22 | onSuccess, |
| 23 | onCancel, |
| 24 | placeholder = "Write a comment... (Markdown supported)", |
| 25 | autoFocus = false, |
| 26 | }: CommentFormProps) { |
| 27 | const [content, setContent] = useState("") |
| 28 | const [isSubmitting, setIsSubmitting] = useState(false) |
| 29 | const [error, setError] = useState<string | null>(null) |
| 30 | |
| 31 | const addComment = useMutation(api.comments.add) |
| 32 | |
| 33 | const handleSubmit = async (e: React.FormEvent) => { |
| 34 | e.preventDefault() |
| 35 | if (!content.trim()) return |
| 36 | |
| 37 | setIsSubmitting(true) |
| 38 | setError(null) |
| 39 | |
| 40 | try { |
| 41 | await addComment({ |
| 42 | extensionId, |
| 43 | parentId, |
| 44 | content: content.trim(), |
| 45 | }) |
| 46 | setContent("") |
| 47 | onSuccess?.() |
| 48 | } catch (err) { |
| 49 | setError(err instanceof Error ? err.message : "Failed to post comment") |
| 50 | } finally { |
| 51 | setIsSubmitting(false) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return ( |
| 56 | <form onSubmit={handleSubmit} className="flex flex-col gap-3"> |
| 57 | <Textarea |
| 58 | value={content} |
| 59 | onChange={(e) => setContent(e.target.value)} |
| 60 | placeholder={placeholder} |
| 61 | className="min-h-[100px] resize-y" |
| 62 | autoFocus={autoFocus} |
| 63 | disabled={isSubmitting} |
| 64 | /> |
| 65 | {error && ( |
| 66 | <p className="text-sm text-[var(--color-danger)]">{error}</p> |
| 67 | )} |
| 68 | <div className="flex items-center justify-end gap-2"> |
| 69 | {onCancel && ( |
| 70 | <Button |
| 71 | type="button" |
| 72 | variant="ghost" |
| 73 | size="sm" |
| 74 | onClick={onCancel} |
| 75 | disabled={isSubmitting} |
| 76 | > |
nothing calls this directly
no outgoing calls
no test coverage detected