Permalink
Browse files

Added user homepage. Ability to vote on threads. Moved Active Threads…

… to different page
  • Loading branch information...
SlashmanX committed Oct 29, 2013
1 parent f2ad542 commit fa29ca5a50ca9c4559c47176a60ba76e1008771e
View
@@ -0,0 +1,7 @@
+/public/*
+
+*.jade
+
+/.git/*
+
+/.idea/*
View
31 app.js
@@ -117,8 +117,8 @@ passport.use(new RedditStrategy({
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
-var bundle = browserify().use(browserijade(__dirname +'/views/partials'));
-bundle.addEntry(__dirname +'/public/javascripts/app.js');
+var bundle = browserify().use(browserijade(__dirname + '/views/partials'));
+bundle.addEntry(__dirname + '/public/javascripts/app.js');
app.use(bundle);
app.use(express.favicon());
app.use(express.logger('dev'));
@@ -127,7 +127,7 @@ app.use(express.methodOverride());
app.use(express.cookieParser('I am not wearing any pants'));
app.use(express.session({
cookie: {
- maxAge: new Date(Date.now() + 3600000)
+ maxAge: new Date(Date.now() + 3600000 * 24 * 365) // 3600000ms = 1 day
},
key: 'express.sid',
store: new MongoStore({db: db})
@@ -162,11 +162,14 @@ app.get('/', function(req, res) {
else {
res.render('home', {title: 'Home', threads: [], user: req.user});
}
- /*getActiveThreads({limit: 10, time: ACTIVE_THREAD_TIME_LIMIT}, function(err, data) {
- var active = data.data.data;
- res.render('home', {title: 'Home', activeThreads: active, user: req.user });
- })*/
});
+
+app.get('/active/', function(req, res) {
+ getActiveThreads({limit: 10, time: ACTIVE_THREAD_TIME_LIMIT}, function(err, data) {
+ var active = data.data.data;
+ res.render('active', {title: 'Home', threads: active, user: req.user });
+ })
+})
app.get('/r/:subreddit/', function(req, res) {
res.render('stream', { title: req.params.subreddit, subreddit: req.params.subreddit, user: req.user });
});
@@ -231,7 +234,17 @@ app.post('/downvote/thread/:threadid/', function(req, res){
else
res.send(err, 403);
})
-})
+});
+
+app.post('/unvote/thread/:threadid/', function(req, res){
+
+ voteThing({id: 't3_'+ req.params.threadid, dir: 0, user: req.user}, function(err, status) {
+ if(!err)
+ res.send('ok', 200);
+ else
+ res.send(err, 403);
+ })
+});
/*var parser = JSONStream.parse() //emit parts that match this path (any element of the rows array)
var req = request({url: 'http://stream.redditanalytics.com'})
var logger = es.mapSync(function (data) {
@@ -266,7 +279,7 @@ function getThreadAndComments(data, callback) {
callback(error, null);
}
else {
- var data = JSON.parse(body)
+ var data = JSON.parse(body);
var topic_info = data[0].data.children[0].data;
var comments = data[1].data.children; //newest first
View
@@ -0,0 +1,14 @@
+var mongoose = require('mongoose');
+var Schema = mongoose.Schema;
+var ObjectId = Schema.ObjectId;
+
+var subredditSchema = new Schema({
+ id: String,
+ name: String,
+ description: String,
+ over18: Boolean,
+ link: String,
+ lastUpdated: { type : Date, default: Date.now }
+});
+
+module.exports = mongoose.model('Subreddit', subredditSchema);
View
@@ -18,27 +18,60 @@ socket.on('comment', function(data) {
})
$('span.upvote').on('click', function() {
+ var upvoter = $(this);
var parent_row = $($(this).closest('.row[id]'))[0];
var thread_id = ($(parent_row).attr('id'));
- $.ajax({
- type: "POST",
- url: "/upvote/thread/"+ thread_id +"/",
- success: function() {
- console.log('upvoted');
- }
- })
+ if(upvoter.hasClass('liked'))
+ {
+ $.ajax({
+ type: "POST",
+ url: "/unvote/thread/"+ thread_id +"/",
+ success: function() {
+ upvoter.removeClass('liked', 400);
+ $('#'+ thread_id +' .score').removeClass('liked', 400);
+ }
+ });
+ }
+ else {
+ $.ajax({
+ type: "POST",
+ url: "/upvote/thread/"+ thread_id +"/",
+ success: function() {
+ upvoter.addClass('liked', 400);
+ $('#'+ thread_id +' .downvote').removeClass('disliked', 400);
+ $('#'+ thread_id +' .score').removeClass('disliked', 400);
+ $('#'+ thread_id +' .score').addClass('liked', 400);
+ }
+ })
+ }
})
$('span.downvote').on('click', function() {
+ var downvoter = $(this);
var parent_row = $($(this).closest('.row[id]'))[0];
var thread_id = ($(parent_row).attr('id'));
-
- $.ajax({
- type: "POST",
- url: "/downvote/thread/"+ thread_id +"/",
- success: function() {
- console.log('downvoted');
- }
- })
+ if(downvoter.hasClass('disliked'))
+ {
+ $.ajax({
+ type: "POST",
+ url: "/unvote/thread/"+ thread_id +"/",
+ success: function() {
+ downvoter.removeClass('disliked', 400);
+ $('#'+ thread_id +' .score').removeClass('disliked', 400);
+ }
+ });
+ }
+ else {
+ $.ajax({
+ type: "POST",
+ url: "/downvote/thread/"+ thread_id +"/",
+ success: function() {
+ downvoter.addClass('disliked', 400);
+ $('#'+ thread_id +' .upvote').removeClass('liked', 400);
+ $('#'+ thread_id +' .score').removeClass('liked', 400);
+ $('#'+ thread_id +' .score').addClass('disliked', 400);
+ }
+ })
+ }
})

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -26,6 +26,18 @@ body {
color: @downvote_color;
}
}
+
+.score {
+ font-size: 30px;
+ color: #D0D0D0;
+ &.liked {
+ color: @upvote_color;
+ }
+
+ &.disliked {
+ color: @downvote_color;
+ }
+}
.upvote {
.vote;
.glyphicon-chevron-up;
View
@@ -0,0 +1,8 @@
+extends layout
+
+block content
+ h3 Active Threads
+ .active-threads
+ - each thread in threads
+ - thread.score = thread.ups - thread.downs
+ include partials/homepage_thread.jade
View
@@ -5,7 +5,7 @@ head
meta(name='viewport', content='width=device-width, initial-scale=1.0')
meta(name='description', content='')
meta(name='author', content='')
- title #{title} - Reddit Stream
+ title #{title} - Reddit Live
script(src="/socket.io/socket.io.js")
script var socket = io.connect()
script!= javascript
@@ -18,13 +18,13 @@ body
span.icon-bar
span.icon-bar
span.icon-bar
- a.navbar-brand(href='#') Reddit Stream
+ a.navbar-brand(href='#') Reddit Live
.navbar-collapse.collapse
ul.nav.navbar-nav
li.active
a(href='#') Home
li
- a(href='#') Active Threads
+ a(href='/active/') Active Threads
li
a(href='#') Link
li.dropdown
@@ -52,6 +52,7 @@ body
block content
script(src='/javascripts/lib/jquery-1.10.2.min.js')
+ script(src='/javascripts/lib/jquery-ui-1.10.3.custom.min.js')
script(src='/javascripts/lib/bootstrap.min.js')
script(src="/browserify.js")
script(src='/javascripts/app.js')
@@ -0,0 +1,17 @@
+.row(id=thread.id)
+ .col-md-1
+ .row
+ .col-md-12(style="text-align:center; padding:5px")
+ span.upvote(class=thread.likes ? 'liked' : '')
+ .row
+ .col-md-12
+ span.score(class=thread.likes ? 'liked' : thread.likes==false ? 'disliked' : '')=thread.score
+ .row
+ .col-md-12(style="text-align:center; padding: 5px")
+ span.downvote(class= thread.likes==false ? 'disliked' : '')
+
+ .col-md-10
+ .panel.panel-default
+ .panel-heading Posted in <strong><a href="http://reddit.com/r/#{thread.subreddit}">#{thread.subreddit}</a></strong> by <strong>#{thread.author}</strong><span class='pull-right'>#{moment.unix(thread.created_utc).fromNow()}</span>
+ .panel-body <a href = "#{thread.url}">#{thread.title}</a><a class = 'pull-right' href = '#{thread.permalink}'>View Live</a>
+ .panel-footer #{thread.score} pts | #{thread.num_comments} comments | <a href = "http://reddit.com#{thread.permalink}" target='_blank'>View On Reddit</a>

0 comments on commit fa29ca5

Please sign in to comment.