Vulcan/client/views/users/profile/user_posts.js

25 lines
742 B
JavaScript
Raw Normal View History

2014-12-08 14:53:26 +09:00
Template[getTemplate('userPosts')].created = function () {
Session.set('postsShown', 5);
var user = this.data;
Tracker.autorun(function () {
coreSubscriptions.subscribe('userPosts', user._id, Session.get('postsShown'));
});
2014-12-08 14:53:26 +09:00
};
Template[getTemplate('userPosts')].helpers({
posts: function () {
return Posts.find({userId: this._id}, {limit: Session.get('postsShown')});
},
hasMorePosts: function () {
console.log(this)
return Posts.find({userId: this._id}).count() >= Session.get('postsShown');
2014-12-08 14:53:26 +09:00
}
});
Template[getTemplate('userPosts')].events({
'click .posts-more': function (e) {
e.preventDefault();
var postsShown = Session.get('postsShown');
Session.set('postsShown', postsShown + 10);
}
});