diff --git a/app/soapbox/features/chats/chat-room.tsx b/app/soapbox/features/chats/chat-room.tsx index 222f208a1..520349288 100644 --- a/app/soapbox/features/chats/chat-room.tsx +++ b/app/soapbox/features/chats/chat-room.tsx @@ -1,5 +1,5 @@ import { Map as ImmutableMap } from 'immutable'; -import React, { useEffect, useRef } from 'react'; +import React, { useEffect } from 'react'; import { fetchChat, markChatRead } from 'soapbox/actions/chats'; import { Column } from 'soapbox/components/ui'; @@ -22,22 +22,12 @@ interface IChatRoom { const ChatRoom: React.FC = ({ params }) => { const dispatch = useAppDispatch(); const displayFqn = useAppSelector(getDisplayFqn); - const inputElem = useRef(null); const chat = useAppSelector(state => { const chat = state.chats.items.get(params.chatId, ImmutableMap()).toJS() as any; return getChat(state, chat); }); - const focusInput = () => { - inputElem.current?.focus(); - }; - - const handleInputRef = (el: HTMLTextAreaElement) => { - inputElem.current = el; - focusInput(); - }; - const markRead = () => { if (!chat) return; dispatch(markChatRead(chat.id)); @@ -57,11 +47,7 @@ const ChatRoom: React.FC = ({ params }) => { return ( - + ); }; diff --git a/app/soapbox/features/chats/components/chat-box.tsx b/app/soapbox/features/chats/components/chat-box.tsx index 9553dec34..3c78e7603 100644 --- a/app/soapbox/features/chats/components/chat-box.tsx +++ b/app/soapbox/features/chats/components/chat-box.tsx @@ -1,20 +1,13 @@ import { useMutation } from '@tanstack/react-query'; -import { OrderedSet as ImmutableOrderedSet } from 'immutable'; -import React, { MutableRefObject, useEffect, useRef, useState } from 'react'; +import React, { MutableRefObject, useState } from 'react'; import { useIntl, defineMessages } from 'react-intl'; -import { - sendChatMessage, - markChatRead, -} from 'soapbox/actions/chats'; import { uploadMedia } from 'soapbox/actions/media'; -import { openModal } from 'soapbox/actions/modals'; -import { initReport } from 'soapbox/actions/reports'; -import { Avatar, Button, HStack, Icon, IconButton, Input, Stack, Text, Textarea } from 'soapbox/components/ui'; +import { HStack, IconButton, Stack, Text, Textarea } from 'soapbox/components/ui'; import UploadProgress from 'soapbox/components/upload-progress'; import UploadButton from 'soapbox/features/compose/components/upload_button'; import { useAppSelector, useAppDispatch, useOwnAccount } from 'soapbox/hooks'; -import { IChat, IChatMessage, useChat } from 'soapbox/queries/chats'; +import { IChat, useChat } from 'soapbox/queries/chats'; import { queryClient } from 'soapbox/queries/client'; import { truncateFilename } from 'soapbox/utils/media'; @@ -29,7 +22,6 @@ const fileKeyGen = (): number => Math.floor((Math.random() * 0x10000)); interface IChatBox { chat: IChat, - onSetInputRef: (el: HTMLTextAreaElement) => void, autosize?: boolean, inputRef?: MutableRefObject } @@ -38,21 +30,19 @@ interface IChatBox { * Chat UI with just the messages and textarea. * Reused between floating desktop chats and fullscreen/mobile chats. */ -const ChatBox: React.FC = ({ chat, onSetInputRef, autosize, inputRef }) => { +const ChatBox: React.FC = ({ chat, autosize, inputRef }) => { const intl = useIntl(); const dispatch = useAppDispatch(); - const chatMessageIds = useAppSelector(state => state.chat_message_lists.get(chat.id, ImmutableOrderedSet())); const account = useOwnAccount(); - const { createChatMessage, markChatAsRead, acceptChat } = useChat(chat.id); + const { createChatMessage, acceptChat } = useChat(chat.id); const [content, setContent] = useState(''); const [attachment, setAttachment] = useState(undefined); const [isUploading, setIsUploading] = useState(false); const [uploadProgress, setUploadProgress] = useState(0); const [resetFileKey, setResetFileKey] = useState(fileKeyGen()); - - const inputElem = useRef(null); + const [hasErrorSubmittingMessage, setErrorSubmittingMessage] = useState(false); const isSubmitDisabled = content.length === 0 && !attachment; @@ -99,6 +89,7 @@ const ChatBox: React.FC = ({ chat, onSetInputRef, autosize, inputRef } onError: (_error: any, _newData: any, context: any) => { setContent(context.prevContent); queryClient.setQueryData(['chats', 'messages', chat.id], context.prevChatMessages); + setErrorSubmittingMessage(true); }, // Always refetch after error or success: onSuccess: () => { @@ -112,6 +103,7 @@ const ChatBox: React.FC = ({ chat, onSetInputRef, autosize, inputRef } setIsUploading(false); setUploadProgress(0); setResetFileKey(fileKeyGen()); + setErrorSubmittingMessage(false); }; const sendMessage = () => { @@ -217,11 +209,11 @@ const ChatBox: React.FC = ({ chat, onSetInputRef, autosize, inputRef }
-
+ -
+
-
+