Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
2 changes: 1 addition & 1 deletion both/components/Feed/FeedContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions both/components/Feed/FeedList.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*global FeedItem */

class FeedList extends React.Component {
// TODO break out more button into comp
render() {
console.log("[FeedList] Rendering");
return (
Expand All @@ -17,16 +16,14 @@ class FeedList extends React.Component {
/>;
})
}
<button className='more-btn'
onClick={this.props.incrementLimit}>
Load More
</button>
<MoreFeedItems incrementLimit={this.props.incrementLimit}/>
</div>
);
}
}
FeedList.propTypes = {
comments: React.PropTypes.array,
incrementLimit: React.PropTypes.func,
postItems: React.PropTypes.array
};

this.FeedList = FeedList;
10 changes: 0 additions & 10 deletions both/components/FeedItem/_FeedItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

15 changes: 15 additions & 0 deletions both/components/MoreFeedItems/MoreFeedItems.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
this.MoreFeedItems = React.createClass({
propTypes: {
incrementLimit: React.PropTypes.func
},
render() {
return (
<div className='more-feed'>
<button className='more-feed__more-btn'
onClick={this.props.incrementLimit}>
Load More
</button>
</div>
);
}
});
17 changes: 17 additions & 0 deletions both/components/MoreFeedItems/_MoreFeedItems.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions client/styles/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import '../../both/components/ParamsExample/ParamsExample';
@import '../../both/components/CommentItem/CommentItem';
@import '../../both/components/Header/Header';
@import '../../both/components/MoreFeedItems/MoreFeedItems';
16 changes: 14 additions & 2 deletions server/publications/feed.js
Original file line number Diff line number Diff line change
@@ -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});
Expand Down Expand Up @@ -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})
];
});