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

disabled btn on msg sending #1184

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect } from 'react';
import { useContext, useEffect, useState } from 'react';
import { AuthContext } from '../../context/AuthContext';
import { ConversationContext } from '../../context/ConversationContext';
import { MessageContext } from '../../context/MessageContext';
Expand All @@ -14,6 +14,7 @@ export function MessageInputField(props: MessageDataProps) {
const { addMessage } = useContext(MessageContext);
const { setMessageView, messageView } = useContext(UiViewContext);
const { setLastMessageAction } = useContext(ModalContext);
const [isSendBtnDisabled, setIsSendBtnDisabled] = useState<boolean>(false);

const resetMessageView = {
actionType: MessageActionType.NONE,
Expand All @@ -31,6 +32,10 @@ export function MessageInputField(props: MessageDataProps) {

async function submit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (isSendBtnDisabled) {
return;
}
setIsSendBtnDisabled(true);
await onSubmitMessage(
messageView,
setMessageView,
Expand All @@ -41,6 +46,7 @@ export function MessageInputField(props: MessageDataProps) {
account!,
selectedContact!,
);
setIsSendBtnDisabled(false);
}

// Focus on input field when user selects a msg to EEDIT or REPLY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './SendMessage.css';
import { useContext } from 'react';
import { useContext, useState } from 'react';
import sendBtnIcon from '../../assets/images/send-btn.svg';
import { AuthContext } from '../../context/AuthContext';
import { ConversationContext } from '../../context/ConversationContext';
Expand All @@ -15,8 +15,13 @@ export function SendMessage(props: MessageDataProps) {
const { selectedContact } = useContext(ConversationContext);
const { messageView, setMessageView } = useContext(UiViewContext);
const { setLastMessageAction } = useContext(ModalContext);
const [isSendBtnDisabled, setIsSendBtnDisabled] = useState<boolean>(false);

async function submit() {
if (isSendBtnDisabled) {
return;
}
setIsSendBtnDisabled(true);
await onSubmitMessage(
messageView,
setMessageView,
Expand All @@ -27,6 +32,7 @@ export function SendMessage(props: MessageDataProps) {
account!,
selectedContact!,
);
setIsSendBtnDisabled(false);
}

return (
Expand Down
Loading