1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +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

@ -12,52 +12,18 @@ import { NodeBottomBlock } from '~/components/node/NodeBottomBlock';
import { useNodeCoverImage } from '~/utils/hooks/node/useNodeCoverImage';
import { URLS } from '~/constants/urls';
import { EditorEditDialog } from '~/containers/dialogs/EditorEditDialog';
import { useNodePermissions } from '~/utils/hooks/node/useNodePermissions';
import { IComment, IFile, INode, ITag } from '~/redux/types';
import { INodeRelated } from '~/redux/node/types';
import styles from './styles.module.scss';
import { IUser } from '~/redux/auth/types';
import { useNodeContext } from '~/utils/providers/NodeProvider';
type IProps = {
node: INode;
user: IUser;
lastSeenCurrent?: string;
related: INodeRelated;
comments: IComment[];
commentsCount: number;
isUser: boolean;
isLoading: boolean;
isLoadingComments: boolean;
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;
};
type IProps = {};
const NodeLayout: FC<IProps> = () => {
const { node, isUser, isLoading } = useNodeContext();
const NodeLayout: FC<IProps> = ({
node,
user,
comments,
commentsCount,
related,
lastSeenCurrent,
isUser,
isLoading,
isLoadingComments,
onLoadMoreComments,
onDeleteComment,
onShowImageModal,
onTagsChange,
onTagClick,
onTagDelete,
}) => {
useNodeCoverImage(node);
const { head, block } = useNodeBlocks(node, isLoading);
const [canEdit] = useNodePermissions(node);
return (
<div className={styles.wrap}>
@ -71,25 +37,7 @@ const NodeLayout: FC<IProps> = ({
<NodePanel node={node} isLoading={isLoading} />
</div>
<NodeBottomBlock
isUser={isUser}
user={user}
node={node}
canEdit={canEdit}
comments={comments}
commentsCount={commentsCount}
commentsOrder="DESC"
related={related}
isLoadingComments={isLoadingComments}
isLoading={isLoading}
lastSeenCurrent={lastSeenCurrent}
onShowImageModal={onShowImageModal}
onLoadMoreComments={onLoadMoreComments}
onDeleteComment={onDeleteComment}
onTagsChange={onTagsChange}
onTagClick={onTagClick}
onTagDelete={onTagDelete}
/>
<NodeBottomBlock isUser={isUser} commentsOrder="DESC" />
<Footer />
</Card>