CHats: fix deleting a specific attachment

gleasonator^2
Alex Gleason 2023-02-08 13:02:48 -06:00
rodzic 64f17ef013
commit 6eadaf2942
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 16 dodań i 6 usunięć

Wyświetl plik

@ -43,7 +43,7 @@ interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaEl
onSelectFile: (files: FileList, intl: IntlShape) => void
resetFileKey: number | null
attachments?: Attachment[]
onDeleteAttachment?: () => void
onDeleteAttachment?: (i: number) => void
isUploading?: boolean
uploadProgress?: number
}

Wyświetl plik

@ -8,7 +8,7 @@ import ChatUpload from './chat-upload';
interface IChatTextarea extends React.ComponentProps<typeof Textarea> {
attachments?: Attachment[]
onDeleteAttachment?: () => void
onDeleteAttachment?: (i: number) => void
isUploading?: boolean
uploadProgress?: number
}
@ -21,6 +21,14 @@ const ChatTextarea: React.FC<IChatTextarea> = ({
uploadProgress = 0,
...rest
}) => {
const handleDeleteAttachment = (i: number) => {
return () => {
if (onDeleteAttachment) {
onDeleteAttachment(i);
}
};
};
return (
<div className={`
block
@ -36,12 +44,12 @@ const ChatTextarea: React.FC<IChatTextarea> = ({
>
{(!!attachments?.length || isUploading) && (
<HStack className='-ml-2 -mt-2 p-3 pb-0' wrap>
{attachments?.map(attachment => (
{attachments?.map((attachment, i) => (
<div className='ml-2 mt-2 flex'>
<ChatUpload
key={attachment.id}
attachment={attachment}
onDelete={onDeleteAttachment}
onDelete={handleDeleteAttachment(i)}
/>
</div>
))}

Wyświetl plik

@ -131,8 +131,10 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
const handleMouseOver = () => markRead();
const handleRemoveFile = () => {
setAttachments([]);
const handleRemoveFile = (i: number) => {
const newAttachments = [...attachments];
newAttachments.splice(i, 1);
setAttachments(newAttachments);
setResetFileKey(fileKeyGen());
};