forked from VulcanJS/Vulcan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostsList.jsx
76 lines (63 loc) · 2.14 KB
/
PostsList.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Components, getRawComponent, registerComponent, withList, withCurrentUser } from 'meteor/nova:core';
import React from 'react';
import Posts from 'meteor/nova:posts';
import { Alert } from 'react-bootstrap';
const PostsList = (props) => {
const {results, loading, count, totalCount, loadMore, showHeader = true, networkStatus, currentUser, error} = props;
const loadingMore = networkStatus === 2;
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;
return (
<div className="posts-list">
{showHeader ? <Components.PostsListHeader/> : null}
<div className="posts-list-content">
{results.map(post => <Components.PostsItem post={post} key={post._id} currentUser={currentUser} />)}
</div>
{hasMore ? (loadingMore ? <Components.PostsLoading/> : <Components.PostsLoadMore loadMore={loadMore} count={count} totalCount={totalCount} />) : <Components.PostsNoMore/>}
</div>
)
} else if (loading) {
return (
<div className="posts-list">
{showHeader ? <Components.PostsListHeader /> : null}
<div className="posts-list-content">
<Components.PostsLoading/>
</div>
</div>
)
} else {
return (
<div className="posts-list">
{showHeader ? <Components.PostsListHeader /> : null}
<div className="posts-list-content">
<Components.PostsNoResults/>
</div>
</div>
)
}
};
PostsList.displayName = "PostsList";
PostsList.propTypes = {
results: React.PropTypes.array,
terms: React.PropTypes.object,
hasMore: React.PropTypes.bool,
loading: React.PropTypes.bool,
count: React.PropTypes.number,
totalCount: React.PropTypes.number,
loadMore: React.PropTypes.func,
showHeader: React.PropTypes.bool,
};
const options = {
collection: Posts,
queryName: 'postsListQuery',
fragmentName: 'PostsList',
};
registerComponent('PostsList', PostsList, withCurrentUser, [withList, options]);