(event)
| 169 | ); |
| 170 | |
| 171 | async function handleSubmit(event) { |
| 172 | event.preventDefault(); |
| 173 | if (contentTooLarge || submitting) { |
| 174 | return; |
| 175 | } |
| 176 | const form = event.currentTarget; |
| 177 | const submitter = event.nativeEvent.submitter; |
| 178 | setSubmitting(true); |
| 179 | try { |
| 180 | const finalizedContent = await finalizePostContentAttachments(content, attachmentsRef.current); |
| 181 | const finalizedContentBytes = getUtf8ByteLength(finalizedContent); |
| 182 | if (finalizedContentBytes > POST_CONTENT_MAX_BYTES) { |
| 183 | setContentError(`文章内容不能超过 ${formatPostContentSize(POST_CONTENT_MAX_BYTES)},当前 ${formatPostContentSize(finalizedContentBytes)}。`); |
| 184 | return; |
| 185 | } |
| 186 | const formData = new FormData(form); |
| 187 | if (submitter?.name) { |
| 188 | formData.set(submitter.name, submitter.value); |
| 189 | } |
| 190 | formData.set("Content", finalizedContent); |
| 191 | submit(formData, {method: "post"}); |
| 192 | } catch (error) { |
| 193 | setContentError(error.message); |
| 194 | } finally { |
| 195 | setSubmitting(false); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return ( |
| 200 | <Form |
nothing calls this directly
no test coverage detected