sforkowany z mirror/soapbox
Move chat attachments into composer
rodzic
382e464390
commit
7b32373694
|
@ -43,6 +43,7 @@ interface IChatComposer extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaEl
|
||||||
onSelectFile: (files: FileList, intl: IntlShape) => void
|
onSelectFile: (files: FileList, intl: IntlShape) => void
|
||||||
resetFileKey: number | null
|
resetFileKey: number | null
|
||||||
attachments?: Attachment[]
|
attachments?: Attachment[]
|
||||||
|
onDeleteAttachment?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Textarea input for chats. */
|
/** Textarea input for chats. */
|
||||||
|
@ -57,6 +58,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
||||||
resetFileKey,
|
resetFileKey,
|
||||||
onPaste,
|
onPaste,
|
||||||
attachments = [],
|
attachments = [],
|
||||||
|
onDeleteAttachment,
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
@ -186,6 +188,7 @@ const ChatComposer = React.forwardRef<HTMLTextAreaElement | null, IChatComposer>
|
||||||
maxRows={5}
|
maxRows={5}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
attachments={attachments}
|
attachments={attachments}
|
||||||
|
onDeleteAttachment={onDeleteAttachment}
|
||||||
/>
|
/>
|
||||||
{isSuggestionsAvailable ? (
|
{isSuggestionsAvailable ? (
|
||||||
<ComboboxPopover>
|
<ComboboxPopover>
|
||||||
|
|
|
@ -3,12 +3,15 @@ import React from 'react';
|
||||||
import { Textarea } from 'soapbox/components/ui';
|
import { Textarea } from 'soapbox/components/ui';
|
||||||
import { Attachment } from 'soapbox/types/entities';
|
import { Attachment } from 'soapbox/types/entities';
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Custom textarea for chats. */
|
/** Custom textarea for chats. */
|
||||||
const ChatTextarea: React.FC<IChatTextarea> = ({ attachments, ...rest }) => {
|
const ChatTextarea: React.FC<IChatTextarea> = ({ attachments, onDeleteAttachment, ...rest }) => {
|
||||||
return (
|
return (
|
||||||
<div className={`
|
<div className={`
|
||||||
bg-white
|
bg-white
|
||||||
|
@ -22,14 +25,17 @@ const ChatTextarea: React.FC<IChatTextarea> = ({ attachments, ...rest }) => {
|
||||||
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?.map(attachment => (
|
{(!!attachments?.length) && (
|
||||||
<img
|
<div className='p-3 pb-0'>
|
||||||
className='w-8 h-8'
|
{attachments?.map(attachment => (
|
||||||
key={attachment.id}
|
<ChatUpload
|
||||||
src={attachment.url}
|
key={attachment.id}
|
||||||
alt=''
|
attachment={attachment}
|
||||||
/>
|
onDelete={onDeleteAttachment}
|
||||||
))}
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<Textarea theme='transparent' {...rest} />
|
<Textarea theme='transparent' {...rest} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { Icon } from 'soapbox/components/ui';
|
||||||
|
|
||||||
|
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 }) => {
|
||||||
|
return (
|
||||||
|
<div className='relative inline-block'>
|
||||||
|
<div className='absolute right-[6px] top-[6px]'>
|
||||||
|
<RemoveButton onClick={onDelete} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img
|
||||||
|
className='w-24 h-24 rounded-lg'
|
||||||
|
key={attachment.id}
|
||||||
|
src={attachment.url}
|
||||||
|
alt=''
|
||||||
|
/>
|
||||||
|
</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'
|
||||||
|
src={require('@tabler/icons/x.svg')}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChatUpload;
|
|
@ -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 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 { normalizeAttachment } from 'soapbox/normalizers';
|
||||||
|
@ -181,6 +180,7 @@ const Chat: React.FC<ChatInterface> = ({ chat, inputRef, className }) => {
|
||||||
resetFileKey={resetFileKey}
|
resetFileKey={resetFileKey}
|
||||||
onPaste={handlePaste}
|
onPaste={handlePaste}
|
||||||
attachments={attachment ? [attachment] : []}
|
attachments={attachment ? [attachment] : []}
|
||||||
|
onDeleteAttachment={handleRemoveFile}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|
Ładowanie…
Reference in New Issue