1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fix file uploads on comments

This commit is contained in:
Fedor Katurov 2023-10-30 17:23:30 +06:00
parent 8abf6177b5
commit 8e40cf9885
3 changed files with 35 additions and 26 deletions

View file

@ -1,5 +1,7 @@
import { FC } from 'react'; import { FC } from 'react';
import { observer } from 'mobx-react-lite';
import { CommentForm } from '~/components/comment/CommentForm'; import { CommentForm } from '~/components/comment/CommentForm';
import { UploadDropzone } from '~/components/upload/UploadDropzone'; import { UploadDropzone } from '~/components/upload/UploadDropzone';
import { UploadSubject, UploadTarget } from '~/constants/uploads'; import { UploadSubject, UploadTarget } from '~/constants/uploads';
@ -14,11 +16,8 @@ interface CommentEditingFormProps {
onCancelEdit?: () => void; onCancelEdit?: () => void;
} }
const CommentEditingForm: FC<CommentEditingFormProps> = ({ const CommentEditingForm: FC<CommentEditingFormProps> = observer(
saveComment, ({ saveComment, comment, onCancelEdit }) => {
comment,
onCancelEdit,
}) => {
const uploader = useUploader(UploadSubject.Comment, UploadTarget.Comments); const uploader = useUploader(UploadSubject.Comment, UploadTarget.Comments);
return ( return (
@ -33,6 +32,7 @@ const CommentEditingForm: FC<CommentEditingFormProps> = ({
</UploaderContextProvider> </UploaderContextProvider>
</UploadDropzone> </UploadDropzone>
); );
}; },
);
export { CommentEditingForm }; export { CommentEditingForm };

View file

@ -4,7 +4,6 @@ import classnames from 'classnames';
import classNames from 'classnames'; import classNames from 'classnames';
import Dropzone from 'react-dropzone'; import Dropzone from 'react-dropzone';
import { DropHereIcon } from '~/components/input/DropHereIcon'; import { DropHereIcon } from '~/components/input/DropHereIcon';
import { useDragDetector } from '~/hooks/dom/useDragDetector'; import { useDragDetector } from '~/hooks/dom/useDragDetector';
import { DivProps } from '~/utils/types'; import { DivProps } from '~/utils/types';
@ -16,26 +15,34 @@ interface IProps extends DivProps {
helperClassName?: string; helperClassName?: string;
} }
const UploadDropzone: FC<IProps> = ({ children, onUpload, helperClassName, ...rest }) => { const UploadDropzone: FC<IProps> = ({
children,
onUpload,
helperClassName,
...rest
}) => {
const { isDragging: isDraggingOnBody, onStopDragging } = useDragDetector(); const { isDragging: isDraggingOnBody, onStopDragging } = useDragDetector();
const onDrop = useCallback( const onDrop = useCallback(
(files: File[]) => { (files: File[]) => {
onStopDragging(); onStopDragging();
onUpload(files); onUpload(files);
}, },
[onStopDragging, onUpload] [onStopDragging, onUpload],
); );
return ( return (
<Dropzone onDrop={onDrop}> <Dropzone onDrop={onDrop} noClick>
{({ getRootProps, isDragActive }) => ( {({ getRootProps, isDragActive, getInputProps }) => (
<div <div
{...getRootProps({ {...getRootProps({
...rest, ...rest,
className: classnames(styles.zone), className: classnames(styles.zone),
})} })}
> >
<input {...getInputProps()} />
{children} {children}
<div <div
className={classNames(styles.helper, helperClassName, { className={classNames(styles.helper, helperClassName, {
[styles.active]: isDragActive || isDraggingOnBody, [styles.active]: isDragActive || isDraggingOnBody,

View file

@ -1,5 +1,7 @@
import { FC, useCallback } from 'react'; import { FC, useCallback } from 'react';
import { observer } from 'mobx-react-lite';
import { CommentForm } from '~/components/comment/CommentForm'; import { CommentForm } from '~/components/comment/CommentForm';
import { CommentWrapper } from '~/components/containers/CommentWrapper'; import { CommentWrapper } from '~/components/containers/CommentWrapper';
import { UploadDropzone } from '~/components/upload/UploadDropzone'; import { UploadDropzone } from '~/components/upload/UploadDropzone';
@ -16,7 +18,7 @@ export interface Props {
saveComment: (comment: IComment) => Promise<IComment | undefined>; saveComment: (comment: IComment) => Promise<IComment | undefined>;
} }
const NodeCommentForm: FC<Props> = ({ saveComment }) => { const NodeCommentForm: FC<Props> = observer(({ saveComment }) => {
const { user, isUser } = useAuth(); const { user, isUser } = useAuth();
const showLoginDialog = useShowModal(Dialog.Login); const showLoginDialog = useShowModal(Dialog.Login);
@ -42,6 +44,6 @@ const NodeCommentForm: FC<Props> = ({ saveComment }) => {
</UploaderContextProvider> </UploaderContextProvider>
</UploadDropzone> </UploadDropzone>
); );
}; });
export { NodeCommentForm }; export { NodeCommentForm };