Chats: move uploading progress into the composer text box

This commit is contained in:
Alex Gleason 2023-02-02 17:37:37 -06:00
parent 6b1882d7a9
commit e203e0d0d2
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 25 additions and 10 deletions

View file

@ -44,6 +44,8 @@ interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaEl
resetFileKey: number | null resetFileKey: number | null
attachments?: Attachment[] attachments?: Attachment[]
onDeleteAttachment?: () => void onDeleteAttachment?: () => void
isUploading?: boolean
uploadProgress?: number
} }
/** Textarea input for chats. */ /** Textarea input for chats. */
@ -59,6 +61,8 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
onPaste, onPaste,
attachments = [], attachments = [],
onDeleteAttachment, onDeleteAttachment,
isUploading,
uploadProgress,
}, ref) => { }, ref) => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -189,6 +193,8 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
disabled={disabled} disabled={disabled}
attachments={attachments} attachments={attachments}
onDeleteAttachment={onDeleteAttachment} onDeleteAttachment={onDeleteAttachment}
isUploading={isUploading}
uploadProgress={uploadProgress}
/> />
{isSuggestionsAvailable ? ( {isSuggestionsAvailable ? (
<ComboboxPopover> <ComboboxPopover>

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Textarea } from 'soapbox/components/ui'; import { ProgressBar, Textarea } from 'soapbox/components/ui';
import { Attachment } from 'soapbox/types/entities'; import { Attachment } from 'soapbox/types/entities';
import ChatUpload from './chat-upload'; import ChatUpload from './chat-upload';
@ -8,10 +8,18 @@ import ChatUpload from './chat-upload';
interface IChatTextarea extends React.ComponentProps<typeof Textarea> { interface IChatTextarea extends React.ComponentProps<typeof Textarea> {
attachments?: Attachment[] attachments?: Attachment[]
onDeleteAttachment?: () => void onDeleteAttachment?: () => void
isUploading?: boolean
uploadProgress?: number
} }
/** Custom textarea for chats. */ /** Custom textarea for chats. */
const ChatTextarea: React.FC<IChatTextarea> = ({ attachments, onDeleteAttachment, ...rest }) => { const ChatTextarea: React.FC<IChatTextarea> = ({
attachments,
onDeleteAttachment,
isUploading = false,
uploadProgress = 0,
...rest
}) => {
return ( return (
<div className={` <div className={`
bg-white bg-white
@ -25,8 +33,14 @@ const ChatTextarea: React.FC<IChatTextarea> = ({ attachments, onDeleteAttachment
dark:focus-within:ring-primary-500 dark:focus-within:border-primary-500 dark:focus-within:ring-primary-500 dark:focus-within:border-primary-500
`} `}
> >
{(!!attachments?.length) && ( {(!!attachments?.length || isUploading) && (
<div className='p-3 pb-0'> <div className='p-3 pb-0'>
{isUploading && (
<div className='relative p-4 inline-flex items-center justify-center w-24 h-24 rounded-lg overflow-hidden isolate bg-gray-200 dark:bg-primary-900'>
<ProgressBar progress={uploadProgress} />
</div>
)}
{attachments?.map(attachment => ( {attachments?.map(attachment => (
<ChatUpload <ChatUpload
key={attachment.id} key={attachment.id}

View file

@ -5,7 +5,6 @@ import { defineMessages, useIntl } from 'react-intl';
import { uploadMedia } from 'soapbox/actions/media'; import { uploadMedia } from 'soapbox/actions/media';
import { Stack } from 'soapbox/components/ui'; import { Stack } from 'soapbox/components/ui';
import UploadProgress from 'soapbox/components/upload-progress';
import { useAppDispatch } from 'soapbox/hooks'; import { useAppDispatch } from 'soapbox/hooks';
import { normalizeAttachment } from 'soapbox/normalizers'; import { normalizeAttachment } from 'soapbox/normalizers';
import { IChat, useChatActions } from 'soapbox/queries/chats'; import { IChat, useChatActions } from 'soapbox/queries/chats';
@ -163,12 +162,6 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
<ChatMessageList chat={chat} /> <ChatMessageList chat={chat} />
</div> </div>
{isUploading && (
<div className='p-4'>
<UploadProgress progress={uploadProgress * 100} />
</div>
)}
<ChatComposer <ChatComposer
ref={inputRef} ref={inputRef}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
@ -181,6 +174,8 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
onPaste={handlePaste} onPaste={handlePaste}
attachments={attachment ? [attachment] : []} attachments={attachment ? [attachment] : []}
onDeleteAttachment={handleRemoveFile} onDeleteAttachment={handleRemoveFile}
isUploading={isUploading}
uploadProgress={uploadProgress}
/> />
</Stack> </Stack>
); );