Skip to content

Commit

Permalink
Update profile to use controller state #6 instead of sessions #9
Browse files Browse the repository at this point in the history
  • Loading branch information
erasaur committed May 2, 2015
1 parent bcb1d56 commit 26c3e08
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
8 changes: 4 additions & 4 deletions client/views/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ <h3 class="profile-title">{{profile.name}}</h3>
<div class="divider"><hr></div>
<ul class="page-nav-action clearfix">
<li>
<a href="#" class="js-nav-button {{Session "currentTab" eq="profileComments" s="active"}}" data-tab="profileComments">
<a href="#" class="js-nav-button {{activeClass 'profileComments'}}" data-tab="profileComments">
<span class="value">{{stats.commentsCount}}</span>
<span class="label">{{_ "comments"}}</span>
</a>
</li>
<li>
<a href="#" class="js-nav-button {{Session "currentTab" eq="profileTopics" s="active"}}" data-tab="profileTopics">
<a href="#" class="js-nav-button {{activeClass 'profileTopics'}}" data-tab="profileTopics">
<span class="value">{{stats.topicsCount}}</span>
<span class="label">{{_ "topics"}}</span>
</a>
</li>
<li>
<a href="#" class="js-nav-button {{Session "currentTab" eq="profileFollowers" s="active"}}" data-tab="profileFollowers">
<a href="#" class="js-nav-button {{activeClass 'profileFollowers'}}" data-tab="profileFollowers">
<span class="value">{{activity.followers.length}}</span>
<span class="label">{{_ "followers"}}</span>
</a>
</li>
<li>
<a href="#" class="js-nav-button {{Session "currentTab" eq="profileFollowing" s="active"}}" data-tab="profileFollowing">
<a href="#" class="js-nav-button {{activeClass 'profileFollowing'}}" data-tab="profileFollowing">
<span class="value">{{activity.followingUsers.length}}</span>
<span class="label">{{_ "following"}}</span>
</a>
Expand Down
75 changes: 48 additions & 27 deletions client/views/profile/profile.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
Template.profileComments.created = function () {
initInfiniteScroll.call(this, Comments.find({
'userId': this.data._id
// profile comments ----------------------------------

Template.profileComments.onCreated(function () {
initInfiniteScroll.call(this, Comments.find({ 'userId': this.data._id }, {
fields: { '_id': 1 }
}));
};
Template.profileComments.destroyed = function () {
});
Template.profileComments.onDestroyed(function () {
stopInfiniteScroll.call(this);
};
Template.profileTopics.created = function () {
initInfiniteScroll.call(this, Topics.find({
'userId': this.data._id
});

// profile topics ------------------------------------

Template.profileTopics.onCreated(function () {
initInfiniteScroll.call(this, Topics.find({ 'userId': this.data._id }, {
fields: { '_id': 1 }
}));
};
Template.profileTopics.destroyed = function () {
});
Template.profileTopics.onDestroyed(function () {
stopInfiniteScroll.call(this);
};
});

// profile -------------------------------------------

Template.profile.helpers({
currentTab: function () {
return Session.get('currentTab');
var controller = getCurrentController();
return controller.state.get('currentTab');
}
});

// profile buttons -----------------------------------

Template.profileButtons.helpers({
ownProfile: function () {
var userId = Meteor.userId();
return userId && userId === this._id;
return Meteor.userId() === this._id;
}
});

Template.profileHeader.helpers({
canFollow: function () {
return canFollow(Meteor.user(), this._id);
},
following: function () {
return this.activity && this.activity.followers &&
_.contains(this.activity.followers, Meteor.userId());
}
});

Template.profileButtons.events({
'click #js-settings': function (event, template) {
Router.go('settings', { '_id': this._id });
Expand All @@ -49,6 +48,18 @@ Template.profileButtons.events({
}
});

// profile header ------------------------------------

Template.profileHeader.helpers({
canFollow: function () {
return canFollow(Meteor.user(), this._id);
},
following: function () {
var followers = getProperty(this, 'activity.followers');
return followers && _.contains(followers, Meteor.userId());
}
});

Template.profileHeader.events({
'click #js-follow': function (event, template) {
Meteor.call('newFollower', this._id, function (error) {
Expand All @@ -64,13 +75,23 @@ Template.profileHeader.events({
}
});

// profile nav ---------------------------------------

Template.profileNav.helpers({
activeClass: function (tab) {
var controller = getCurrentController();
return controller.state.get('currentTab') === tab && 'active';
}
});

Template.profileNav.events({
'click .js-nav-button': function (event, template) {
Session.set('currentTab', event.currentTarget.getAttribute('data-tab'));
var controller = getCurrentController();
controller.state.set('currentTab', event.currentTarget.getAttribute('data-tab'));
}
});

// page tabs -----------------------------------------
// profile tabs --------------------------------------

Template.profileTopics.helpers({
topics: function () {
Expand Down

0 comments on commit 26c3e08

Please sign in to comment.