From 06f8926964abebf667bf332415973d250b07b1a7 Mon Sep 17 00:00:00 2001 From: okbel Date: Wed, 4 Apr 2018 07:25:47 -0300 Subject: [PATCH] Avoiding refetching --- .../coral-admin/src/components/UserDetail.js | 20 ++++++------------- .../coral-admin/src/containers/UserDetail.js | 3 ++- client/coral-framework/graphql/mutations.js | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/client/coral-admin/src/components/UserDetail.js b/client/coral-admin/src/components/UserDetail.js index 31ad999dc..90df62f4a 100644 --- a/client/coral-admin/src/components/UserDetail.js +++ b/client/coral-admin/src/components/UserDetail.js @@ -28,16 +28,6 @@ import UserInfoTooltip from './UserInfoTooltip'; import t from 'coral-framework/services/i18n'; class UserDetail extends React.Component { - rejectThenReload = async info => { - await this.props.rejectComment(info); - this.props.data.refetch(); - }; - - acceptThenReload = async info => { - await this.props.acceptComment(info); - this.props.data.refetch(); - }; - bulkAcceptThenReload = async () => { await this.props.bulkAccept(); this.props.data.refetch(); @@ -110,6 +100,8 @@ class UserDetail extends React.Component { unbanUser, unsuspendUser, modal, + acceptComment, + rejectComment, } = this.props; // if totalComments is 0, you're dividing by zero @@ -304,8 +296,8 @@ class UserDetail extends React.Component { loadMore={loadMore} toggleSelect={toggleSelect} viewUserDetail={viewUserDetail} - acceptComment={this.acceptThenReload} - rejectComment={this.rejectThenReload} + acceptComment={acceptComment} + rejectComment={rejectComment} selectedCommentIds={selectedCommentIds} toggleSelectAll={toggleSelectAll} bulkAcceptThenReload={this.bulkAcceptThenReload} @@ -322,8 +314,8 @@ class UserDetail extends React.Component { loadMore={loadMore} toggleSelect={toggleSelect} viewUserDetail={viewUserDetail} - acceptComment={this.acceptThenReload} - rejectComment={this.rejectThenReload} + acceptComment={acceptComment} + rejectComment={rejectComment} selectedCommentIds={selectedCommentIds} toggleSelectAll={toggleSelectAll} bulkAcceptThenReload={this.bulkAcceptThenReload} diff --git a/client/coral-admin/src/containers/UserDetail.js b/client/coral-admin/src/containers/UserDetail.js index fb1508a2f..73b46db3c 100644 --- a/client/coral-admin/src/containers/UserDetail.js +++ b/client/coral-admin/src/containers/UserDetail.js @@ -109,6 +109,7 @@ class UserDetailContainer extends React.Component { componentWillReceiveProps(next) { if (this.props.userId === null && next.userId) { next.data.refetch(); + console.log('fetching'); } } @@ -148,6 +149,7 @@ UserDetailContainer.propTypes = { selectedCommentIds: PropTypes.array, unbanUser: PropTypes.func.isRequired, unsuspendUser: PropTypes.func.isRequired, + userId: PropTypes.string, }; const LOAD_MORE_QUERY = gql` @@ -245,7 +247,6 @@ export const withUserDetailQuery = withQuery( options: ({ userId, statuses }) => { return { variables: { author_id: userId, statuses }, - fetchPolicy: 'network-only', }; }, skip: ownProps => !ownProps.userId, diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index 1b3b4c6fc..0c8d404f6 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -180,7 +180,7 @@ export const withSetCommentStatus = withMutation( const fragmentId = `Comment_${commentId}`; const data = proxy.readFragment({ fragment, id: fragmentId }); - + console.log('data', data); data.status = status; data.status_history = data.status_history ? data.status_history