Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reply storage is updated with the new content on file upload #1585

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
const [tab, setTab] = useState('write')
const [, meta, helpers] = useField(props)
Expand Down Expand Up @@ -367,6 +375,7 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, onKe
let text = innerRef.current.value
text = text.replace(`![Uploading ${name}…]()`, `![](${url})`)
helpers.setValue(text)
setNativeValue(innerRef.current, text)
aegroto marked this conversation as resolved.
Show resolved Hide resolved
const s3Keys = [...text.matchAll(AWS_S3_URL_REGEXP)].map(m => Number(m[1]))
updateUploadFees({ variables: { s3Keys } })
setSubmitDisabled?.(false)
Expand Down
Loading