mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
77 lines
2.5 KiB
JavaScript
77 lines
2.5 KiB
JavaScript
import { Components, getRawComponent, registerComponent, withList, withCurrentUser, Utils } from 'meteor/vulcan:core';
|
|
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import Posts from 'meteor/vulcan:posts';
|
|
import { Alert } from 'react-bootstrap';
|
|
import { FormattedMessage, intlShape } from 'react-intl';
|
|
|
|
const Error = ({error}) => <Alert className="flash-message" bsStyle="danger"><FormattedMessage id={error.id} values={{value: error.value}}/>{error.message}</Alert>
|
|
|
|
const PostsList = (props) => {
|
|
|
|
const {results, loading, count, totalCount, loadMore, showHeader = true, networkStatus, currentUser, error, terms} = props;
|
|
|
|
const loadingMore = networkStatus === 2;
|
|
|
|
if (results && results.length) {
|
|
|
|
const hasMore = totalCount > results.length;
|
|
|
|
return (
|
|
<div className="posts-list">
|
|
{showHeader ? <Components.PostsListHeader/> : null}
|
|
{error ? <Error error={Utils.decodeIntlError(error)} /> : null }
|
|
<div className="posts-list-content">
|
|
{results.map(post => <Components.PostsItem post={post} key={post._id} currentUser={currentUser} terms={terms} />)}
|
|
</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}
|
|
{error ? <Error error={Utils.decodeIntlError(error)} /> : null }
|
|
<div className="posts-list-content">
|
|
<Components.PostsLoading/>
|
|
</div>
|
|
</div>
|
|
)
|
|
} else {
|
|
return (
|
|
<div className="posts-list">
|
|
{showHeader ? <Components.PostsListHeader /> : null}
|
|
{error ? <Error error={Utils.decodeIntlError(error)} /> : null }
|
|
<div className="posts-list-content">
|
|
<Components.PostsNoResults/>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
};
|
|
|
|
PostsList.displayName = "PostsList";
|
|
|
|
PostsList.propTypes = {
|
|
results: PropTypes.array,
|
|
terms: PropTypes.object,
|
|
hasMore: PropTypes.bool,
|
|
loading: PropTypes.bool,
|
|
count: PropTypes.number,
|
|
totalCount: PropTypes.number,
|
|
loadMore: PropTypes.func,
|
|
showHeader: PropTypes.bool,
|
|
};
|
|
|
|
PostsList.contextTypes = {
|
|
intl: intlShape
|
|
};
|
|
|
|
const options = {
|
|
collection: Posts,
|
|
queryName: 'postsListQuery',
|
|
fragmentName: 'PostsList',
|
|
};
|
|
|
|
registerComponent('PostsList', PostsList, withCurrentUser, [withList, options]);
|