use networkStatus === 1 instead of loading prop from apollo-client hoc

This commit is contained in:
xavcz 2016-12-21 18:14:13 +01:00
parent 78ba0e8530
commit 4ca3cab7ce
3 changed files with 14 additions and 16 deletions

View file

@ -1,13 +1,12 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { ModalTrigger, withList } from 'meteor/nova:core';
import { withCurrentUser, Components, registerComponent, Utils } from 'meteor/nova:core';
import { ModalTrigger, withList, withCurrentUser, Components, registerComponent, Utils } from 'meteor/nova:core';
import Comments from 'meteor/nova:comments';
import gql from 'graphql-tag';
const PostsCommentsThread = (props, context) => {
const {loading, terms: { postId }, results} = props;
const {loading, terms: { postId }, results, totalCount} = props;
if (loading) {
@ -15,16 +14,14 @@ const PostsCommentsThread = (props, context) => {
} else {
const commentCount = results.length;
const resultsClone = _.map(results, _.clone); // we don't want to modify the objects we got from props
const nestedComments = Utils.unflatten(resultsClone, '_id', 'parentCommentId');
return (
<div className="posts-comments-thread">
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
<Components.CommentsList comments={nestedComments} commentCount={commentCount}/>
{ props.currentUser ?
<Components.CommentsList comments={nestedComments} commentCount={totalCount}/>
{!!props.currentUser ?
<div className="posts-comments-thread-new">
<h4><FormattedMessage id="comments.new"/></h4>
<Components.CommentsNewForm
@ -74,4 +71,4 @@ const options = {
fragment: PostsCommentsThread.fragment,
};
registerComponent('PostsCommentsThread', PostsCommentsThread, withCurrentUser, withList(options));
registerComponent('PostsCommentsThread', PostsCommentsThread, withList(options), withCurrentUser);

View file

@ -25,7 +25,7 @@ export default function withDocument (options) {
props: returnedProps => {
const { ownProps, data } = returnedProps;
return {
loading: data.loading,
loading: data.networkStatus === 1,
document: data[singleResolverName],
fragmentName,
fragment,

View file

@ -149,15 +149,16 @@ export default function withList (options) {
},
props(props) {
const loading = props.data.loading,
fetchMore = props.data.fetchMore,
const fetchMore = props.data.fetchMore,
refetch = props.data.refetch,
results = props.data[listResolverName],
totalCount = props.data[totalResolverName],
networkStatus = props.data.networkStatus;
return {
loading,
// see https://github.com/apollostack/apollo-client/blob/master/src/queries/store.ts#L28-L36
// note: loading will propably change soon https://github.com/apollostack/apollo-client/issues/831
loading: networkStatus === 1, // networkStatus = 1 <=> the graphql container is loading
results,
totalCount,
refetch,