From 9993350b7ee6ec05b2e14c7c272bbdaf840a6a8f Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 6 Jun 2017 00:54:12 +0700 Subject: [PATCH] Animate flash for new comments --- .../src/components/Comment.css | 10 +++++ .../src/components/Comment.js | 39 ++++++++++++++++--- .../src/components/Stream.js | 7 ++-- .../src/containers/Embed.js | 2 +- package.json | 1 + yarn.lock | 2 +- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/client/coral-embed-stream/src/components/Comment.css b/client/coral-embed-stream/src/components/Comment.css index 5fab57d95..b0fca75c8 100644 --- a/client/coral-embed-stream/src/components/Comment.css +++ b/client/coral-embed-stream/src/components/Comment.css @@ -97,3 +97,13 @@ .Wizard .textAlignRight { text-align: right; } + +@keyframes enter { + 0% {background-color: rgba(0, 0, 0, 0);} + 50% {background-color: rgba(255,255,0, 0.2);} + 100% {background-color: rgba(0, 0, 0, 0);} +} + +.enter { + animation: enter 1000ms; +} diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 2c69f3979..c853e5018 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -8,6 +8,9 @@ import Content from 'coral-plugin-commentcontent/CommentContent'; import PubDate from 'coral-plugin-pubdate/PubDate'; import {ReplyBox, ReplyButton} from 'coral-plugin-replies'; import FlagComment from 'coral-plugin-flags/FlagComment'; +import {TransitionGroup} from 'react-transition-group'; +import cn from 'classnames'; + import { BestButton, IfUserCanModifyBest, @@ -19,7 +22,6 @@ import Slot from 'coral-framework/components/Slot'; import LoadMore from './LoadMore'; import IgnoredCommentTombstone from './IgnoredCommentTombstone'; import {TopRightMenu} from './TopRightMenu'; -import classnames from 'classnames'; import {EditableCommentContent} from './EditableCommentContent'; import {getActionSummary, iPerformedThisAction} from 'coral-framework/utils'; import {getEditableUntilDate} from './util'; @@ -85,9 +87,9 @@ class Comment extends React.Component { // Whether the comment should be editable (e.g. after a commenter clicking the 'Edit' button on their own comment) isEditing: false, replyBoxVisible: false, + animateEnter: false, ...resetCursors({}, props), }; - } componentWillReceiveProps(next) { @@ -110,6 +112,28 @@ class Comment extends React.Component { } } + componentWillAppear(callback) { + callback(); + } + componentWillEnter(callback) { + callback(); + const userId = this.props.currentUser ? this.props.currentUser.id : null; + if (this.props.comment.id.indexOf('pending') >= 0) { + return; + } + if (userId && this.props.comment.user.id === userId) { + + // This comment was just added by currentUser. + if (Date.now() - Number(new Date(this.props.comment.created_at)) < 30 * 1000) { + return; + } + } + this.setState({animateEnter: true}); + } + componentWillLeave(callback) { + callback(); + } + static propTypes = { reactKey: PropTypes.string.isRequired, @@ -325,7 +349,7 @@ class Comment extends React.Component { return (
@@ -362,17 +386,17 @@ class Comment extends React.Component { (comment.user.id === currentUser.id)) /* User can edit/delete their own comment for a short window after posting */ - ? + ? { commentIsStillEditable(comment) && Edit } /* TopRightMenu allows currentUser to ignore other users' comments */ - : + : : null} + + {view.map((reply) => { return commentIsIgnored(reply) ? @@ -499,6 +525,7 @@ class Comment extends React.Component { comment={reply} />; })} +
nodes.some((node) => node.id === id); @@ -239,7 +240,7 @@ class Stream extends React.Component { count={comments.nodes.length - view.length} loadMore={this.viewNewComments} /> -
+ {view.map((comment) => { return commentIsIgnored(comment) ? @@ -273,7 +274,7 @@ class Stream extends React.Component { liveUpdates={false} />; })} -
+ pym.scrollParentToChildEl('coralStream'), 0); diff --git a/package.json b/package.json index fe87f17f5..c3c08a2db 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "react-apollo": "^1.1.0", "react-recaptcha": "^2.2.6", "react-toastify": "^1.5.0", + "react-transition-group": "^1.1.3", "recompose": "^0.23.1", "redis": "^2.7.1", "resolve": "^1.3.2", diff --git a/yarn.lock b/yarn.lock index 9855d91e8..6a069df84 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6909,7 +6909,7 @@ react-toastify@^1.5.0: prop-types "^15.5.8" react-transition-group "^1.1.2" -react-transition-group@^1.1.2: +react-transition-group@^1.1.2, react-transition-group@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.1.3.tgz#5e02cf6e44a863314ff3c68a0c826c2d9d70b221" dependencies: