Make .compose-form__upload more widely available

This commit is contained in:
Alex Gleason 2022-12-06 17:08:00 -06:00
parent 6a27670271
commit e1edc9796b
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 92 additions and 100 deletions

View file

@ -4,11 +4,12 @@ import React, { MutableRefObject, useEffect, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import { uploadMedia } from 'soapbox/actions/media'; import { uploadMedia } from 'soapbox/actions/media';
import { IconButton, Stack } from 'soapbox/components/ui'; import { Stack } from 'soapbox/components/ui';
import Upload from 'soapbox/components/upload';
import UploadProgress from 'soapbox/components/upload-progress'; import UploadProgress from 'soapbox/components/upload-progress';
import { useAppDispatch } from 'soapbox/hooks'; import { useAppDispatch } from 'soapbox/hooks';
import { normalizeAttachment } from 'soapbox/normalizers';
import { IChat, useChatActions } from 'soapbox/queries/chats'; import { IChat, useChatActions } from 'soapbox/queries/chats';
import { truncateFilename } from 'soapbox/utils/media';
import ChatComposer from './chat-composer'; import ChatComposer from './chat-composer';
import ChatMessageList from './chat-message-list'; import ChatMessageList from './chat-message-list';
@ -144,31 +145,13 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
data.append('file', files[0]); data.append('file', files[0]);
dispatch(uploadMedia(data, onUploadProgress)).then((response: any) => { dispatch(uploadMedia(data, onUploadProgress)).then((response: any) => {
setAttachment(response.data); setAttachment(normalizeAttachment(response.data));
setIsUploading(false); setIsUploading(false);
}).catch(() => { }).catch(() => {
setIsUploading(false); setIsUploading(false);
}); });
}; };
const renderAttachment = () => {
if (!attachment) return null;
return (
<div className='chat-box__attachment'>
<div className='chat-box__filename'>
{truncateFilename(attachment.preview_url, 20)}
</div>
<div className='chat-box__remove-attachment'>
<IconButton
src={require('@tabler/icons/x.svg')}
onClick={handleRemoveFile}
/>
</div>
</div>
);
};
useEffect(() => { useEffect(() => {
if (inputRef?.current) { if (inputRef?.current) {
inputRef.current.focus(); inputRef.current.focus();
@ -181,7 +164,15 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
<ChatMessageList chat={chat} /> <ChatMessageList chat={chat} />
</div> </div>
{renderAttachment()} {attachment && (
<div className='relative h-48'>
<Upload
media={attachment}
onDelete={handleRemoveFile}
withPreview
/>
</div>
)}
{isUploading && ( {isUploading && (
<div className='p-4'> <div className='p-4'>

View file

@ -30,6 +30,9 @@
font-family: inherit; font-family: inherit;
font-size: 14px; font-size: 14px;
background: var(--background-color); background: var(--background-color);
}
}
.compose-form__upload-wrapper { overflow: hidden; } .compose-form__upload-wrapper { overflow: hidden; }
.compose-form__uploads-wrapper { .compose-form__uploads-wrapper {
@ -116,8 +119,6 @@
background-size: cover; background-size: cover;
} }
} }
} // end .compose-form .compose-form__modifiers
} // end .compose-form
.privacy-dropdown__dropdown { .privacy-dropdown__dropdown {
@apply absolute bg-white dark:bg-gray-900 z-[1000] rounded-md shadow-lg ml-10 text-sm; @apply absolute bg-white dark:bg-gray-900 z-[1000] rounded-md shadow-lg ml-10 text-sm;