pass error to PostsList and show error message

This commit is contained in:
SachaG 2017-02-03 15:36:40 +09:00
parent afebadba55
commit cf1ee06273
3 changed files with 17 additions and 4 deletions

View file

@ -3,14 +3,25 @@ import React from 'react';
import { withList } from 'meteor/nova:core';
import Posts from 'meteor/nova:posts';
import { withCurrentUser } from 'meteor/nova:core';
import { Alert } from 'react-bootstrap';
const PostsList = (props) => {
const {results, loading, count, totalCount, loadMore, showHeader = true, networkStatus, currentUser} = props;
const {results, loading, count, totalCount, loadMore, showHeader = true, networkStatus, currentUser, error} = props;
const loadingMore = networkStatus === 2;
if (results && results.length) {
if (error) {
return (
<div className="posts-list">
<Alert className="flash-message" bsStyle="danger">
{error.message}
</Alert>
</div>
)
} else if (results && results.length) {
const hasMore = totalCount > results.length;

View file

@ -110,7 +110,8 @@ const withList = (options) => {
// results = Utils.convertDates(collection, props.data[listResolverName]),
results = props.data[listResolverName],
totalCount = props.data[totalResolverName],
networkStatus = props.data.networkStatus;
networkStatus = props.data.networkStatus,
error = props.data.error;
return {
// see https://github.com/apollostack/apollo-client/blob/master/src/queries/store.ts#L28-L36
@ -120,6 +121,7 @@ const withList = (options) => {
totalCount,
refetch,
networkStatus,
error,
count: results && results.length,
// regular load more (reload everything)

View file

@ -47,7 +47,7 @@ Meteor.startup(function initNovaRoutesAndApollo() {
// configure apollo
client = new ApolloClient(meteorClientConfig());
var apolloClientReducer = (state = initialState.apollo, action) => {
var apolloClientReducer = (state = initialState && initialState.apollo, action) => {
return client.reducer()(state, action);
};
addReducer({apollo: apolloClientReducer});