mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed unsupported files uploading
This commit is contained in:
parent
9db25afb28
commit
63b9781977
2 changed files with 11 additions and 12 deletions
|
@ -4,7 +4,7 @@ import styles from './styles.module.scss';
|
|||
import { Filler } from '~/components/containers/Filler';
|
||||
import { Button } from '~/components/input/Button';
|
||||
import assocPath from 'ramda/es/assocPath';
|
||||
import { IComment, IFile, IFileWithUUID, InputHandler } from '~/redux/types';
|
||||
import { IComment, IFileWithUUID, InputHandler } from '~/redux/types';
|
||||
import { connect } from 'react-redux';
|
||||
import * as NODE_ACTIONS from '~/redux/node/actions';
|
||||
import { selectNode } from '~/redux/node/selectors';
|
||||
|
@ -16,15 +16,10 @@ import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
|||
import { selectUploads } from '~/redux/uploads/selectors';
|
||||
import { IState } from '~/redux/store';
|
||||
import { getFileType } from '~/utils/uploader';
|
||||
import { ButtonGroup } from '~/components/input/ButtonGroup';
|
||||
import { SortableImageGrid } from '~/components/editors/SortableImageGrid';
|
||||
import { moveArrItem } from '~/utils/fn';
|
||||
import { SortEnd } from 'react-sortable-hoc';
|
||||
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
|
||||
import { getRandomPhrase } from '~/constants/phrases';
|
||||
import { ERROR_LITERAL } from '~/constants/errors';
|
||||
import { CommentFormAttaches } from '~/components/comment/CommentFormAttaches';
|
||||
import { CommentFormButtons } from '~/components/comment/CommentFormButtons';
|
||||
import { CommentFormAttachButtons } from '~/components/comment/CommentFormButtons';
|
||||
|
||||
const mapStateToProps = (state: IState) => ({
|
||||
node: selectNode(state),
|
||||
|
@ -205,7 +200,7 @@ const CommentFormUnconnected: FC<IProps> = memo(
|
|||
/>
|
||||
|
||||
<Group horizontal className={styles.buttons}>
|
||||
<CommentFormButtons onUpload={onUpload} />
|
||||
<CommentFormAttachButtons onUpload={onUpload} />
|
||||
|
||||
<Filler />
|
||||
|
||||
|
|
|
@ -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