Chats: fix submitting an attachment

revert-fa4bd20d
Alex Gleason 2022-12-06 16:27:07 -06:00
rodzic 6eafb8c0c3
commit dc420a843b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -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 : '';

Wyświetl plik

@ -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>
);

Wyświetl plik

@ -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) => {