fix: prevent duplicate post submissions
This commit is contained in:
parent
a6d6a19199
commit
c2b0e6f666
1 changed files with 6 additions and 2 deletions
|
|
@ -118,11 +118,14 @@ export default function PostContent({
|
||||||
)
|
)
|
||||||
}, [defaultContent, parentStuff, isNsfw, isPoll, pollCreateData, addClientTag])
|
}, [defaultContent, parentStuff, isNsfw, isPoll, pollCreateData, addClientTag])
|
||||||
|
|
||||||
|
const postingRef = useRef(false)
|
||||||
|
|
||||||
const post = async (e?: React.MouseEvent) => {
|
const post = async (e?: React.MouseEvent) => {
|
||||||
e?.stopPropagation()
|
e?.stopPropagation()
|
||||||
checkLogin(async () => {
|
checkLogin(async () => {
|
||||||
if (!canPost) return
|
if (!canPost || postingRef.current) return
|
||||||
|
|
||||||
|
postingRef.current = true
|
||||||
setPosting(true)
|
setPosting(true)
|
||||||
try {
|
try {
|
||||||
const draftEvent =
|
const draftEvent =
|
||||||
|
|
@ -158,6 +161,7 @@ export default function PostContent({
|
||||||
postEditorCache.clearPostCache({ defaultContent, parentStuff })
|
postEditorCache.clearPostCache({ defaultContent, parentStuff })
|
||||||
deleteDraftEventCache(draftEvent)
|
deleteDraftEventCache(draftEvent)
|
||||||
addReplies([newEvent])
|
addReplies([newEvent])
|
||||||
|
toast.success(t('Post successful'), { duration: 2000 })
|
||||||
close()
|
close()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errors = error instanceof AggregateError ? error.errors : [error]
|
const errors = error instanceof AggregateError ? error.errors : [error]
|
||||||
|
|
@ -171,8 +175,8 @@ export default function PostContent({
|
||||||
return
|
return
|
||||||
} finally {
|
} finally {
|
||||||
setPosting(false)
|
setPosting(false)
|
||||||
|
postingRef.current = false
|
||||||
}
|
}
|
||||||
toast.success(t('Post successful'), { duration: 2000 })
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue