posting a reply refetches comments

This commit is contained in:
Riley Davis
2017-01-24 10:43:29 -07:00
parent 75bcf29154
commit 7fd075a7a6
5 changed files with 34 additions and 15 deletions
+14 -11
View File
@@ -9,12 +9,12 @@
import React, {PropTypes} from 'react';
import PermalinkButton from 'coral-plugin-permalinks/PermalinkButton';
import AuthorName from '../../coral-plugin-author-name/AuthorName';
import Content from '../../coral-plugin-commentcontent/CommentContent';
import PubDate from '../../coral-plugin-pubdate/PubDate';
import AuthorName from 'coral-plugin-author-name/AuthorName';
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 LikeButton from '../../coral-plugin-likes/LikeButton';
import FlagComment from 'coral-plugin-flags/FlagComment';
import LikeButton from 'coral-plugin-likes/LikeButton';
const getAction = (type, comment) => comment.actions.filter((a) => a.type === type)[0];
@@ -26,6 +26,7 @@ class Comment extends React.Component {
}
static propTypes = {
refetch: PropTypes.func.isRequired,
showSignInDialog: PropTypes.func.isRequired,
postAction: PropTypes.func.isRequired,
deleteAction: PropTypes.func.isRequired,
@@ -67,6 +68,7 @@ class Comment extends React.Component {
asset,
depth,
postItem,
refetch,
addNotification,
showSignInDialog,
postAction,
@@ -99,7 +101,6 @@ class Comment extends React.Component {
? <div className="commentActionsLeft">
<ReplyButton
onClick={() => {
console.log('reply button click');
this.setState({replyBoxVisible: !this.state.replyBoxVisible});
}}
parentCommentId={parentId || comment.id}
@@ -134,17 +135,19 @@ class Comment extends React.Component {
{
this.state.replyBoxVisible
? <ReplyBox
parentId={parentId || comment.id}
addNotification={addNotification}
authorId={currentUser.id}
postItem={postItem}
assetId={asset.id} />
refetch={refetch}
parentId={parentId || comment.id}
addNotification={addNotification}
authorId={currentUser.id}
postItem={postItem}
assetId={asset.id} />
: null
}
{
comment.replies &&
comment.replies.map(reply => {
return <Comment
refetch={refetch}
addNotification={addNotification}
parentId={comment.id}
postItem={postItem}
+1
View File
@@ -133,6 +133,7 @@ class Embed extends Component {
{
user
? <CommentBox
refetch={refetch}
addNotification={this.props.addNotification}
postItem={this.props.postItem}
appendItemArray={this.props.appendItemArray}
+13 -1
View File
@@ -1,12 +1,23 @@
import React, {PropTypes} from 'react';
import Comment from './Comment';
const Stream = ({comments, currentUser, asset, postItem, addNotification, postAction, deleteAction, showSignInDialog}) => {
const Stream = ({
comments,
currentUser,
asset,
postItem,
addNotification,
postAction,
deleteAction,
showSignInDialog,
refetch
}) => {
return (
<div>
{
comments.map(comment => {
return <Comment
refetch={refetch}
addNotification={addNotification}
depth={0}
postItem={postItem}
@@ -24,6 +35,7 @@ const Stream = ({comments, currentUser, asset, postItem, addNotification, postAc
};
Stream.propTypes = {
refetch: PropTypes.func.isRequired,
addNotification: PropTypes.func.isRequired,
postItem: PropTypes.func.isRequired,
asset: PropTypes.object.isRequired,
+3 -2
View File
@@ -11,6 +11,7 @@ class CommentBox extends Component {
// updateItem: PropTypes.func,
// comments: PropTypes.array,
refetch: PropTypes.func.isRequired,
postItem: PropTypes.func.isRequired,
assetId: PropTypes.string.isRequired,
parentId: PropTypes.string,
@@ -35,6 +36,7 @@ class CommentBox extends Component {
assetId,
parentId,
addNotification,
refetch,
authorId
} = this.props;
@@ -45,8 +47,6 @@ class CommentBox extends Component {
parent_id: parentId
};
console.log('CommentBox.parentId', parentId);
// let related;
// let parent_type;
// if (parent_id) {
@@ -78,6 +78,7 @@ class CommentBox extends Component {
// appendItemArray(parent_id || id, related, commentId, !parent_id, parent_type);
addNotification('success', 'Your comment has been posted.');
}
refetch();
})
.catch((err) => console.error(err));
this.setState({body: ''});
+3 -1
View File
@@ -3,9 +3,10 @@ import CommentBox from '../coral-plugin-commentbox/CommentBox';
const name = 'coral-plugin-replies';
const ReplyBox = ({styles, postItem, assetId, authorId, addNotification, parentId}) => (
const ReplyBox = ({styles, postItem, assetId, authorId, addNotification, parentId, refetch}) => (
<div className={`${name}-textarea`} style={styles && styles.container}>
<CommentBox
refetch={refetch}
parentId={parentId}
addNotification={addNotification}
authorId={authorId}
@@ -16,6 +17,7 @@ const ReplyBox = ({styles, postItem, assetId, authorId, addNotification, parentI
);
ReplyBox.propTypes = {
refetch: PropTypes.func.isRequired,
parentId: PropTypes.string,
addNotification: PropTypes.func.isRequired,
authorId: PropTypes.string.isRequired,