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
|
errorMessage: string | undefined
|
||||||
onSelectFile: (files: FileList, intl: IntlShape) => void
|
onSelectFile: (files: FileList, intl: IntlShape) => void
|
||||||
resetFileKey: number | null
|
resetFileKey: number | null
|
||||||
|
hasAttachment?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Textarea input for chats. */
|
/** Textarea input for chats. */
|
||||||
|
@ -52,6 +53,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
||||||
onSelectFile,
|
onSelectFile,
|
||||||
resetFileKey,
|
resetFileKey,
|
||||||
onPaste,
|
onPaste,
|
||||||
|
hasAttachment,
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -66,7 +68,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
||||||
const isSuggestionsAvailable = suggestions.list.length > 0;
|
const isSuggestionsAvailable = suggestions.list.length > 0;
|
||||||
|
|
||||||
const isOverCharacterLimit = maxCharacterCount && value?.length > maxCharacterCount;
|
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 : '';
|
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 isSubmitDisabled = content.length === 0 && !attachment;
|
||||||
|
|
||||||
const submitMessage = () => {
|
const submitMessage = () => {
|
||||||
createChatMessage.mutate({ chatId: chat.id, content }, {
|
createChatMessage.mutate({ chatId: chat.id, content, mediaId: attachment?.id }, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setErrorMessage(undefined);
|
setErrorMessage(undefined);
|
||||||
},
|
},
|
||||||
|
@ -197,6 +197,7 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
|
||||||
onSelectFile={handleFiles}
|
onSelectFile={handleFiles}
|
||||||
resetFileKey={resetFileKey}
|
resetFileKey={resetFileKey}
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
|
hasAttachment={!!attachment}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|
|
@ -233,8 +233,8 @@ const useChatActions = (chatId: string) => {
|
||||||
|
|
||||||
const createChatMessage = useMutation(
|
const createChatMessage = useMutation(
|
||||||
(
|
(
|
||||||
{ chatId, content }: { chatId: string, content: string },
|
{ chatId, content, mediaId }: { chatId: string, content: string, mediaId?: string },
|
||||||
) => api.post<IChatMessage>(`/api/v1/pleroma/chats/${chatId}/messages`, { content }),
|
) => api.post<IChatMessage>(`/api/v1/pleroma/chats/${chatId}/messages`, { content, media_id: mediaId }),
|
||||||
{
|
{
|
||||||
retry: false,
|
retry: false,
|
||||||
onMutate: async (variables) => {
|
onMutate: async (variables) => {
|
||||||
|
|
Loading…
Reference in a new issue