Skip to content

Commit

Permalink
[Upd #70] Refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Jan 27, 2022
1 parent 73b4299 commit f4be32d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/components/comment/CommentList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Rings } from 'react-loader-spinner';
const CommentList = (props) => {
const [isCommentDeleted, setIsCommentDeleted] = useState(false);

const deleteComment = () => {
const deleteCommentViewHandler = () => {
setIsCommentDeleted(true);
setTimeout(() => {
setIsCommentDeleted(false);
Expand All @@ -29,10 +29,9 @@ const CommentList = (props) => {
commentValue={comment[Constants.HAS_COMMENT_VALUE]}
author={comment[Constants.HAS_AUTHOR] ? comment[Constants.HAS_AUTHOR] : null}
timestamp={comment[Constants.HAS_TIMESTAMP]}
onClickDeleteComment={props.onClickDeleteComment}
deleteCommment={deleteComment}
deleteQuestionComment={props.deleteQuestionComment}
deleteCommentView={deleteCommentViewHandler}
index={index}
comment={comment}
/>
</div>
))}
Expand All @@ -44,7 +43,7 @@ const CommentList = (props) => {

CommentList.propTypes = {
comment: PropTypes.array.isRequired,
onClickDeleteComment: PropTypes.func.isRequired
deleteQuestionComment: PropTypes.func.isRequired
};

export default CommentList;
11 changes: 6 additions & 5 deletions src/components/comment/CommentView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const CommentView = (props) => {
setShowRecycleBin(!showRecycleBin)
}

const onClickDeleteCommentHandler = () => {
props.onClickDeleteComment(props.index);
props.deleteCommment()
const onClickDeleteQuestionCommentHandler = () => {
props.deleteQuestionComment(props.index);
props.deleteCommentView();
}

return (
Expand All @@ -101,7 +101,7 @@ const CommentView = (props) => {
className="comment-delete emphasise-on-relevant-icon"
whileHover={{scale: 1.2}}
whileTap={{scale: 0.9}}
onClick={onClickDeleteCommentHandler}>
onClick={onClickDeleteQuestionCommentHandler}>
<RecycleBin/>
</motion.div>
: null }
Expand All @@ -117,7 +117,8 @@ CommentView.propTypes = {
author: PropTypes.object.isRequired,
timestamp: PropTypes.string.isRequired,
commentValue: PropTypes.string.isRequired,
onClickDeleteComment: PropTypes.func.isRequired,
deleteQuestionComment: PropTypes.func.isRequired,
deleteCommentView: PropTypes.func.isRequired,
index: PropTypes.number.isRequired
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/comment/QuestionCommentIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const QuestionCommentIcon = (props) => {
change[Constants.HAS_TIMESTAMP] = Date.now().toString();
};

const onClickDeleteCommentHandler = (index) => {
const deleteQuestionCommentHandler = (index) => {
const comment = _getComments();
comment.splice(index, 1);
}
Expand Down Expand Up @@ -105,7 +105,7 @@ const QuestionCommentIcon = (props) => {
whileHover={{scale: 1.1, transition: {duration: 0.1}}}>
<Close/>
</motion.div>
<CommentList comment={_getComments()} onClickDeleteComment={onClickDeleteCommentHandler}/>
<CommentList comment={_getComments()} deleteQuestionComment={deleteQuestionCommentHandler}/>
<CommentForm onChange={onCommentValueChangeHandler} />
</span>
</Tooltip>
Expand Down

0 comments on commit f4be32d

Please sign in to comment.