still working on "load more" bug

This commit is contained in:
Sacha Greif 2014-08-28 07:55:13 +09:00
parent ba1c6f7c75
commit 5a7921c6d2
3 changed files with 32 additions and 25 deletions

View file

@ -13,9 +13,11 @@ Meteor.startup(function () {
template: getTemplate('posts_daily'),
onBeforeAction: function() {
this.days = this.params.days ? this.params.days : 3;
// this.days = Session.get('postsDays') ? Session.get('postsDays') : 3;
var terms = {
view: 'daily',
days: this.days,
after: moment().subtract('days', this.days).startOf('day').toDate()
};
@ -29,6 +31,7 @@ Meteor.startup(function () {
},
data: function() {
Session.set('postsDays', this.days);
return {
days: this.days
};

View file

@ -1,23 +1,23 @@
<template name="postsDaily">
{{#if postsLoaded}}
<div class="grid">
{{#each days}}
<h2 class="posts-day-heading">{{formatDate date "dddd, MMMM Do YYYY"}}</h2>
<div class="posts-wrapper posts-day posts list grid-module">
{{#if posts}}
{{#each posts}}
{{> UI.dynamic template=post_item}}
{{/each}}
{{else}}
<p class="empty-day-notice">Sorry, no posts for that day.</p>
{{/if}}
</div>
{{/each}}
<a class="more-button grid-module" href="{{loadMoreUrl}}"><span>{{i18n "Load more"}}</span></a>
</div>
{{else}}
<div class="grid loading-page">
{{>spinner}}
</div>
{{/if}}
{{#if postsLoaded}}
<div class="grid">
{{#each days}}
<h2 class="posts-day-heading">{{formatDate date "dddd, MMMM Do YYYY"}}</h2>
<div class="posts-wrapper posts-day posts list grid-module">
{{#if posts}}
{{#each posts}}
{{> UI.dynamic template=post_item}}
{{/each}}
{{else}}
<p class="empty-day-notice">Sorry, no posts for that day.</p>
{{/if}}
</div>
{{/each}}
<a class="more-button grid-module" href="{{loadMoreUrl}}"><span>{{i18n "Load more"}}</span></a>
</div>
{{else}}
<div class="grid loading-page">
{{>spinner}}
</div>
{{/if}}
</template>

View file

@ -20,9 +20,10 @@ Template[getTemplate('postsDaily')].helpers({
return getTemplate('post_item');
},
days: function () {
console.log(this)
var daysArray = [];
for (i = 0; i < this.days; i++) {
// var days = this.days;
var days = Session.get('postsDays');
for (i = 0; i < days; i++) {
daysArray.push({
date: moment().subtract('days', i).startOf('day').toDate()
});
@ -33,12 +34,15 @@ Template[getTemplate('postsDaily')].helpers({
return getPosts(this.date);
},
loadMoreUrl: function () {
return '/daily/' + (parseInt(this.days) + 3);
var count = parseInt(Session.get('postsDays')) + 3;
return '/daily/' + count;
}
});
// Template[getTemplate('postsDaily')].events({
// 'click .more-button': function (e) {
// e.preventDefault();
// var count = parseInt(Session.get('postsDays')) + 3;
// Session.set('postsDays', count);
// }
// });