diff --git a/ts/components/CompositionInput.tsx b/ts/components/CompositionInput.tsx index 60a09fd6d..7ad5af866 100644 --- a/ts/components/CompositionInput.tsx +++ b/ts/components/CompositionInput.tsx @@ -127,6 +127,7 @@ export function CompositionInput(props: Props): React.ReactElement { const quillRef = React.useRef(); const scrollerRef = React.useRef(null); const propsRef = React.useRef(props); + const canSendRef = React.useRef(false); const memberRepositoryRef = React.useRef( new MemberRepository() ); @@ -206,6 +207,7 @@ export function CompositionInput(props: Props): React.ReactElement { return; } + canSendRef.current = true; quill.setText(''); const historyModule = quill.getModule('history'); @@ -235,11 +237,19 @@ export function CompositionInput(props: Props): React.ReactElement { return; } + if (!canSendRef.current) { + log.warn( + 'CompositionInput: Not submitting message - cannot send right now' + ); + return; + } + const [text, mentions] = getTextAndMentions(); log.info( `CompositionInput: Submitting message ${timestamp} with ${mentions.length} mentions` ); + canSendRef.current = false; onSubmit(text, mentions, timestamp); }; @@ -257,6 +267,10 @@ export function CompositionInput(props: Props): React.ReactElement { propsRef.current = props; }, [props]); + React.useEffect(() => { + canSendRef.current = !disabled; + }, [disabled]); + const onShortKeyEnter = (): boolean => { submit(); return false; diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 8c9bb6916..313651c2f 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -9013,6 +9013,14 @@ "reasonCategory": "usageTrusted", "updated": "2021-07-30T16:57:33.618Z" }, + { + "rule": "React-useRef", + "path": "ts/components/CompositionInput.tsx", + "line": " const canSendRef = React.useRef(false);", + "reasonCategory": "usageTrusted", + "updated": "2022-06-25T00:06:19.860Z", + "reasonDetail": "Not used for DOM manipulation" + }, { "rule": "React-useRef", "path": "ts/components/ContactPills.tsx",