CompositionInput: Use sendingRef to ensure we don't double-submit
This commit is contained in:
parent
6a509bab72
commit
8b30d24c18
2 changed files with 22 additions and 0 deletions
|
@ -127,6 +127,7 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
const quillRef = React.useRef<Quill>();
|
const quillRef = React.useRef<Quill>();
|
||||||
const scrollerRef = React.useRef<HTMLDivElement>(null);
|
const scrollerRef = React.useRef<HTMLDivElement>(null);
|
||||||
const propsRef = React.useRef<Props>(props);
|
const propsRef = React.useRef<Props>(props);
|
||||||
|
const canSendRef = React.useRef<boolean>(false);
|
||||||
const memberRepositoryRef = React.useRef<MemberRepository>(
|
const memberRepositoryRef = React.useRef<MemberRepository>(
|
||||||
new MemberRepository()
|
new MemberRepository()
|
||||||
);
|
);
|
||||||
|
@ -206,6 +207,7 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canSendRef.current = true;
|
||||||
quill.setText('');
|
quill.setText('');
|
||||||
|
|
||||||
const historyModule = quill.getModule('history');
|
const historyModule = quill.getModule('history');
|
||||||
|
@ -235,11 +237,19 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canSendRef.current) {
|
||||||
|
log.warn(
|
||||||
|
'CompositionInput: Not submitting message - cannot send right now'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [text, mentions] = getTextAndMentions();
|
const [text, mentions] = getTextAndMentions();
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`CompositionInput: Submitting message ${timestamp} with ${mentions.length} mentions`
|
`CompositionInput: Submitting message ${timestamp} with ${mentions.length} mentions`
|
||||||
);
|
);
|
||||||
|
canSendRef.current = false;
|
||||||
onSubmit(text, mentions, timestamp);
|
onSubmit(text, mentions, timestamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -257,6 +267,10 @@ export function CompositionInput(props: Props): React.ReactElement {
|
||||||
propsRef.current = props;
|
propsRef.current = props;
|
||||||
}, [props]);
|
}, [props]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
canSendRef.current = !disabled;
|
||||||
|
}, [disabled]);
|
||||||
|
|
||||||
const onShortKeyEnter = (): boolean => {
|
const onShortKeyEnter = (): boolean => {
|
||||||
submit();
|
submit();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -9013,6 +9013,14 @@
|
||||||
"reasonCategory": "usageTrusted",
|
"reasonCategory": "usageTrusted",
|
||||||
"updated": "2021-07-30T16:57:33.618Z"
|
"updated": "2021-07-30T16:57:33.618Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "React-useRef",
|
||||||
|
"path": "ts/components/CompositionInput.tsx",
|
||||||
|
"line": " const canSendRef = React.useRef<boolean>(false);",
|
||||||
|
"reasonCategory": "usageTrusted",
|
||||||
|
"updated": "2022-06-25T00:06:19.860Z",
|
||||||
|
"reasonDetail": "Not used for DOM manipulation"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "React-useRef",
|
"rule": "React-useRef",
|
||||||
"path": "ts/components/ContactPills.tsx",
|
"path": "ts/components/ContactPills.tsx",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue