fix: reply storage is updated with the new content on file upload (#1585)
* fix: reply storage is updated with the new content on file upload * Revert "fix: reply storage is updated with the new content on file upload" This reverts commit 350931fd0c7a47ffe59716722755ab294c481b71. * chore: reworked image draft save by using events * chore: helpers.setValue called just after setNativeValue * chore: updated setNativeValue function to be more use-case specific
This commit is contained in:
parent
8a2bd84f69
commit
83e72e21cc
|
@ -131,6 +131,14 @@ export function InputSkeleton ({ label, hint }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fix https://github.com/stackernews/stacker.news/issues/1522
|
||||||
|
// see https://github.com/facebook/react/issues/11488#issuecomment-558874287
|
||||||
|
function setNativeValue (textarea, value) {
|
||||||
|
const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value')?.set
|
||||||
|
setter?.call(textarea, value)
|
||||||
|
textarea.dispatchEvent(new Event('input', { bubbles: true, value }))
|
||||||
|
}
|
||||||
|
|
||||||
export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKeyDown, innerRef, ...props }) {
|
export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKeyDown, innerRef, ...props }) {
|
||||||
const [tab, setTab] = useState('write')
|
const [tab, setTab] = useState('write')
|
||||||
const [, meta, helpers] = useField(props)
|
const [, meta, helpers] = useField(props)
|
||||||
|
@ -367,6 +375,7 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKe
|
||||||
let text = innerRef.current.value
|
let text = innerRef.current.value
|
||||||
text = text.replace(`![Uploading ${name}…]()`, `![](${url})`)
|
text = text.replace(`![Uploading ${name}…]()`, `![](${url})`)
|
||||||
helpers.setValue(text)
|
helpers.setValue(text)
|
||||||
|
setNativeValue(innerRef.current, text)
|
||||||
const s3Keys = [...text.matchAll(AWS_S3_URL_REGEXP)].map(m => Number(m[1]))
|
const s3Keys = [...text.matchAll(AWS_S3_URL_REGEXP)].map(m => Number(m[1]))
|
||||||
updateUploadFees({ variables: { s3Keys } })
|
updateUploadFees({ variables: { s3Keys } })
|
||||||
setSubmitDisabled?.(false)
|
setSubmitDisabled?.(false)
|
||||||
|
|
Loading…
Reference in New Issue