Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
knrt10 committed Apr 8, 2019
1 parent e4b5011 commit e0ef9da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/discussion/client/views/DiscussionTabbar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="discussionsTabbar">
{{#if Template.subscriptionsReady}}
{{#if noMessages}}
{{#unless hasMessages}}
<div class="list-view discussions-list flex-tab__header">
<h2>{{_ "No_discussions_yet"}}</h2>
Expand Down
31 changes: 18 additions & 13 deletions app/discussion/client/views/DiscussionTabbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { messageContext } from '../../../ui-utils/client/lib/messageContext';
import { DiscussionOfRoom } from '../lib/discussionsOfRoom';
import { Meteor } from 'meteor/meteor';

import './DiscussionTabbar.html';

Template.discussionsTabbar.helpers({
noMessages() {
return Template.instance().cursor.get().length === 0 ? true : false;
},
hasMessages() {
return Template.instance().cursor > 0;
return Template.instance().cursor.get().length > 1;
},
messages() {
Template.instance().cursor;
return Template.instance().cursor.get();
},
message() {
return _.extend(this, { customClass: 'pinned', actionContext: 'pinned' });
Expand All @@ -24,24 +28,25 @@ Template.discussionsTabbar.helpers({

Template.discussionsTabbar.onCreated(function() {
this.rid = this.data.rid;
this.cursor = DiscussionOfRoom.find({
rid: this.rid,
}, {
sort: {
ts: -1,
},
});
this.hasMore = new ReactiveVar(true);
this.limit = new ReactiveVar(50);
return this.autorun(() => {
this.cursor = new ReactiveVar([]);
this.autorun(() => {
const data = Template.currentData();
return this.subscribe('discussionsOfRoom', data.rid, this.limit.get(), () => {
const handle = Meteor.subscribe('discussionsOfRoom', data.rid, this.limit.get());
const isReady = handle.ready();
// Wait for collection to be ready
if (isReady) {
const discussions = DiscussionOfRoom.find({
rid: data.rid,
}).fetch();
this.cursor.set(discussions);
if (DiscussionOfRoom.find({
rid: data.rid,
}).count() < this.limit.get()) {
}).fetch().length < this.limit.get()) {
return this.hasMore.set(false);
}
});
}
});
});

Expand Down

0 comments on commit e0ef9da

Please sign in to comment.