Disable submit button

This commit is contained in:
Justin 2022-08-12 11:48:56 -04:00
parent 84dc06db42
commit 751c031420
1 changed files with 5 additions and 11 deletions

View File

@ -51,6 +51,8 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
const inputElem = useRef<HTMLTextAreaElement | null>(null); const inputElem = useRef<HTMLTextAreaElement | null>(null);
const isSubmitDisabled = content.length === 0 && !attachment;
// TODO: needs last_read_id param // TODO: needs last_read_id param
const markAsRead = useMutation(() => markChatAsRead(), { const markAsRead = useMutation(() => markChatAsRead(), {
onSuccess: () => { onSuccess: () => {
@ -114,17 +116,8 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
setResetFileKey(fileKeyGen()); setResetFileKey(fileKeyGen());
}; };
const canSubmit = () => {
const conds = [
content.length > 0,
attachment,
];
return conds.some(c => c);
};
const sendMessage = () => { const sendMessage = () => {
if (canSubmit() && !submitMessage.isLoading) { if (!isSubmitDisabled && !submitMessage.isLoading) {
const params = { const params = {
content, content,
media_id: attachment && attachment.id, media_id: attachment && attachment.id,
@ -153,7 +146,7 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
}; };
const handlePaste: React.ClipboardEventHandler<HTMLTextAreaElement> = (e) => { const handlePaste: React.ClipboardEventHandler<HTMLTextAreaElement> = (e) => {
if (!canSubmit() && e.clipboardData && e.clipboardData.files.length === 1) { if (isSubmitDisabled && e.clipboardData && e.clipboardData.files.length === 1) {
handleFiles(e.clipboardData.files); handleFiles(e.clipboardData.files);
} }
}; };
@ -245,6 +238,7 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
src={require('@tabler/icons/send.svg')} src={require('@tabler/icons/send.svg')}
iconClassName='w-5 h-5' iconClassName='w-5 h-5'
className='text-primary-500' className='text-primary-500'
disabled={isSubmitDisabled}
onClick={sendMessage} onClick={sendMessage}
/> />
</HStack> </HStack>