diff --git a/.gitignore b/.gitignore index e69de29..62c8935 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/both/components/Feed/FeedContainer.jsx b/both/components/Feed/FeedContainer.jsx index f4a8608..39c4a54 100644 --- a/both/components/Feed/FeedContainer.jsx +++ b/both/components/Feed/FeedContainer.jsx @@ -43,7 +43,7 @@ this.FeedContainer = React.createClass({ }, // subscribe to a reactive stream of data from - // publication at: server/publications/posts.js + // publication at: server/publications/feed.js startMeteorSubscriptions() { var fields = this.state.fieldsNeeded; var postIds = this.data.postIds; diff --git a/both/components/Feed/FeedList.jsx b/both/components/Feed/FeedList.jsx index ceed960..803e7de 100644 --- a/both/components/Feed/FeedList.jsx +++ b/both/components/Feed/FeedList.jsx @@ -1,7 +1,6 @@ /*global FeedItem */ class FeedList extends React.Component { - // TODO break out more button into comp render() { console.log("[FeedList] Rendering"); return ( @@ -17,16 +16,14 @@ class FeedList extends React.Component { />; }) } - + ); } } FeedList.propTypes = { - comments: React.PropTypes.array, + incrementLimit: React.PropTypes.func, + postItems: React.PropTypes.array }; this.FeedList = FeedList; diff --git a/both/components/FeedItem/_FeedItem.scss b/both/components/FeedItem/_FeedItem.scss index dd14f73..4e89d91 100644 --- a/both/components/FeedItem/_FeedItem.scss +++ b/both/components/FeedItem/_FeedItem.scss @@ -78,13 +78,3 @@ } -// TODO move to correct place -.more-btn { - padding: 7px 15px; - margin: 10px 0 20px 200px; // FIXME - background-color: $primary; - color: #ffffff; - border: none; - cursor: pointer; -} - diff --git a/both/components/MoreFeedItems/MoreFeedItems.jsx b/both/components/MoreFeedItems/MoreFeedItems.jsx new file mode 100644 index 0000000..49b30e1 --- /dev/null +++ b/both/components/MoreFeedItems/MoreFeedItems.jsx @@ -0,0 +1,15 @@ +this.MoreFeedItems = React.createClass({ + propTypes: { + incrementLimit: React.PropTypes.func + }, + render() { + return ( +
+ +
+ ); + } +}); \ No newline at end of file diff --git a/both/components/MoreFeedItems/_MoreFeedItems.scss b/both/components/MoreFeedItems/_MoreFeedItems.scss new file mode 100644 index 0000000..7f3a649 --- /dev/null +++ b/both/components/MoreFeedItems/_MoreFeedItems.scss @@ -0,0 +1,17 @@ +.more-feed { + width: 100%; + display: flex; + justify-content: center; + align-items: center; + + + &__more-btn { + padding: 7px 15px; + min-width: 20px; + margin-bottom: 13px; + background-color: $primary; + color: #ffffff; + border: none; + cursor: pointer; + } +} \ No newline at end of file diff --git a/client/styles/_components.scss b/client/styles/_components.scss index 4a3b284..d3f4307 100644 --- a/client/styles/_components.scss +++ b/client/styles/_components.scss @@ -4,3 +4,4 @@ @import '../../both/components/ParamsExample/ParamsExample'; @import '../../both/components/CommentItem/CommentItem'; @import '../../both/components/Header/Header'; +@import '../../both/components/MoreFeedItems/MoreFeedItems'; diff --git a/server/publications/feed.js b/server/publications/feed.js index e3c794b..b7ea27e 100644 --- a/server/publications/feed.js +++ b/server/publications/feed.js @@ -1,6 +1,7 @@ /*global Posts, Comments */ -var optional = Match.Optional; +var optional = Match.Optional, + loadMoreStep = 5; Meteor.publish('feed', function(fields, limits, postIds) { check(limits, {posts: Number}); @@ -49,10 +50,21 @@ Meteor.publish('feed', function(fields, limits, postIds) { }); + // current 'load more' postIds + var newPostIds = Posts.find({}, { + fields: {'_id': 1}, + sort: {createdAt: -1}, + limit: limits.posts, + skip: limits.posts - loadMoreStep} + ).map(function (post) { + return post._id; + }); + postIds = _.union(postIds ? postIds : [], newPostIds); + // returns Mongo Cursors return [ Posts.find({}, {fields: fields.posts, sort: {createdAt: -1}, limit: limits.posts}), - Comments.find({postId: {$in: postIds ? postIds : []}}, {fields: fields.postComments}) + Comments.find({postId: {$in: postIds}}, {fields: fields.postComments}) ]; });