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

View file

@ -149,15 +149,16 @@ export default function withList (options) {
}, },
props(props) { props(props) {
const loading = props.data.loading, const fetchMore = props.data.fetchMore,
fetchMore = props.data.fetchMore,
refetch = props.data.refetch, refetch = props.data.refetch,
results = props.data[listResolverName], results = props.data[listResolverName],
totalCount = props.data[totalResolverName], totalCount = props.data[totalResolverName],
networkStatus = props.data.networkStatus; networkStatus = props.data.networkStatus;
return { 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, results,
totalCount, totalCount,
refetch, refetch,