Add uploadFile function, allow uploading images in Lexical

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2023-07-21 20:24:28 +02:00
parent f55a76886f
commit 79200cae0f
6 changed files with 535 additions and 213 deletions

View File

@ -23,7 +23,7 @@ import * as React from 'react';
import { createPortal } from 'react-dom';
import { useIntl } from 'react-intl';
import { uploadFiles } from 'soapbox/actions/compose';
import { uploadFile } from 'soapbox/actions/compose';
import { useAppDispatch, useInstance } from 'soapbox/hooks';
import { onlyImages } from '../../components/upload-button';
@ -49,7 +49,11 @@ const UploadButton: React.FC<IUploadButton> = ({ onSelectFile }) => {
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
if (e.target.files?.length) {
// @ts-ignore
dispatch(uploadFiles([e.target.files.item(0)] as any, intl));
dispatch(uploadFile(
e.target.files.item(0) as File,
intl,
({ url }) => onSelectFile(url),
));
}
};