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

made node use context providers

This commit is contained in:
Fedor Katurov 2021-11-19 16:18:51 +07:00
parent 15095b3116
commit f631f79654
8 changed files with 189 additions and 180 deletions

View file

@ -6,53 +6,19 @@ import { NodeCommentsBlock } from '~/components/node/NodeCommentsBlock';
import { NodeCommentForm } from '~/components/node/NodeCommentForm';
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
import { IComment, IFile, INode, ITag } from '~/redux/types';
import { NodeTagsBlock } from '~/components/node/NodeTagsBlock';
import { INodeRelated } from '~/redux/node/types';
import StickyBox from 'react-sticky-box/dist/esnext';
import styles from './styles.module.scss';
import { NodeAuthorBlock } from '~/components/node/NodeAuthorBlock';
import { IUser } from '~/redux/auth/types';
import { useNodeContext } from '~/utils/providers/NodeProvider';
interface IProps {
node: INode;
user: IUser;
isUser: boolean;
canEdit: boolean;
isLoading: boolean;
commentsOrder: 'ASC' | 'DESC';
comments: IComment[];
commentsCount: number;
isLoadingComments: boolean;
related: INodeRelated;
lastSeenCurrent?: string;
onShowImageModal: (images: IFile[], index: number) => void;
onLoadMoreComments: () => void;
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
onTagsChange: (tags: string[]) => void;
onTagClick: (tag: Partial<ITag>) => void;
onTagDelete: (id: ITag['ID']) => void;
}
const NodeBottomBlock: FC<IProps> = ({
node,
user,
canEdit,
isLoading,
isUser,
isLoadingComments,
comments,
commentsCount,
commentsOrder,
related,
lastSeenCurrent,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
onTagsChange,
onTagClick,
onTagDelete,
}) => {
const NodeBottomBlock: FC<IProps> = ({ commentsOrder }) => {
const { node, related, isUser, isLoading } = useNodeContext();
const { inline } = useNodeBlocks(node, isLoading);
if (node.deleted_at) {
@ -66,19 +32,7 @@ const NodeBottomBlock: FC<IProps> = ({
<Group className={styles.comments}>
{inline && <div className={styles.inline}>{inline}</div>}
<NodeCommentsBlock
lastSeenCurrent={lastSeenCurrent}
isLoading={isLoading}
isLoadingComments={isLoadingComments}
comments={comments}
count={commentsCount}
order={commentsOrder}
user={user}
node={node}
onShowImageModal={onShowImageModal}
onLoadMoreComments={onLoadMoreComments}
onDeleteComment={onDeleteComment}
/>
<NodeCommentsBlock order={commentsOrder} />
{isUser && !isLoading && <NodeCommentForm nodeId={node.id} />}
</Group>
@ -89,16 +43,9 @@ const NodeBottomBlock: FC<IProps> = ({
<div className={styles.left_item}>
<NodeAuthorBlock user={node?.user} />
</div>
<div className={styles.left_item}>
<NodeTagsBlock
tags={node.tags}
canDelete={canEdit}
canAppend={isUser}
isLoading={isLoading}
onChange={onTagsChange}
onTagClick={onTagClick}
onTagDelete={onTagDelete}
/>
<NodeTagsBlock />
</div>
<div className={styles.left_item}>
<NodeRelatedBlock isLoading={isLoading} node={node} related={related} />

View file

@ -1,40 +1,30 @@
import React, { FC } from 'react';
import { NodeNoComments } from '~/components/node/NodeNoComments';
import { NodeComments } from '~/components/node/NodeComments';
import { IComment, IFile, INode } from '~/redux/types';
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
import { IUser } from '~/redux/auth/types';
import { useCommentContext } from '~/utils/providers/CommentProvider';
interface IProps {
order: 'ASC' | 'DESC';
node: INode;
user: IUser;
comments: IComment[];
count: number;
lastSeenCurrent?: string;
isLoading: boolean;
isLoadingComments: boolean;
onShowImageModal: (images: IFile[], index: number) => void;
onLoadMoreComments: () => void;
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
}
const NodeCommentsBlock: FC<IProps> = ({
node,
user,
comments,
count,
lastSeenCurrent,
isLoading,
isLoadingComments,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
}) => {
const { inline } = useNodeBlocks(node, isLoading);
const NodeCommentsBlock: FC<IProps> = () => {
const {
node,
user,
comments,
count,
lastSeenCurrent,
isLoadingNode,
isLoadingComments,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
} = useCommentContext();
const { inline } = useNodeBlocks(node, isLoadingNode);
return isLoading || isLoadingComments || (!comments.length && !inline) ? (
<NodeNoComments is_loading={isLoadingComments || isLoading} />
return isLoadingNode || isLoadingComments || (!comments.length && !inline) ? (
<NodeNoComments is_loading={isLoadingComments || isLoadingNode} />
) : (
<NodeComments
count={count}

View file

@ -1,26 +1,20 @@
import React, { FC } from 'react';
import { ITag } from '~/redux/types';
import { NodeTags } from '~/components/node/NodeTags';
import { useTagContext } from '~/utils/providers/TagProvider';
interface IProps {
tags: ITag[];
canAppend: boolean;
canDelete: boolean;
isLoading: boolean;
onChange: (tags: string[]) => void;
onTagClick: (tag: Partial<ITag>) => void;
onTagDelete: (id: ITag['ID']) => void;
}
interface IProps {}
const NodeTagsBlock: FC<IProps> = ({}) => {
const {
tags,
canAppend,
canDelete,
isLoading,
onChange,
onTagClick,
onTagDelete,
} = useTagContext();
const NodeTagsBlock: FC<IProps> = ({
tags,
canAppend,
canDelete,
isLoading,
onChange,
onTagClick,
onTagDelete,
}) => {
if (isLoading) {
return null;
}