Skip to content

Commit

Permalink
Handle commentReply subs at the template level #6, show loader when s…
Browse files Browse the repository at this point in the history
…ubscriptions are loading #3
  • Loading branch information
erasaur committed May 2, 2015
1 parent 4246f16 commit f82cee9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 12 additions & 8 deletions client/views/comments/replies.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<template name="replies">
<div class="comment-container {{side}} {{#if side}}{{side}}{{color}}{{/if}}" id="{{id}}-replies">
<div class="comment-replies clearfix">
{{> newComment}}
</div>
{{#if Template.subscriptionsReady}}
<div class="comment-replies clearfix">
{{> newComment}}
</div>

{{#if hasReplies}}
{{#each replies}}
{{> commentRow}}
{{/each}}
{{#if hasReplies}}
{{#each replies}}
{{> commentRow}}
{{/each}}
{{else}}
<div class="muted">{{_ "no_more"}}</div>
{{/if}}
{{else}}
<div class="muted">{{_ "no_more"}}</div>
<div class="loader">{{_ "loading"}}</div>
{{/if}}
</div>
</template>
10 changes: 7 additions & 3 deletions client/views/comments/replies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Template.replies.rendered = function () {
Template.replies.onCreated(function () {
this.subscribe('commentReplies', this.data.id);
});

Template.replies.onRendered(function () {
var container = this.firstNode;
container._uihooks = {
insertElement: function (node, next) {
Expand All @@ -14,11 +18,11 @@ Template.replies.rendered = function () {
}
}
}
};
});

Template.replies.helpers({
hasReplies: function () {
var comment = Comments.findOne(this.id);
var comment = Comments.findOne(this.id, { fields: { 'replies': 1 } });
return comment && comment.replies.length;
},
replies: function () {
Expand Down

0 comments on commit f82cee9

Please sign in to comment.