2023-01-25 13:45:33 -08:00
|
|
|
import React from 'react';
|
|
|
|
|
2023-02-08 10:50:35 -08:00
|
|
|
import { HStack, Textarea } from 'soapbox/components/ui';
|
2023-01-25 13:45:33 -08:00
|
|
|
import { Attachment } from 'soapbox/types/entities';
|
|
|
|
|
2023-02-02 16:03:22 -08:00
|
|
|
import ChatPendingUpload from './chat-pending-upload';
|
2023-01-26 10:30:26 -08:00
|
|
|
import ChatUpload from './chat-upload';
|
|
|
|
|
2023-01-25 13:45:33 -08:00
|
|
|
interface IChatTextarea extends React.ComponentProps<typeof Textarea> {
|
|
|
|
attachments?: Attachment[]
|
2023-02-08 11:02:48 -08:00
|
|
|
onDeleteAttachment?: (i: number) => void
|
2023-02-27 07:59:00 -08:00
|
|
|
uploadCount?: number
|
2023-02-02 15:37:37 -08:00
|
|
|
uploadProgress?: number
|
2023-01-25 13:45:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Custom textarea for chats. */
|
2023-02-02 15:37:37 -08:00
|
|
|
const ChatTextarea: React.FC<IChatTextarea> = ({
|
|
|
|
attachments,
|
|
|
|
onDeleteAttachment,
|
2023-02-27 07:59:00 -08:00
|
|
|
uploadCount = 0,
|
2023-02-02 15:37:37 -08:00
|
|
|
uploadProgress = 0,
|
|
|
|
...rest
|
|
|
|
}) => {
|
2023-02-27 07:59:00 -08:00
|
|
|
const isUploading = uploadCount > 0;
|
|
|
|
|
2023-02-08 11:02:48 -08:00
|
|
|
const handleDeleteAttachment = (i: number) => {
|
|
|
|
return () => {
|
|
|
|
if (onDeleteAttachment) {
|
|
|
|
onDeleteAttachment(i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-25 13:45:33 -08:00
|
|
|
return (
|
|
|
|
<div className={`
|
2023-02-03 10:03:45 -08:00
|
|
|
block
|
|
|
|
w-full
|
|
|
|
rounded-md border border-gray-400
|
|
|
|
bg-white text-gray-900
|
|
|
|
shadow-sm placeholder:text-gray-600
|
|
|
|
focus-within:border-primary-500
|
|
|
|
focus-within:ring-1 focus-within:ring-primary-500 dark:border-gray-800 dark:bg-gray-800
|
|
|
|
dark:text-gray-100 dark:ring-1 dark:ring-gray-800 dark:placeholder:text-gray-600 dark:focus-within:border-primary-500
|
|
|
|
dark:focus-within:ring-primary-500 sm:text-sm
|
2023-01-25 13:45:33 -08:00
|
|
|
`}
|
|
|
|
>
|
2023-02-02 15:37:37 -08:00
|
|
|
{(!!attachments?.length || isUploading) && (
|
2023-02-08 10:50:35 -08:00
|
|
|
<HStack className='-ml-2 -mt-2 p-3 pb-0' wrap>
|
2023-02-08 11:02:48 -08:00
|
|
|
{attachments?.map((attachment, i) => (
|
2023-02-08 10:50:35 -08:00
|
|
|
<div className='ml-2 mt-2 flex'>
|
|
|
|
<ChatUpload
|
|
|
|
key={attachment.id}
|
|
|
|
attachment={attachment}
|
2023-02-08 11:02:48 -08:00
|
|
|
onDelete={handleDeleteAttachment(i)}
|
2023-02-08 10:50:35 -08:00
|
|
|
/>
|
|
|
|
</div>
|
2023-01-26 10:30:26 -08:00
|
|
|
))}
|
2023-02-08 10:50:35 -08:00
|
|
|
|
2023-02-27 07:59:00 -08:00
|
|
|
{Array.from(Array(uploadCount)).map(() => (
|
2023-02-08 10:50:35 -08:00
|
|
|
<div className='ml-2 mt-2 flex'>
|
|
|
|
<ChatPendingUpload progress={uploadProgress} />
|
|
|
|
</div>
|
2023-02-27 07:59:00 -08:00
|
|
|
))}
|
2023-02-08 10:50:35 -08:00
|
|
|
</HStack>
|
2023-01-26 10:30:26 -08:00
|
|
|
)}
|
2023-01-25 13:45:33 -08:00
|
|
|
|
|
|
|
<Textarea theme='transparent' {...rest} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
export default ChatTextarea;
|