From 1bf9fe6b83cd3f1e85027b9ad4bc70ad4af23909 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Tue, 3 Dec 2019 15:02:03 +0700 Subject: [PATCH] comment menu --- src/components/node/Comment/index.tsx | 39 ++++-- src/components/node/CommentContent/index.tsx | 30 ++--- .../node/CommentContent/styles.scss | 12 +- src/components/node/CommentForm/index.tsx | 117 +++++++++--------- src/components/node/CommentMenu/index.tsx | 20 +++ src/components/node/CommentMenu/styles.scss | 68 ++++++++++ src/components/node/NodeCommentForm/index.tsx | 36 ++++++ src/components/node/NodeComments/index.tsx | 10 +- src/containers/node/BorisLayout/index.tsx | 15 ++- src/containers/node/NodeLayout/index.tsx | 16 ++- src/redux/node/actions.ts | 10 ++ src/redux/node/constants.ts | 2 + src/redux/node/handlers.ts | 7 ++ src/redux/node/sagas.ts | 35 +++++- 14 files changed, 319 insertions(+), 98 deletions(-) create mode 100644 src/components/node/CommentMenu/index.tsx create mode 100644 src/components/node/CommentMenu/styles.scss create mode 100644 src/components/node/NodeCommentForm/index.tsx diff --git a/src/components/node/Comment/index.tsx b/src/components/node/Comment/index.tsx index 4f8b78d4..e43c244b 100644 --- a/src/components/node/Comment/index.tsx +++ b/src/components/node/Comment/index.tsx @@ -3,18 +3,34 @@ import { CommentWrapper } from '~/components/containers/CommentWrapper'; import { ICommentGroup, IComment } from '~/redux/types'; import { CommentContent } from '~/components/node/CommentContent'; import * as styles from './styles.scss'; +import { nodeLockComment, nodeEditComment } from '~/redux/node/actions'; +import { INodeState } from '~/redux/node/reducer'; +import { CommentForm } from '../CommentForm'; type IProps = HTMLAttributes & { is_empty?: boolean; is_loading?: boolean; comment_group?: ICommentGroup; + comment_data: INodeState['comment_data']; is_same?: boolean; can_edit?: boolean; - onDelete: (id: IComment['id'], is_deteted: boolean) => void; + onDelete: typeof nodeLockComment; + onEdit: typeof nodeEditComment; }; const Comment: FC = memo( - ({ comment_group, is_empty, is_same, is_loading, className, can_edit, onDelete, ...props }) => { + ({ + comment_group, + comment_data, + is_empty, + is_same, + is_loading, + className, + can_edit, + onDelete, + onEdit, + ...props + }) => { return ( = memo( {...props} >
- {comment_group.comments.map(comment => - comment.deleted_at ? ( -
deleted
- ) : ( + {comment_group.comments.map(comment => { + if (comment.deleted_at) { + return
deleted
; + } + + if (Object.prototype.hasOwnProperty.call(comment_data, comment.id)) { + return ; + } + + return ( - ) - )} + ); + })}
); diff --git a/src/components/node/CommentContent/index.tsx b/src/components/node/CommentContent/index.tsx index 9bf478b0..017bbcda 100644 --- a/src/components/node/CommentContent/index.tsx +++ b/src/components/node/CommentContent/index.tsx @@ -13,14 +13,17 @@ import classnames from 'classnames'; import { PRESETS } from '~/constants/urls'; import { COMMENT_BLOCK_RENDERERS } from '~/constants/comment'; import { Icon } from '~/components/input/Icon'; +import { nodeLockComment, nodeEditComment } from '~/redux/node/actions'; +import { CommentMenu } from '../CommentMenu'; interface IProps { comment: IComment; can_edit: boolean; - onDelete: (id: IComment['id'], is_deteted: boolean) => void; + onDelete: typeof nodeLockComment; + onEdit: typeof nodeEditComment; } -const CommentContent: FC = memo(({ comment, can_edit, onDelete }) => { +const CommentContent: FC = memo(({ comment, can_edit, onDelete, onEdit }) => { const groupped = useMemo>( () => reduce( @@ -35,23 +38,20 @@ const CommentContent: FC = memo(({ comment, can_edit, onDelete }) => { onDelete(comment.id, !comment.deleted_at); }, [comment, onDelete]); - const lock = useMemo( - () => - can_edit ? ( -
-
- -
-
- ) : null, - [can_edit, comment] + const onEditClick = useCallback(() => { + onEdit(comment.id); + }, [comment, onEdit]); + + const menu = useMemo( + () => can_edit && , + [can_edit, comment, onEditClick, onLockClick] ); return (
{comment.text && ( - {lock} + {menu} {formatCommentText(path(['user', 'username'], comment), comment.text).map( (block, key) => @@ -65,7 +65,7 @@ const CommentContent: FC = memo(({ comment, can_edit, onDelete }) => { {groupped.image && groupped.image.length > 0 && (
- {lock} + {menu}
{groupped.image.map(file => ( @@ -83,6 +83,8 @@ const CommentContent: FC = memo(({ comment, can_edit, onDelete }) => { <> {groupped.audio.map(file => (
+ {menu} +
{getPrettyDate(comment.created_at)}
diff --git a/src/components/node/CommentContent/styles.scss b/src/components/node/CommentContent/styles.scss index 883d23bd..0d807c5d 100644 --- a/src/components/node/CommentContent/styles.scss +++ b/src/components/node/CommentContent/styles.scss @@ -4,7 +4,8 @@ position: relative; } -.lock { +.lock, +.edit { position: absolute; right: 0; top: 0; @@ -21,6 +22,7 @@ transition: opacity 0.25s, transform 0.25s; cursor: pointer; background: $red; + z-index: 2; & > div { width: 20px; @@ -46,6 +48,11 @@ } } +.edit { + top: 28px; + background: blue; +} + .block { @include outer_shadow(); min-height: $comment_height; @@ -68,7 +75,8 @@ } &:hover { - .lock { + .lock, + .edit { opacity: 1; pointer-events: all; touch-action: initial; diff --git a/src/components/node/CommentForm/index.tsx b/src/components/node/CommentForm/index.tsx index 2a790b6e..14107403 100644 --- a/src/components/node/CommentForm/index.tsx +++ b/src/components/node/CommentForm/index.tsx @@ -23,6 +23,7 @@ import { SortableImageGrid } from '~/components/editors/SortableImageGrid'; import { moveArrItem } from '~/utils/fn'; import { SortEnd } from 'react-sortable-hoc'; import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid'; +import { NodeCommentForm } from '../NodeCommentForm'; const mapStateToProps = (state: IState) => ({ node: selectNode(state), @@ -188,68 +189,66 @@ const CommentFormUnconnected: FC = ({ ); return ( - -
-
-