mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-28 14:16:41 +07:00
fixed unsupported files uploading
This commit is contained in:
parent
9db25afb28
commit
63b9781977
2 changed files with 11 additions and 12 deletions
|
@ -1,18 +1,22 @@
|
|||
import React, { FC, useCallback } from 'react';
|
||||
import { ButtonGroup } from '~/components/input/ButtonGroup';
|
||||
import { Button } from '~/components/input/Button';
|
||||
import { FILE_MIMES, UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
|
||||
interface IProps {
|
||||
onUpload: (files: File[]) => void;
|
||||
}
|
||||
|
||||
const CommentFormButtons: FC<IProps> = ({ onUpload }) => {
|
||||
const ALLOWED_TYPES = [...FILE_MIMES[UPLOAD_TYPES.IMAGE], ...FILE_MIMES[UPLOAD_TYPES.AUDIO]];
|
||||
|
||||
const CommentFormAttachButtons: FC<IProps> = ({ onUpload }) => {
|
||||
const onInputChange = useCallback(
|
||||
event => {
|
||||
event.preventDefault();
|
||||
|
||||
const files: File[] = Array.from(event.target?.files);
|
||||
|
||||
const files = Array.from(event.target?.files as File[]).filter((file: File) =>
|
||||
ALLOWED_TYPES.includes(file.type)
|
||||
);
|
||||
if (!files || !files.length) return;
|
||||
|
||||
onUpload(files);
|
||||
|
@ -33,4 +37,4 @@ const CommentFormButtons: FC<IProps> = ({ onUpload }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export { CommentFormButtons };
|
||||
export { CommentFormAttachButtons };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue