Chats: fix submitting an attachment
This commit is contained in:
parent
6eafb8c0c3
commit
dc420a843b
3 changed files with 7 additions and 4 deletions
|
@ -39,6 +39,7 @@ interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaEl
|
|||
errorMessage: string | undefined
|
||||
onSelectFile: (files: FileList, intl: IntlShape) => void
|
||||
resetFileKey: number | null
|
||||
hasAttachment?: boolean
|
||||
}
|
||||
|
||||
/** Textarea input for chats. */
|
||||
|
@ -52,6 +53,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
|||
onSelectFile,
|
||||
resetFileKey,
|
||||
onPaste,
|
||||
hasAttachment,
|
||||
}, ref) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const intl = useIntl();
|
||||
|
@ -66,7 +68,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
|||
const isSuggestionsAvailable = suggestions.list.length > 0;
|
||||
|
||||
const isOverCharacterLimit = maxCharacterCount && value?.length > maxCharacterCount;
|
||||
const isSubmitDisabled = disabled || isOverCharacterLimit || value.length === 0;
|
||||
const isSubmitDisabled = disabled || isOverCharacterLimit || (value.length === 0 && !hasAttachment);
|
||||
|
||||
const overLimitText = maxCharacterCount ? maxCharacterCount - value?.length : '';
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
|
|||
const isSubmitDisabled = content.length === 0 && !attachment;
|
||||
|
||||
const submitMessage = () => {
|
||||
createChatMessage.mutate({ chatId: chat.id, content }, {
|
||||
createChatMessage.mutate({ chatId: chat.id, content, mediaId: attachment?.id }, {
|
||||
onSuccess: () => {
|
||||
setErrorMessage(undefined);
|
||||
},
|
||||
|
@ -197,6 +197,7 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
|
|||
onSelectFile={handleFiles}
|
||||
resetFileKey={resetFileKey}
|
||||
onPaste={handlePaste}
|
||||
hasAttachment={!!attachment}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
|
|
|
@ -233,8 +233,8 @@ const useChatActions = (chatId: string) => {
|
|||
|
||||
const createChatMessage = useMutation(
|
||||
(
|
||||
{ chatId, content }: { chatId: string, content: string },
|
||||
) => api.post<IChatMessage>(`/api/v1/pleroma/chats/${chatId}/messages`, { content }),
|
||||
{ chatId, content, mediaId }: { chatId: string, content: string, mediaId?: string },
|
||||
) => api.post<IChatMessage>(`/api/v1/pleroma/chats/${chatId}/messages`, { content, media_id: mediaId }),
|
||||
{
|
||||
retry: false,
|
||||
onMutate: async (variables) => {
|
||||
|
|
Loading…
Reference in a new issue