bigbuffet-rw/app/soapbox/features/compose/components/upload.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
2022-05-30 11:53:14 -07:00
import { useHistory } from 'react-router-dom';
import { undoUploadCompose, changeUploadCompose, submitCompose } from 'soapbox/actions/compose';
import Upload from 'soapbox/components/upload';
2022-11-26 08:38:16 -08:00
import { useAppDispatch, useCompose, useInstance } from 'soapbox/hooks';
2022-05-30 11:53:14 -07:00
interface IUploadCompose {
id: string
composeId: string
2022-05-30 11:53:14 -07:00
}
const UploadCompose: React.FC<IUploadCompose> = ({ composeId, id }) => {
2022-05-30 11:53:14 -07:00
const history = useHistory();
const dispatch = useAppDispatch();
2022-11-26 08:38:16 -08:00
const { description_limit: descriptionLimit } = useInstance();
2022-11-26 08:38:16 -08:00
const media = useCompose(composeId).media_attachments.find(item => item.id === id)!;
2022-05-30 11:53:14 -07:00
const handleSubmit = () => {
dispatch(submitCompose(composeId, history));
2022-05-30 11:53:14 -07:00
};
const handleDescriptionChange = (description: string) => {
dispatch(changeUploadCompose(composeId, media.id, { description }));
2022-05-30 11:53:14 -07:00
};
const handleDelete = () => {
dispatch(undoUploadCompose(composeId, media.id));
2022-05-30 11:53:14 -07:00
};
return (
<Upload
media={media}
onDelete={handleDelete}
onDescriptionChange={handleDescriptionChange}
onSubmit={handleSubmit}
descriptionLimit={descriptionLimit}
withPreview
/>
2022-05-30 11:53:14 -07:00
);
};
export default UploadCompose;