mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-06-25 19:18:29 +07:00
removed almost all node sagas
This commit is contained in:
parent
f76a5a4798
commit
168ba8cc04
30 changed files with 268 additions and 448 deletions
|
@ -14,6 +14,7 @@ type IProps = HTMLAttributes<HTMLDivElement> & {
|
|||
group: ICommentGroup;
|
||||
isSame?: boolean;
|
||||
canEdit?: boolean;
|
||||
saveComment: (data: IComment) => Promise<unknown>;
|
||||
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
||||
onShowImageModal: (images: IFile[], index: number) => void;
|
||||
};
|
||||
|
@ -29,6 +30,7 @@ const Comment: FC<IProps> = memo(
|
|||
canEdit,
|
||||
onDelete,
|
||||
onShowImageModal,
|
||||
saveComment,
|
||||
...props
|
||||
}) => {
|
||||
return (
|
||||
|
@ -50,6 +52,7 @@ const Comment: FC<IProps> = memo(
|
|||
|
||||
return (
|
||||
<CommentContent
|
||||
saveComment={saveComment}
|
||||
nodeId={nodeId}
|
||||
comment={comment}
|
||||
key={comment.id}
|
||||
|
|
|
@ -18,12 +18,13 @@ interface IProps {
|
|||
nodeId: number;
|
||||
comment: IComment;
|
||||
canEdit: boolean;
|
||||
saveComment: (data: IComment) => Promise<unknown>;
|
||||
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
||||
onShowImageModal: (images: IFile[], index: number) => void;
|
||||
}
|
||||
|
||||
const CommentContent: FC<IProps> = memo(
|
||||
({ comment, canEdit, nodeId, onDelete, onShowImageModal }) => {
|
||||
({ comment, canEdit, nodeId, saveComment, onDelete, onShowImageModal }) => {
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
|
||||
const startEditing = useCallback(() => setIsEditing(true), [setIsEditing]);
|
||||
|
@ -58,7 +59,14 @@ const CommentContent: FC<IProps> = memo(
|
|||
);
|
||||
|
||||
if (isEditing) {
|
||||
return <CommentForm nodeId={nodeId} comment={comment} onCancelEdit={stopEditing} />;
|
||||
return (
|
||||
<CommentForm
|
||||
saveComment={saveComment}
|
||||
nodeId={nodeId}
|
||||
comment={comment}
|
||||
onCancelEdit={stopEditing}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -20,17 +20,24 @@ import { Filler } from '~/components/containers/Filler';
|
|||
interface IProps {
|
||||
comment?: IComment;
|
||||
nodeId: INode['id'];
|
||||
saveComment: (data: IComment) => Promise<unknown>;
|
||||
onCancelEdit?: () => void;
|
||||
}
|
||||
|
||||
const CommentForm: FC<IProps> = ({ comment, nodeId, onCancelEdit }) => {
|
||||
const CommentForm: FC<IProps> = ({ comment, nodeId, saveComment, onCancelEdit }) => {
|
||||
const [textarea, setTextarea] = useState<HTMLTextAreaElement>();
|
||||
const uploader = useFileUploader(
|
||||
UPLOAD_SUBJECTS.COMMENT,
|
||||
UPLOAD_TARGETS.COMMENTS,
|
||||
comment?.files
|
||||
);
|
||||
const formik = useCommentFormFormik(comment || EMPTY_COMMENT, nodeId, uploader, onCancelEdit);
|
||||
const formik = useCommentFormFormik(
|
||||
comment || EMPTY_COMMENT,
|
||||
nodeId,
|
||||
uploader,
|
||||
saveComment,
|
||||
onCancelEdit
|
||||
);
|
||||
const isLoading = formik.isSubmitting || uploader.isUploading;
|
||||
const isEditing = !!comment?.id;
|
||||
|
||||
|
|
|
@ -1,27 +1,21 @@
|
|||
import React, { FC } from 'react';
|
||||
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
||||
import { connect } from 'react-redux';
|
||||
import { selectAuthUser } from '~/redux/auth/selectors';
|
||||
import { CommentForm } from '~/components/comment/CommentForm';
|
||||
import { INode } from '~/redux/types';
|
||||
import { IComment } from '~/redux/types';
|
||||
import { IUser } from '~/redux/auth/types';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
user: selectAuthUser(state),
|
||||
});
|
||||
interface NodeCommentFormProps {
|
||||
user: IUser;
|
||||
nodeId?: number;
|
||||
saveComment: (comment: IComment) => Promise<unknown>;
|
||||
}
|
||||
|
||||
type IProps = ReturnType<typeof mapStateToProps> & {
|
||||
isBefore?: boolean;
|
||||
nodeId: INode['id'];
|
||||
};
|
||||
|
||||
const NodeCommentFormUnconnected: FC<IProps> = ({ user, isBefore, nodeId }) => {
|
||||
const NodeCommentForm: FC<NodeCommentFormProps> = ({ user, nodeId, saveComment }) => {
|
||||
return (
|
||||
<CommentWrapper user={user} isForm>
|
||||
<CommentForm nodeId={nodeId} />
|
||||
<CommentForm nodeId={nodeId} saveComment={saveComment} />
|
||||
</CommentWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
const NodeCommentForm = connect(mapStateToProps)(NodeCommentFormUnconnected);
|
||||
|
||||
export { NodeCommentForm };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue