Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graded! #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Build Process! yay, happy face. Have you looked into webpack, its like this on steroids
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand Down
3 changes: 2 additions & 1 deletion models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ var Article = mongoose.Schema({
data: {type: [mongoose.Schema.Types.Mixed], required: true}
}, {collection: 'Articles'});

module.exports = mongoose.model('Articles', Article);
//probably don't need to specify the collection twice
module.exports = mongoose.model('Articles', Article);
3 changes: 2 additions & 1 deletion password.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ module.exports = function(passport) {
callbackURL: auth.FACEBOOK_CALLBACK_URL
},
function(accessToken, refreshToken, profile, done) {
// Lol is this supposed to be here? The person below is right though
//This is not what you want to do here.
//Here you should search the connected DB if the user exists and load that in, or add it to db.
done(null, profile);
}
));
};
};
37 changes: 21 additions & 16 deletions react_components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ var DisplayEnum = Object.freeze({
DISPLAY_LOGIN: 2,
});

var endArticle = {
var endArticle = {
url: '#',
byline: '',
abstract: 'There are no more new articles',
headline: 'Check again tomorrow!',
date: '',
articleId: 0,
img: {
img: {
url: 'http://vignette1.wikia.nocookie.net/playstationallstarsfanfictionroyale/images/b/b3/Sad-Puppy-Face-Picture.jpg/revision/latest/scale-to-width-down/628?cb=20130529190645',
height: 480,
width: 628
}
width: 628
}
};

var noArticle = {
Expand All @@ -35,25 +35,26 @@ var noArticle = {
headline: 'Click the button to start browsing',
date: '',
articleId: 0,
img: {
img: {
url: 'http://www.mrwallpaper.com/wallpapers/Sad-Puppy.jpg',
height: 1200,
width: 1920,
}
}
}

var TinderTimesApp = React.createClass({
getInitialState: function() {
return {
user: {},
display: DisplayEnum.DISPLAY_LOGIN,
articles: [endArticle],
currArticle: 0,
};
return {
user: {},
display: DisplayEnum.DISPLAY_LOGIN,
articles: [endArticle],
currArticle: 0,
};
},

componentDidMount: function() {
this.loginFacebook();
// per the react docs componentDidMount should be void and not return anything so you don't need this
return null;
},

Expand Down Expand Up @@ -96,7 +97,7 @@ var TinderTimesApp = React.createClass({
this.loadArticlesFromServer(user._id);
if (user.savedArticles.length === 0) user.savedArticles = [noArticle];
this.setState({
display: DisplayEnum.DISPLAY_DASHBOARD,
display: DisplayEnum.DISPLAY_DASHBOARD,
user: user,
});
}.bind(this),
Expand Down Expand Up @@ -131,8 +132,10 @@ var TinderTimesApp = React.createClass({
url: '/api/article',
dataType: 'json',
cache: false,
//should this be a POST, you don't seem to be sending any new data
type: 'POST',
data: {
// shouldn't this be in req.user on the server?
'userId': mongoid,
},
success: function(serverArticles) {
Expand All @@ -147,6 +150,7 @@ var TinderTimesApp = React.createClass({

addArticleToUser: function(newArticle) {
console.log('new', newArticle);
//why data0, I feel like there could be a more descriptive variable name
var data0 = {'_id': this.state.user._id, newArticle: newArticle};
$.ajax({
url: '/api/user/newarticle/',
Expand Down Expand Up @@ -216,14 +220,15 @@ var TinderTimesApp = React.createClass({
var page;

// Decide whether to show login page, tinder news wheel, or dashboard
// this a great spot for react router
switch (this.state.display) {
case DisplayEnum.DISPLAY_DASHBOARD:
page = (
<div>
<Navbar displayName={this.state.user.displayName || ''} />
<div>
<TimeTinderBox pageChange={this.showTinderNews}
id={this.state.user._id || ''}
<TimeTinderBox pageChange={this.showTinderNews}
id={this.state.user._id || ''}
articles={this.state.user.savedArticles || []}
deleteUserArticle={this.deleteUserArticle}/>
</div>
Expand Down Expand Up @@ -266,4 +271,4 @@ var TinderTimesApp = React.createClass({
ReactDOM.render(
<TinderTimesApp />,
document.getElementById('content')
);
);
7 changes: 4 additions & 3 deletions react_components/carouselstuff/carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var Carousel = React.createClass({
componentWillReceiveProps: function (nextProps) {
this.depot.onNextProps(nextProps);
},

render: function () {
var angle = (2 * Math.PI) / this.state.figures.length;
var translateZ = -Layout[this.props.layout].distance(this.props.width,
Expand All @@ -67,6 +67,7 @@ var Carousel = React.createClass({
};

return (<figure key={i} style={Util.figureStyle(d)}>
{//css classes are normally hypen separated, but really anything but this below}
<div className="imagedashdiv" onMouseLeave={root.onMouseOut.bind(null,d.all_info.articleId)} onMouseEnter={root.onHover.bind(null,d.all_info.articleId)}>
<div className="imagedash">
<img className src={d.image} alt={i} height={"100%"} width={"100%"}/>
Expand All @@ -88,7 +89,7 @@ var Carousel = React.createClass({
</div>
</figure>);
});

if ((figures).length > 1) {
return (
<section className='react-3d-carousel'>
Expand All @@ -113,4 +114,4 @@ var Carousel = React.createClass({
}
}
});
module.exports = Carousel;
module.exports = Carousel;
22 changes: 11 additions & 11 deletions react_components/tinderNews.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var TinderNews = React.createClass({
},

getInitialState: function() {
return {
vw: size*document.documentElement.clientWidth/100,
hover: false,
}
return {
vw: size*document.documentElement.clientWidth/100,
hover: false,
}
},

updateVw: function() {
Expand All @@ -33,7 +33,7 @@ var TinderNews = React.createClass({
},

componentDidMount: function() {
window.addEventListener('resize', this.updateVw);
window.addEventListener('resize', this.updateVw);
},

handleNext: function() {
Expand All @@ -43,12 +43,12 @@ var TinderNews = React.createClass({
handleSave: function() {
var save;
if (this.props.currArticle+1 < this.props.articles.length)
save = this.props.currArticle;
save = this.props.currArticle;
this.handleNext();
console.log(save);
if (save+1) {
console.log('saving');
this.props.addSavedArticle(this.props.articles[save]);
console.log('saving');
this.props.addSavedArticle(this.props.articles[save]);
}
},

Expand Down Expand Up @@ -97,8 +97,8 @@ var TinderNews = React.createClass({
return (
<Motion key={i} style={style}>
{function (style) {
return <Article article={root.props.articles[i]}
style={style}
return <Article article={root.props.articles[i]}
style={style}
hovering={root.state.hover}
vw={root.state.vw/size}/>
}}
Expand All @@ -123,7 +123,7 @@ var TinderNews = React.createClass({
<Motion style={{height: spring(currHeight), width: spring(currWidth)}}>
{function(container) {
return (
<div className="slider-inner"
<div className="slider-inner"
style={container}
onMouseOver={root.changeHover}
onMouseOut={root.changeHover}>
Expand Down
12 changes: 4 additions & 8 deletions routes/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var request = require('request');
function processJSON(response) {
var newAll = [];
response.map(function(elem, i) {
// might be more efficent to do this as an else in your if(elem.media)
var selectImg = {
url: "http://www.trbimg.com/img-56b0e859/turbine/la-na-inside-iowa-caucus-precinct-20160202",
width: 2048,
Expand Down Expand Up @@ -43,8 +44,11 @@ Then it finds the user, and pushes the new article's id onto
user.article.
*/
router.post('/', function(req, res, next) {
// I don't think you need an exec unless you are chaining queries or using promises
Article.find().exec(function(findErr, articleModel) {
// I don't think you need to convert the id to an Object Id (it does the coercion for you
User.findOne({'_id': new ObjectId(req.body.userId)}).exec(function(userFindErr, userModel) {
// might want to clean up debugging logs
console.log(userModel);
if (findErr || userFindErr) {
res.send(findErr || userFindErr);
Expand Down Expand Up @@ -102,11 +106,3 @@ router.post('/', function(req, res, next) {

module.exports = router;









3 changes: 2 additions & 1 deletion routes/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Article = require('../models/article');
var ObjectId = require('mongoose').Types.ObjectId;

// logs you in through facebook and adds user if you never logged in before
// inconsitent tab spacing or weird tab to spaces issue?
router.get('/', function(req, res, next) {
if (req.session.passport) {
var username = req.session.passport.user.displayName;
Expand All @@ -26,4 +27,4 @@ router.get('/', function(req, res, next) {
}
});

module.exports = router;
module.exports = router;
13 changes: 8 additions & 5 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ var User = require('../models/user');
var Article = require('../models/article');
var ObjectId = require('mongoose').Types.ObjectId;

/*
/* I don't think the below is true :P
GET particular user. First it looks for the id in the User
collection, then finds (in the Article collection) all the
collection, then finds (in the Article collection) all the
articles whose ids are present in the user.articles array
*/
router.put('/', function(req, res, next) {
console.log(req.body);
User.update({
//why are you updating the user's id with itself?
'_id': new ObjectId(req.body.userId)
}, {$inc: {
'onArticle': req.body.seen
Expand All @@ -25,6 +26,7 @@ POST a new user.
*/
router.post('/', function(req, res, next) {
User.findOrCreate({
// why do you store this twice?
'userId': req.body.username,
'displayName': req.body.username
}, function(err, user, isNew) {
Expand All @@ -47,7 +49,7 @@ router.post('/newArticle/', function(req,res, next) {
console.log(body);
User.findOne({
'_id': new ObjectId(body._id)
}, function(err, user) {
}, function(err, user) {
user.savedArticles.push(body.newArticle);
user.save(function(err) {
if (err) {
Expand All @@ -67,9 +69,10 @@ POST deleting an article from user's list of article
router.delete('/readArticle/', function(req,res, next) {
User.findOne({
'_id': new ObjectId(req.body.userId)
}, function(err, user) {
}, function(err, user) {
console.log(req.body.articleId);

//nice use of filter
var data = user.savedArticles.filter(function(article) {
console.log(article.articleId, req.body.articleId);
return article.articleId != req.body.articleId;
Expand All @@ -88,4 +91,4 @@ router.delete('/readArticle/', function(req,res, next) {
})
});

module.exports = router;
module.exports = router;