mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
refactored node comments to component
This commit is contained in:
parent
b44266437d
commit
ab15a10d01
13 changed files with 208 additions and 111 deletions
|
@ -5,21 +5,30 @@ import { NodeCommentForm } from '~/components/node/NodeCommentForm';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeComments } from '~/components/node/NodeComments';
|
import { NodeComments } from '~/components/node/NodeComments';
|
||||||
import { Footer } from '~/components/main/Footer';
|
import { Footer } from '~/components/main/Footer';
|
||||||
import { Card } from '~/components/containers/Card';
|
import { IComment, IFile, INode } from '~/redux/types';
|
||||||
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
|
import { IUser } from '~/redux/auth/types';
|
||||||
import { selectAuthUser } from '~/redux/auth/selectors';
|
|
||||||
import { IComment, INode } from '~/redux/types';
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
isLoadingComments: boolean;
|
|
||||||
commentCount: number;
|
|
||||||
node: INode;
|
node: INode;
|
||||||
|
user: IUser;
|
||||||
|
commentCount: number;
|
||||||
comments: IComment[];
|
comments: IComment[];
|
||||||
|
isLoadingComments: boolean;
|
||||||
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
|
onLoadMoreComments: () => void;
|
||||||
|
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BorisComments: FC<IProps> = ({ isLoadingComments, node, commentCount, comments }) => {
|
const BorisComments: FC<IProps> = ({
|
||||||
const user = useShallowSelect(selectAuthUser);
|
node,
|
||||||
|
user,
|
||||||
|
isLoadingComments,
|
||||||
|
commentCount,
|
||||||
|
comments,
|
||||||
|
onLoadMoreComments,
|
||||||
|
onDeleteComment,
|
||||||
|
onShowImageModal,
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Group className={styles.grid}>
|
<Group className={styles.grid}>
|
||||||
|
@ -28,7 +37,15 @@ const BorisComments: FC<IProps> = ({ isLoadingComments, node, commentCount, comm
|
||||||
{isLoadingComments ? (
|
{isLoadingComments ? (
|
||||||
<NodeNoComments is_loading count={7} />
|
<NodeNoComments is_loading count={7} />
|
||||||
) : (
|
) : (
|
||||||
<NodeComments comments={comments} count={commentCount} user={user} order="ASC" />
|
<NodeComments
|
||||||
|
comments={comments}
|
||||||
|
count={commentCount}
|
||||||
|
user={user}
|
||||||
|
order="ASC"
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import React, { FC, HTMLAttributes, memo } from 'react';
|
import React, { FC, HTMLAttributes, memo } from 'react';
|
||||||
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
import { CommentWrapper } from '~/components/containers/CommentWrapper';
|
||||||
import { IComment, ICommentGroup } from '~/redux/types';
|
import { IComment, ICommentGroup, IFile } from '~/redux/types';
|
||||||
import { CommentContent } from '~/components/comment/CommentContent';
|
import { CommentContent } from '~/components/comment/CommentContent';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { CommendDeleted } from '../../node/CommendDeleted';
|
import { CommendDeleted } from '../../node/CommendDeleted';
|
||||||
import * as MODAL_ACTIONS from '~/redux/modal/actions';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { NEW_COMMENT_CLASSNAME } from '~/constants/comment';
|
import { NEW_COMMENT_CLASSNAME } from '~/constants/comment';
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ type IProps = HTMLAttributes<HTMLDivElement> & {
|
||||||
isSame?: boolean;
|
isSame?: boolean;
|
||||||
canEdit?: boolean;
|
canEdit?: boolean;
|
||||||
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
modalShowPhotoswipe: typeof MODAL_ACTIONS.modalShowPhotoswipe;
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Comment: FC<IProps> = memo(
|
const Comment: FC<IProps> = memo(
|
||||||
|
@ -27,7 +26,7 @@ const Comment: FC<IProps> = memo(
|
||||||
className,
|
className,
|
||||||
canEdit,
|
canEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
modalShowPhotoswipe,
|
onShowImageModal,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
|
@ -53,7 +52,7 @@ const Comment: FC<IProps> = memo(
|
||||||
key={comment.id}
|
key={comment.id}
|
||||||
can_edit={!!canEdit}
|
can_edit={!!canEdit}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
modalShowPhotoswipe={modalShowPhotoswipe}
|
onShowImageModal={onShowImageModal}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -8,23 +8,22 @@ import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||||
import reduce from 'ramda/es/reduce';
|
import reduce from 'ramda/es/reduce';
|
||||||
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
import classNames from 'classnames';
|
||||||
import { PRESETS } from '~/constants/urls';
|
import { PRESETS } from '~/constants/urls';
|
||||||
import { COMMENT_BLOCK_RENDERERS } from '~/constants/comment';
|
import { COMMENT_BLOCK_RENDERERS } from '~/constants/comment';
|
||||||
import { CommentMenu } from '../CommentMenu';
|
import { CommentMenu } from '../CommentMenu';
|
||||||
import * as MODAL_ACTIONS from '~/redux/modal/actions';
|
|
||||||
import { CommentForm } from '~/components/comment/CommentForm';
|
import { CommentForm } from '~/components/comment/CommentForm';
|
||||||
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
|
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
|
||||||
import { selectNode } from '~/redux/node/selectors';
|
import { selectNode } from '~/redux/node/selectors';
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
comment: IComment;
|
comment: IComment;
|
||||||
can_edit: boolean;
|
can_edit: boolean;
|
||||||
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
onDelete: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
modalShowPhotoswipe: typeof MODAL_ACTIONS.modalShowPhotoswipe;
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentContent: FC<IProps> = memo(({ comment, can_edit, onDelete, modalShowPhotoswipe }) => {
|
const CommentContent: FC<IProps> = memo(({ comment, can_edit, onDelete, onShowImageModal }) => {
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const { current } = useShallowSelect(selectNode);
|
const { current } = useShallowSelect(selectNode);
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ const CommentContent: FC<IProps> = memo(({ comment, can_edit, onDelete, modalSho
|
||||||
className={classNames(styles.images, { [styles.multiple]: groupped.image.length > 1 })}
|
className={classNames(styles.images, { [styles.multiple]: groupped.image.length > 1 })}
|
||||||
>
|
>
|
||||||
{groupped.image.map((file, index) => (
|
{groupped.image.map((file, index) => (
|
||||||
<div key={file.id} onClick={() => modalShowPhotoswipe(groupped.image, index)}>
|
<div key={file.id} onClick={() => onShowImageModal(groupped.image, index)}>
|
||||||
<img src={getURL(file, PRESETS['600'])} alt={file.name} />
|
<img src={getURL(file, PRESETS['600'])} alt={file.name} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,26 +1,24 @@
|
||||||
import React, { FC, useCallback } from 'react';
|
import React, { FC, useCallback } from 'react';
|
||||||
import { INode } from '~/redux/types';
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { Avatar } from '~/components/common/Avatar';
|
import { Avatar } from '~/components/common/Avatar';
|
||||||
import { openUserProfile } from '~/utils/user';
|
import { openUserProfile } from '~/utils/user';
|
||||||
import { useUserDescription } from '~/utils/hooks/user/useUserDescription';
|
import { useUserDescription } from '~/utils/hooks/user/useUserDescription';
|
||||||
|
import { INodeUser } from '~/redux/types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
node?: INode;
|
user?: INodeUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeAuthorBlock: FC<Props> = ({ node }) => {
|
const NodeAuthorBlock: FC<Props> = ({ user }) => {
|
||||||
const onOpenProfile = useCallback(() => openUserProfile(node?.user?.username), [
|
const onOpenProfile = useCallback(() => openUserProfile(user?.username), [user?.username]);
|
||||||
node?.user?.username,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const description = useUserDescription(node?.user);
|
const description = useUserDescription(user);
|
||||||
|
|
||||||
if (!node?.user) {
|
if (!user) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { fullname, username, photo } = node.user;
|
const { fullname, username, photo } = user;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.block} onClick={onOpenProfile}>
|
<div className={styles.block} onClick={onOpenProfile}>
|
||||||
|
|
|
@ -6,16 +6,18 @@ import { NodeCommentsBlock } from '~/components/node/NodeCommentsBlock';
|
||||||
import { NodeCommentForm } from '~/components/node/NodeCommentForm';
|
import { NodeCommentForm } from '~/components/node/NodeCommentForm';
|
||||||
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
import { NodeRelatedBlock } from '~/components/node/NodeRelatedBlock';
|
||||||
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
|
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
|
||||||
import { IComment, INode } from '~/redux/types';
|
import { IComment, IFile, INode } from '~/redux/types';
|
||||||
import { useUser } from '~/utils/hooks/user/userUser';
|
|
||||||
import { NodeTagsBlock } from '~/components/node/NodeTagsBlock';
|
import { NodeTagsBlock } from '~/components/node/NodeTagsBlock';
|
||||||
import { INodeRelated } from '~/redux/node/types';
|
import { INodeRelated } from '~/redux/node/types';
|
||||||
import StickyBox from 'react-sticky-box/dist/esnext';
|
import StickyBox from 'react-sticky-box/dist/esnext';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { NodeAuthorBlock } from '~/components/node/NodeAuthorBlock';
|
import { NodeAuthorBlock } from '~/components/node/NodeAuthorBlock';
|
||||||
|
import { IUser } from '~/redux/auth/types';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
node: INode;
|
node: INode;
|
||||||
|
user: IUser;
|
||||||
|
isUser: boolean;
|
||||||
canEdit: boolean;
|
canEdit: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
commentsOrder: 'ASC' | 'DESC';
|
commentsOrder: 'ASC' | 'DESC';
|
||||||
|
@ -24,21 +26,28 @@ interface IProps {
|
||||||
isLoadingComments: boolean;
|
isLoadingComments: boolean;
|
||||||
related: INodeRelated;
|
related: INodeRelated;
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string;
|
||||||
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
|
onLoadMoreComments: () => void;
|
||||||
|
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeBottomBlock: FC<IProps> = ({
|
const NodeBottomBlock: FC<IProps> = ({
|
||||||
node,
|
node,
|
||||||
|
user,
|
||||||
canEdit,
|
canEdit,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
isUser,
|
||||||
isLoadingComments,
|
isLoadingComments,
|
||||||
comments,
|
comments,
|
||||||
commentsCount,
|
commentsCount,
|
||||||
commentsOrder,
|
commentsOrder,
|
||||||
related,
|
related,
|
||||||
lastSeenCurrent,
|
lastSeenCurrent,
|
||||||
|
onLoadMoreComments,
|
||||||
|
onDeleteComment,
|
||||||
|
onShowImageModal,
|
||||||
}) => {
|
}) => {
|
||||||
const { inline } = useNodeBlocks(node, isLoading);
|
const { inline } = useNodeBlocks(node, isLoading);
|
||||||
const { is_user } = useUser();
|
|
||||||
|
|
||||||
if (node.deleted_at) {
|
if (node.deleted_at) {
|
||||||
return <NodeDeletedBadge />;
|
return <NodeDeletedBadge />;
|
||||||
|
@ -58,17 +67,21 @@ const NodeBottomBlock: FC<IProps> = ({
|
||||||
comments={comments}
|
comments={comments}
|
||||||
count={commentsCount}
|
count={commentsCount}
|
||||||
order={commentsOrder}
|
order={commentsOrder}
|
||||||
|
user={user}
|
||||||
node={node}
|
node={node}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{is_user && !isLoading && <NodeCommentForm nodeId={node.id} />}
|
{isUser && !isLoading && <NodeCommentForm nodeId={node.id} />}
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<div className={styles.panel}>
|
<div className={styles.panel}>
|
||||||
<StickyBox className={styles.sticky} offsetTop={72}>
|
<StickyBox className={styles.sticky} offsetTop={72}>
|
||||||
<div className={styles.left}>
|
<div className={styles.left}>
|
||||||
<div className={styles.left_item}>
|
<div className={styles.left_item}>
|
||||||
<NodeAuthorBlock node={node} />
|
<NodeAuthorBlock user={node?.user} />
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.left_item}>
|
<div className={styles.left_item}>
|
||||||
<NodeTagsBlock node={node} canEdit={canEdit} isLoading={isLoading} />
|
<NodeTagsBlock node={node} canEdit={canEdit} isLoading={isLoading} />
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
import React, { FC, memo, useCallback, useMemo } from 'react';
|
import React, { FC, memo, useMemo } from 'react';
|
||||||
import { Comment } from '../../comment/Comment';
|
import { Comment } from '../../comment/Comment';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { IComment, ICommentGroup, IFile } from '~/redux/types';
|
import { IComment, ICommentGroup, IFile } from '~/redux/types';
|
||||||
import { groupCommentsByUser } from '~/utils/fn';
|
|
||||||
import { IUser } from '~/redux/auth/types';
|
import { IUser } from '~/redux/auth/types';
|
||||||
import { canEditComment } from '~/utils/node';
|
import { canEditComment } from '~/utils/node';
|
||||||
import { nodeLoadMoreComments, nodeLockComment } from '~/redux/node/actions';
|
|
||||||
import { INodeState } from '~/redux/node/reducer';
|
import { INodeState } from '~/redux/node/reducer';
|
||||||
import { COMMENTS_DISPLAY } from '~/redux/node/constants';
|
import { COMMENTS_DISPLAY } from '~/redux/node/constants';
|
||||||
import { plural } from '~/utils/dom';
|
import { plural } from '~/utils/dom';
|
||||||
import { modalShowPhotoswipe } from '~/redux/modal/actions';
|
|
||||||
import { useDispatch } from 'react-redux';
|
|
||||||
import { useGrouppedComments } from '~/utils/hooks/node/useGrouppedComments';
|
import { useGrouppedComments } from '~/utils/hooks/node/useGrouppedComments';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
|
@ -20,25 +16,26 @@ interface IProps {
|
||||||
user: IUser;
|
user: IUser;
|
||||||
order?: 'ASC' | 'DESC';
|
order?: 'ASC' | 'DESC';
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string;
|
||||||
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
|
onLoadMoreComments: () => void;
|
||||||
|
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeComments: FC<IProps> = memo(
|
const NodeComments: FC<IProps> = memo(
|
||||||
({ comments, user, count = 0, order = 'DESC', lastSeenCurrent }) => {
|
({
|
||||||
const dispatch = useDispatch();
|
comments,
|
||||||
|
user,
|
||||||
|
count = 0,
|
||||||
|
order = 'DESC',
|
||||||
|
onLoadMoreComments,
|
||||||
|
onDeleteComment,
|
||||||
|
onShowImageModal,
|
||||||
|
lastSeenCurrent,
|
||||||
|
}) => {
|
||||||
const left = useMemo(() => Math.max(0, count - comments.length), [comments, count]);
|
const left = useMemo(() => Math.max(0, count - comments.length), [comments, count]);
|
||||||
|
|
||||||
const groupped: ICommentGroup[] = useGrouppedComments(comments, order, lastSeenCurrent);
|
const groupped: ICommentGroup[] = useGrouppedComments(comments, order, lastSeenCurrent);
|
||||||
|
|
||||||
const onDelete = useCallback(
|
|
||||||
(id: IComment['id'], locked: boolean) => dispatch(nodeLockComment(id, locked)),
|
|
||||||
[dispatch]
|
|
||||||
);
|
|
||||||
const onLoadMoreComments = useCallback(() => dispatch(nodeLoadMoreComments()), [dispatch]);
|
|
||||||
const onShowPhotoswipe = useCallback(
|
|
||||||
(images: IFile[], index: number) => dispatch(modalShowPhotoswipe(images, index)),
|
|
||||||
[dispatch]
|
|
||||||
);
|
|
||||||
|
|
||||||
const more = useMemo(
|
const more = useMemo(
|
||||||
() =>
|
() =>
|
||||||
left > 0 && (
|
left > 0 && (
|
||||||
|
@ -60,8 +57,8 @@ const NodeComments: FC<IProps> = memo(
|
||||||
key={group.ids.join()}
|
key={group.ids.join()}
|
||||||
group={group}
|
group={group}
|
||||||
canEdit={canEditComment(group, user)}
|
canEdit={canEditComment(group, user)}
|
||||||
onDelete={onDelete}
|
onDelete={onDeleteComment}
|
||||||
modalShowPhotoswipe={onShowPhotoswipe}
|
onShowImageModal={onShowImageModal}
|
||||||
isSame={group.user.id === user.id}
|
isSame={group.user.id === user.id}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -1,29 +1,36 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
import { NodeNoComments } from '~/components/node/NodeNoComments';
|
||||||
import { NodeComments } from '~/components/node/NodeComments';
|
import { NodeComments } from '~/components/node/NodeComments';
|
||||||
import { IComment, INode } from '~/redux/types';
|
import { IComment, IFile, INode } from '~/redux/types';
|
||||||
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
|
import { useNodeBlocks } from '~/utils/hooks/node/useNodeBlocks';
|
||||||
import { useUser } from '~/utils/hooks/user/userUser';
|
import { IUser } from '~/redux/auth/types';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
order: 'ASC' | 'DESC';
|
order: 'ASC' | 'DESC';
|
||||||
node: INode;
|
node: INode;
|
||||||
|
user: IUser;
|
||||||
comments: IComment[];
|
comments: IComment[];
|
||||||
count: number;
|
count: number;
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isLoadingComments: boolean;
|
isLoadingComments: boolean;
|
||||||
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
|
onLoadMoreComments: () => void;
|
||||||
|
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NodeCommentsBlock: FC<IProps> = ({
|
const NodeCommentsBlock: FC<IProps> = ({
|
||||||
isLoading,
|
|
||||||
isLoadingComments,
|
|
||||||
node,
|
node,
|
||||||
|
user,
|
||||||
comments,
|
comments,
|
||||||
count,
|
count,
|
||||||
lastSeenCurrent,
|
lastSeenCurrent,
|
||||||
|
isLoading,
|
||||||
|
isLoadingComments,
|
||||||
|
onLoadMoreComments,
|
||||||
|
onDeleteComment,
|
||||||
|
onShowImageModal,
|
||||||
}) => {
|
}) => {
|
||||||
const user = useUser();
|
|
||||||
const { inline } = useNodeBlocks(node, isLoading);
|
const { inline } = useNodeBlocks(node, isLoading);
|
||||||
|
|
||||||
return isLoading || isLoadingComments || (!comments.length && !inline) ? (
|
return isLoading || isLoadingComments || (!comments.length && !inline) ? (
|
||||||
|
@ -35,6 +42,9 @@ const NodeCommentsBlock: FC<IProps> = ({
|
||||||
user={user}
|
user={user}
|
||||||
order="DESC"
|
order="DESC"
|
||||||
lastSeenCurrent={lastSeenCurrent}
|
lastSeenCurrent={lastSeenCurrent}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import React, { FC, useCallback, useEffect } from 'react';
|
import React, { FC, useCallback, useEffect } from 'react';
|
||||||
import { selectNode, selectNodeComments } from '~/redux/node/selectors';
|
import { selectNode, selectNodeComments } from '~/redux/node/selectors';
|
||||||
import { selectAuthIsTester, selectUser } from '~/redux/auth/selectors';
|
import { selectAuthIsTester } from '~/redux/auth/selectors';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
import { Group } from '~/components/containers/Group';
|
import { Group } from '~/components/containers/Group';
|
||||||
import boris from '~/sprites/boris_robot.svg';
|
import boris from '~/sprites/boris_robot.svg';
|
||||||
import { useRandomPhrase } from '~/constants/phrases';
|
import { useRandomPhrase } from '~/constants/phrases';
|
||||||
import isBefore from 'date-fns/isBefore';
|
import isBefore from 'date-fns/isBefore';
|
||||||
import { BorisStats } from '~/components/boris/BorisStats';
|
|
||||||
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
|
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
|
||||||
import { selectBorisStats } from '~/redux/boris/selectors';
|
import { selectBorisStats } from '~/redux/boris/selectors';
|
||||||
import { authSetState, authSetUser } from '~/redux/auth/actions';
|
import { authSetState, authSetUser } from '~/redux/auth/actions';
|
||||||
|
@ -16,20 +15,12 @@ import { borisLoadStats } from '~/redux/boris/actions';
|
||||||
import { Container } from '~/containers/main/Container';
|
import { Container } from '~/containers/main/Container';
|
||||||
import StickyBox from 'react-sticky-box/dist/esnext';
|
import StickyBox from 'react-sticky-box/dist/esnext';
|
||||||
import { BorisComments } from '~/components/boris/BorisComments';
|
import { BorisComments } from '~/components/boris/BorisComments';
|
||||||
import { URLS } from '~/constants/urls';
|
|
||||||
import { Route, Switch } from 'react-router-dom';
|
|
||||||
import { BorisUIDemo } from '~/components/boris/BorisUIDemo';
|
|
||||||
import { BorisSuperpowers } from '~/components/boris/BorisSuperpowers';
|
|
||||||
import { Superpower } from '~/components/boris/Superpower';
|
|
||||||
import { Tabs } from '~/components/dialogs/Tabs';
|
|
||||||
import { Tab } from '~/components/dialogs/Tab';
|
|
||||||
import { useHistory, useLocation } from 'react-router';
|
|
||||||
import { Card } from '~/components/containers/Card';
|
import { Card } from '~/components/containers/Card';
|
||||||
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
import { SidebarRouter } from '~/containers/main/SidebarRouter';
|
||||||
import { BorisContactItem } from '~/components/boris/BorisContactItem';
|
|
||||||
import { BorisContacts } from '~/components/boris/BorisContacts';
|
|
||||||
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
||||||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
import { useImageModal } from '~/utils/hooks/useImageModal';
|
||||||
|
import { useNodeComments } from '~/utils/hooks/node/useNodeComments';
|
||||||
|
import { useUser } from '~/utils/hooks/user/userUser';
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
|
|
||||||
|
@ -37,10 +28,10 @@ const BorisLayout: FC<IProps> = () => {
|
||||||
const title = useRandomPhrase('BORIS_TITLE');
|
const title = useRandomPhrase('BORIS_TITLE');
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const node = useShallowSelect(selectNode);
|
const node = useShallowSelect(selectNode);
|
||||||
const user = useShallowSelect(selectUser);
|
|
||||||
const stats = useShallowSelect(selectBorisStats);
|
const stats = useShallowSelect(selectBorisStats);
|
||||||
const comments = useShallowSelect(selectNodeComments);
|
const comments = useShallowSelect(selectNodeComments);
|
||||||
const isTester = useShallowSelect(selectAuthIsTester);
|
const isTester = useShallowSelect(selectAuthIsTester);
|
||||||
|
const user = useUser();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const last_comment = comments[0];
|
const last_comment = comments[0];
|
||||||
|
@ -73,6 +64,9 @@ const BorisLayout: FC<IProps> = () => {
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onShowImageModal = useImageModal();
|
||||||
|
const { onLoadMoreComments, onDelete: onDeleteComment } = useNodeComments('696');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
|
@ -89,10 +83,14 @@ const BorisLayout: FC<IProps> = () => {
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<Card className={styles.content}>
|
<Card className={styles.content}>
|
||||||
<BorisComments
|
<BorisComments
|
||||||
isLoadingComments={node.is_loading_comments}
|
|
||||||
commentCount={node.comment_count}
|
|
||||||
node={node.current}
|
node={node.current}
|
||||||
|
user={user}
|
||||||
comments={node.comments}
|
comments={node.comments}
|
||||||
|
commentCount={node.comment_count}
|
||||||
|
isLoadingComments={node.is_loading_comments}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { FC, memo } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { Route } from 'react-router';
|
import { Route } from 'react-router';
|
||||||
import { Card } from '~/components/containers/Card';
|
import { Card } from '~/components/containers/Card';
|
||||||
|
|
||||||
|
@ -13,62 +13,84 @@ import { useNodeCoverImage } from '~/utils/hooks/node/useNodeCoverImage';
|
||||||
import { URLS } from '~/constants/urls';
|
import { URLS } from '~/constants/urls';
|
||||||
import { EditorEditDialog } from '~/containers/dialogs/EditorEditDialog';
|
import { EditorEditDialog } from '~/containers/dialogs/EditorEditDialog';
|
||||||
import { useNodePermissions } from '~/utils/hooks/node/useNodePermissions';
|
import { useNodePermissions } from '~/utils/hooks/node/useNodePermissions';
|
||||||
import { IComment, INode } from '~/redux/types';
|
import { IComment, IFile, INode } from '~/redux/types';
|
||||||
import { INodeRelated } from '~/redux/node/types';
|
import { INodeRelated } from '~/redux/node/types';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
import { IUser } from '~/redux/auth/types';
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
node: INode;
|
node: INode;
|
||||||
|
user: IUser;
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string;
|
||||||
related: INodeRelated;
|
related: INodeRelated;
|
||||||
comments: IComment[];
|
comments: IComment[];
|
||||||
commentsCount: number;
|
commentsCount: number;
|
||||||
|
isUser: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isLoadingComments: boolean;
|
isLoadingComments: boolean;
|
||||||
|
onShowImageModal: (images: IFile[], index: number) => void;
|
||||||
|
onLoadMoreComments: () => void;
|
||||||
|
onDeleteComment: (id: IComment['id'], isLocked: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NodeLayout: FC<IProps> = memo(
|
const NodeLayout: FC<IProps> = ({
|
||||||
({ node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments }) => {
|
node,
|
||||||
useNodeCoverImage(node);
|
user,
|
||||||
|
comments,
|
||||||
|
commentsCount,
|
||||||
|
related,
|
||||||
|
lastSeenCurrent,
|
||||||
|
isUser,
|
||||||
|
isLoading,
|
||||||
|
isLoadingComments,
|
||||||
|
onLoadMoreComments,
|
||||||
|
onDeleteComment,
|
||||||
|
onShowImageModal,
|
||||||
|
}) => {
|
||||||
|
useNodeCoverImage(node);
|
||||||
|
|
||||||
const { head, block } = useNodeBlocks(node, isLoading);
|
const { head, block } = useNodeBlocks(node, isLoading);
|
||||||
const [canEdit] = useNodePermissions(node);
|
const [canEdit] = useNodePermissions(node);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
{head}
|
{head}
|
||||||
|
|
||||||
<Container className={styles.content}>
|
<Container className={styles.content}>
|
||||||
<Card className={styles.node} seamless>
|
<Card className={styles.node} seamless>
|
||||||
{block}
|
{block}
|
||||||
|
|
||||||
<div className={styles.panel}>
|
<div className={styles.panel}>
|
||||||
<NodePanel node={node} isLoading={isLoading} />
|
<NodePanel node={node} isLoading={isLoading} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NodeBottomBlock
|
<NodeBottomBlock
|
||||||
canEdit={canEdit}
|
isUser={isUser}
|
||||||
node={node}
|
user={user}
|
||||||
comments={comments}
|
node={node}
|
||||||
commentsCount={commentsCount}
|
canEdit={canEdit}
|
||||||
commentsOrder="DESC"
|
comments={comments}
|
||||||
related={related}
|
commentsCount={commentsCount}
|
||||||
isLoadingComments={isLoadingComments}
|
commentsOrder="DESC"
|
||||||
isLoading={isLoading}
|
related={related}
|
||||||
lastSeenCurrent={lastSeenCurrent}
|
isLoadingComments={isLoadingComments}
|
||||||
/>
|
isLoading={isLoading}
|
||||||
|
lastSeenCurrent={lastSeenCurrent}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
|
/>
|
||||||
|
|
||||||
<Footer />
|
<Footer />
|
||||||
</Card>
|
</Card>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<SidebarRouter prefix="/post:id" />
|
<SidebarRouter prefix="/post:id" />
|
||||||
|
|
||||||
<Route path={URLS.NODE_EDIT_URL(':id')} component={EditorEditDialog} />
|
<Route path={URLS.NODE_EDIT_URL(':id')} component={EditorEditDialog} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
);
|
|
||||||
|
|
||||||
export { NodeLayout };
|
export { NodeLayout };
|
||||||
|
|
|
@ -3,6 +3,9 @@ import { NodeLayout } from '~/layouts/NodeLayout';
|
||||||
import { RouteComponentProps } from 'react-router';
|
import { RouteComponentProps } from 'react-router';
|
||||||
import { useScrollToTop } from '~/utils/hooks/useScrollToTop';
|
import { useScrollToTop } from '~/utils/hooks/useScrollToTop';
|
||||||
import { useFullNode } from '~/utils/hooks/node/useFullNode';
|
import { useFullNode } from '~/utils/hooks/node/useFullNode';
|
||||||
|
import { useImageModal } from '~/utils/hooks/useImageModal';
|
||||||
|
import { useNodeComments } from '~/utils/hooks/node/useNodeComments';
|
||||||
|
import { useUser } from '~/utils/hooks/user/userUser';
|
||||||
|
|
||||||
type Props = RouteComponentProps<{ id: string }> & {};
|
type Props = RouteComponentProps<{ id: string }> & {};
|
||||||
|
|
||||||
|
@ -21,17 +24,25 @@ const NodePage: FC<Props> = ({
|
||||||
lastSeenCurrent,
|
lastSeenCurrent,
|
||||||
} = useFullNode(id);
|
} = useFullNode(id);
|
||||||
|
|
||||||
|
const onShowImageModal = useImageModal();
|
||||||
|
const { onLoadMoreComments, onDelete: onDeleteComment } = useNodeComments(id);
|
||||||
|
const user = useUser();
|
||||||
useScrollToTop([id, isLoadingComments]);
|
useScrollToTop([id, isLoadingComments]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NodeLayout
|
<NodeLayout
|
||||||
node={node}
|
node={node}
|
||||||
|
user={user}
|
||||||
related={related}
|
related={related}
|
||||||
lastSeenCurrent={lastSeenCurrent}
|
lastSeenCurrent={lastSeenCurrent}
|
||||||
comments={comments}
|
comments={comments}
|
||||||
commentsCount={commentsCount}
|
commentsCount={commentsCount}
|
||||||
|
isUser={user.is_user}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
isLoadingComments={isLoadingComments}
|
isLoadingComments={isLoadingComments}
|
||||||
|
onShowImageModal={onShowImageModal}
|
||||||
|
onLoadMoreComments={onLoadMoreComments}
|
||||||
|
onDeleteComment={onDeleteComment}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -118,9 +118,12 @@ export interface FlowDisplay {
|
||||||
dominant_color?: string;
|
dominant_color?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Pick<>
|
||||||
|
export type INodeUser = Partial<IUser>;
|
||||||
|
|
||||||
export interface INode {
|
export interface INode {
|
||||||
id?: number;
|
id?: number;
|
||||||
user?: Partial<IUser>;
|
user?: INodeUser;
|
||||||
|
|
||||||
title: string;
|
title: string;
|
||||||
files: IFile[];
|
files: IFile[];
|
||||||
|
|
17
src/utils/hooks/node/useNodeComments.ts
Normal file
17
src/utils/hooks/node/useNodeComments.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
import { nodeLoadMoreComments, nodeLockComment } from '~/redux/node/actions';
|
||||||
|
import { IComment } from '~/redux/types';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
export const useNodeComments = (id: string) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const onLoadMoreComments = useCallback(() => dispatch(nodeLoadMoreComments()), [dispatch]);
|
||||||
|
|
||||||
|
const onDelete = useCallback(
|
||||||
|
(id: IComment['id'], locked: boolean) => dispatch(nodeLockComment(id, locked)),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { onLoadMoreComments, onDelete };
|
||||||
|
};
|
13
src/utils/hooks/useImageModal.ts
Normal file
13
src/utils/hooks/useImageModal.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
import { IFile } from '~/redux/types';
|
||||||
|
import { modalShowPhotoswipe } from '~/redux/modal/actions';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
export const useImageModal = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
return useCallback(
|
||||||
|
(images: IFile[], index: number) => dispatch(modalShowPhotoswipe(images, index)),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue