Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Commit

Permalink
Merge pull request #111 from christianbundy/master
Browse files Browse the repository at this point in the history
Add comments
  • Loading branch information
christianbundy committed Apr 26, 2014
2 parents f7c70ae + a1facb1 commit 47e92fa
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 37 deletions.
8 changes: 5 additions & 3 deletions client/comments/list/listComments.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template name="comments">
<div class="entry col-md-6 col-md-offset-3">
Oops – post comments haven't been finished yet!
<template name="listComments">
<div class="listComments">
{{#each post.oldChildren}}
{{>viewComment}}
{{/each}}
</div>
</template>
25 changes: 25 additions & 0 deletions client/comments/view/viewComment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template name="viewComment">
{{#if text}}
<div class="nonvoted post" data-id="{{id}}">
<div class="media">
<div href="#" class="pull-left">
{{>vote}}
</div>
<div class="media-body">

<p class="caption">{{points}} points by {{author}} at <abbr title="{{created_at}}"><time datetime="{{created_at}}">{{created_at}}</time></abbr></p>
<p class="commentText">{{{text}}}</p>
</div>
</div>
</div>
{{/if}}
{{#each children}}
<div class="indent">
{{>viewComment}}
</div>
{{/each}}
</template>

<template name="upvoted">
nonvoted
</template>
4 changes: 4 additions & 0 deletions client/comments/view/viewComment.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.indent {
padding-left: 1rem;
background-color: #F9FAFB;
}
3 changes: 0 additions & 3 deletions client/global/header/globalHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
{{#unless timeMonth}}
<li><a href="/{{toLowerCase sortType}}/month">Month</a></li>
{{/unless}}
{{#unless timeQuarter}}
<li><a href="/{{toLowerCase sortType}}/quarter">Quarter</a></li>
{{/unless}}
{{#unless timeYear}}
<li><a href="/{{toLowerCase sortType}}/year">Year</a></li>
{{/unless}}
Expand Down
2 changes: 0 additions & 2 deletions client/global/style/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ html {
}

body {

line-height: 1.3rem;
font-family: 'Open Sans', sans-serif;
background-color: hsl(210, 20%, 98%);
}


a {
color: #399EE3;
&:visited {
Expand Down
2 changes: 1 addition & 1 deletion client/posts/view/viewPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ Template.post.helpers({
},
commentLink: function () {
"use strict";
return 'https://news.ycombinator.com/item?id=' + this.oldId;
return '/hn/' + this.oldId;
}
});
46 changes: 28 additions & 18 deletions server/hn/readHn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ var readHn = function (before) {
"use strict";
console.log('Reading the past ' + before + ' seconds of Hacker News');
var now = Math.floor(Date.now() / 1000);
var query = 'search?tags=story&numericFilters=created_at_i>';
query += (now - before) + ',created_at_i<' + now;
var listQuery = 'search?tags=story&numericFilters=created_at_i>';
listQuery += (now - before) + ',created_at_i<' + now;

hn.call(query, Meteor.bindEnvironment(
hn.call(listQuery, Meteor.bindEnvironment(
function (error, data) {
if (error) {
throw error;
Expand All @@ -25,29 +25,39 @@ var readHn = function (before) {
oldComments: parseInt(item.num_comments, 10),
};

Posts.upsert({
oldId: obj.oldId
},{
$set: obj
});
var postQuery = 'items/' + parseInt(item.objectID, 10);
hn.call(postQuery, Meteor.bindEnvironment(
function (error, post) {
if (error) {
throw error;
}
// save object comments too
obj.oldChildren = post.children;

Posts.upsert({
oldId: obj.oldId
},{
$set: obj
});
})
);
});
}, function (error) {
throw error;
})
);
};

Meteor.setInterval(function () {
Meteor.setInterval(function () { // 720 rph
"use strict";
readHn(60); // top for the minute
readHn(60 * 60); // top for the hour
readHn(24 * 60 * 60); // top for the day
readHn(7 * 24 * 60 * 60); // top for the week
}, 60 * 1000); // every minute
readHn(60 * 60); // hour - 21 requests
readHn(24 * 60 * 60); // day - 21 requests
}, 3.5 * 60 * 1000); // read every 3.5 minutes

Meteor.setInterval(function () {
Meteor.setInterval(function () { // 189 rph
"use strict";
readHn(Math.floor(Date.now() / 1000)); // top ever
readHn(7 * 24 * 60 * 60); // top for the week
}, 60 * 60 * 1000); // every hour
readHn(7 * 24 * 60 * 60); // week - 21 requests
readHn(31 * 24 * 60 * 60); // month - 21 requests
readHn(31 * 24 * 60 * 60); // year - 21 requests
readHn(Math.floor(Date.now() / 1000)); // ever - 21 requests
}, 20 * 60 * 1000); // read every 20 minutes
32 changes: 29 additions & 3 deletions server/posts/publishPosts.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
Meteor.publish('allPosts', function () {
"use strict";
var result = Posts.find({}, {
limit: 50
limit: 50,
fields: {
oldChildren: false
}
});
return result;
});

Meteor.publish('hnPost', function (id) {
"use strict";

console.log({
site: 'hn',
oldId: parseInt(id, 10)
});

return Posts.find({
site: 'hn',
oldId: parseInt(id, 10)
});
});

Meteor.publish('recentPosts', function () {
"use strict";
return Posts.find({}, {
sort: {
createdAt: -1
},
limit: 50
limit: 50,
fields: {
oldChildren: false
}
});
});

Expand All @@ -29,7 +49,10 @@ Meteor.publish('topPosts', function (start) {
sort: {
oldPoints: -1
},
limit: 50
limit: 50,
fields: {
oldChildren: false
}
});
});

Expand All @@ -39,6 +62,9 @@ Meteor.publish('hotPosts', function () {
limit: 50,
sort: {
heat: -1
},
fields: {
oldChildren: false
}
});
});
27 changes: 20 additions & 7 deletions shared/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ Router.map(function () {
}
});

this.route('hnPost', {
path: '/hn/:id',
template: 'listComments',
waitOn: function () {
var id = this.params.id.toLowerCase();
return Meteor.subscribe('hnPost', id);
},
data: function () {
var templateData = {
currentView: 'Hacker News',
post: Posts.findOne({}, {
reactive: false
})
};

return templateData;
}
});

/* disabled
this.route('newPost', {
path: '/new-post',
Expand Down Expand Up @@ -61,9 +80,6 @@ Router.map(function () {
month: function (start) {
return start.setFullYear(start.getFullYear(), start.getMonth() - 1);
},
quarter: function (start) {
return start.setFullYear(start.getFullYear(), start.getMonth() - 3);
},
year: function (start) {
return start.setFullYear(start.getFullYear() - 1);
},
Expand All @@ -72,8 +88,6 @@ Router.map(function () {
},
};

console.log('wat');

// figure out when
if (typeof actions[time] !== 'function') {
Router.go('/hot');
Expand All @@ -97,7 +111,6 @@ Router.map(function () {
'week',
'fortnight',
'month',
'quarter',
'year',
'ever'
];
Expand Down Expand Up @@ -212,7 +225,7 @@ Router.map(function () {
templateData.posts = shuffle(Posts.find({}, {
reactive: false
}).fetch());

return templateData;
}
});
Expand Down

0 comments on commit 47e92fa

Please sign in to comment.