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 scrollerRef = React.useRef<HTMLDivElement>(null);
|
||||
const propsRef = React.useRef<Props>(props);
|
||||
const canSendRef = React.useRef<boolean>(false);
|
||||
const memberRepositoryRef = React.useRef<MemberRepository>(
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue