pleroma/app/soapbox/features/chats/components/chat-upload.tsx

69 lines
1.9 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
import { List as ImmutableList } from 'immutable';
2023-01-26 10:30:26 -08:00
import React from 'react';
import { openModal } from 'soapbox/actions/modals';
2023-02-02 11:06:27 -08:00
import Blurhash from 'soapbox/components/blurhash';
2023-01-26 10:30:26 -08:00
import { Icon } from 'soapbox/components/ui';
import { useAppDispatch } from 'soapbox/hooks';
2023-01-26 10:30:26 -08:00
import type { Attachment } from 'soapbox/types/entities';
interface IChatUpload {
attachment: Attachment,
onDelete?(): void,
}
/** An attachment uploaded to the chat composer, before sending. */
const ChatUpload: React.FC<IChatUpload> = ({ attachment, onDelete }) => {
const dispatch = useAppDispatch();
const clickable = attachment.type !== 'unknown';
const handleOpenModal = () => {
dispatch(openModal('MEDIA', { media: ImmutableList.of(attachment), index: 0 }));
};
2023-01-26 10:30:26 -08:00
return (
<div className='relative inline-block w-24 h-24 rounded-lg overflow-hidden isolate'>
2023-02-02 11:06:27 -08:00
<Blurhash hash={attachment.blurhash} className='absolute inset-0 w-full h-full -z-10' />
2023-01-26 10:30:26 -08:00
<div className='absolute right-[6px] top-[6px]'>
<RemoveButton onClick={onDelete} />
</div>
<button
onClick={clickable ? handleOpenModal : undefined}
className={clsx('w-full h-full', { 'cursor-zoom-in': clickable, 'cursor-default': !clickable })}
>
<img
className='w-full h-full object-cover'
key={attachment.id}
src={attachment.url}
alt=''
/>
</button>
2023-01-26 10:30:26 -08:00
</div>
);
};
interface IRemoveButton {
onClick?: React.MouseEventHandler<HTMLButtonElement>
}
/** Floating button to remove an attachment. */
const RemoveButton: React.FC<IRemoveButton> = ({ onClick }) => {
return (
<button
type='button'
onClick={onClick}
className='bg-secondary-500 w-5 h-5 p-1 rounded-full flex items-center justify-center'
>
<Icon
className='w-4 h-4 text-white'
2023-01-26 10:30:26 -08:00
src={require('@tabler/icons/x.svg')}
/>
</button>
);
};
export default ChatUpload;