mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
add comments for guests
This commit is contained in:
parent
cbf7b1f616
commit
8abf6177b5
16 changed files with 278 additions and 194 deletions
47
src/containers/node/NodeCommentForm/index.tsx
Normal file
47
src/containers/node/NodeCommentForm/index.tsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { FC, useCallback } from 'react';
|
||||
|
||||
import { CommentForm } from '~/components/comment/CommentForm';
|
||||
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
||||
import { UploadDropzone } from '~/components/upload/UploadDropzone';
|
||||
import { EMPTY_USER } from '~/constants/auth';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
import { UploadSubject, UploadTarget } from '~/constants/uploads';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
import { useUploader } from '~/hooks/data/useUploader';
|
||||
import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||
import { IComment } from '~/types';
|
||||
import { UploaderContextProvider } from '~/utils/context/UploaderContextProvider';
|
||||
|
||||
export interface Props {
|
||||
saveComment: (comment: IComment) => Promise<IComment | undefined>;
|
||||
}
|
||||
|
||||
const NodeCommentForm: FC<Props> = ({ saveComment }) => {
|
||||
const { user, isUser } = useAuth();
|
||||
const showLoginDialog = useShowModal(Dialog.Login);
|
||||
|
||||
const uploader = useUploader(UploadSubject.Comment, UploadTarget.Comments);
|
||||
const onCommentSave = useCallback(
|
||||
async (comment: IComment) => {
|
||||
if (!isUser) {
|
||||
showLoginDialog({});
|
||||
return;
|
||||
}
|
||||
|
||||
return saveComment(comment);
|
||||
},
|
||||
[isUser, showLoginDialog, saveComment],
|
||||
);
|
||||
|
||||
return (
|
||||
<UploadDropzone onUpload={uploader.uploadFiles}>
|
||||
<UploaderContextProvider value={uploader}>
|
||||
<CommentWrapper user={isUser ? user : undefined} isForm>
|
||||
<CommentForm saveComment={onCommentSave} allowUploads={isUser} />
|
||||
</CommentWrapper>
|
||||
</UploaderContextProvider>
|
||||
</UploadDropzone>
|
||||
);
|
||||
};
|
||||
|
||||
export { NodeCommentForm };
|
Loading…
Add table
Add a link
Reference in a new issue