From 97103739c2c7f69923665813fde5074e158dd515 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 3 Sep 2018 09:04:33 +0200 Subject: [PATCH] toggle comment date --- .../routes/Moderation/components/Comment.js | 5 ++-- .../Moderation/components/CommentTimeAgo.js | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 client/coral-admin/src/routes/Moderation/components/CommentTimeAgo.js diff --git a/client/coral-admin/src/routes/Moderation/components/Comment.js b/client/coral-admin/src/routes/Moderation/components/Comment.js index b12a1e616..f5ce2bb54 100644 --- a/client/coral-admin/src/routes/Moderation/components/Comment.js +++ b/client/coral-admin/src/routes/Moderation/components/Comment.js @@ -14,8 +14,9 @@ import cn from 'classnames'; import ApproveButton from 'coral-admin/src/components/ApproveButton'; import RejectButton from 'coral-admin/src/components/RejectButton'; import CommentDeletedTombstone from '../../../components/CommentDeletedTombstone'; +import CommentTimeAgo from './CommentTimeAgo'; -import t, { timeago } from 'coral-framework/services/i18n'; +import t from 'coral-framework/services/i18n'; class Comment extends React.Component { ref = null; @@ -127,7 +128,7 @@ class Comment extends React.Component { - {timeago(comment.created_at)} + {comment.editing && comment.editing.edited ? ( diff --git a/client/coral-admin/src/routes/Moderation/components/CommentTimeAgo.js b/client/coral-admin/src/routes/Moderation/components/CommentTimeAgo.js new file mode 100644 index 000000000..280ad4479 --- /dev/null +++ b/client/coral-admin/src/routes/Moderation/components/CommentTimeAgo.js @@ -0,0 +1,27 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { timeago } from 'coral-framework/services/i18n'; + +class CommentTimeAgo extends React.Component { + constructor(props) { + super(props); + this.state = { timeago: true }; + } + toggleDate() { + this.setState({ timeago: !this.state.timeago }); + } + render() { + return ( +
+ {this.state.timeago && timeago(this.props.date)} + {!this.state.timeago && new Date(this.props.date).toLocaleString()} +
+ ); + } +} + +CommentTimeAgo.propTypes = { + date: PropTypes.string, +}; + +export default CommentTimeAgo;