mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Compare commits
5 Commits
engage_mic
...
aditya
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83052f0a80 | ||
|
|
cc20e30990 | ||
|
|
6dbca16ace | ||
|
|
12938e8e9a | ||
|
|
84ad61b954 |
@@ -8,7 +8,6 @@
|
|||||||
},
|
},
|
||||||
"functions": {
|
"functions": {
|
||||||
"predeploy": [
|
"predeploy": [
|
||||||
"npm --prefix \"$RESOURCE_DIR\" run lint"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hosting": {
|
"hosting": {
|
||||||
|
|||||||
@@ -1,226 +1,99 @@
|
|||||||
/* eslint-disable prefer-arrow-callback */
|
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
const admin = require('firebase-admin');
|
const admin = require('firebase-admin');
|
||||||
const { db } = require('../util/admin');
|
const { db } = require('../util/admin');
|
||||||
|
|
||||||
|
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
|
|
||||||
const newPost = {
|
const newPost = {
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
userHandle: req.user.handle,
|
userHandle: req.userData.handle,
|
||||||
userImage: req.body.userImage,
|
userImage: req.body.userImage,
|
||||||
userID: req.user.uid,
|
userID: req.userData.userId,
|
||||||
microBlogTitle: req.body.microBlogTitle,
|
microBlogTitle: req.body.microBlogTitle,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
likeCount: 0,
|
likeCount: 0,
|
||||||
commentCount: 0,
|
commentCount: 0,
|
||||||
microBlogTopics: req.body.microBlogTopics
|
microBlogTopics: req.body.microBlogTopics
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
admin.firestore().collection('posts').add(newPost)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
doc.update({postId: doc.id})
|
|
||||||
const resPost = newPost;
|
const resPost = newPost;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something went wrong'});
|
return res.status(500).json({ error: 'something is wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
|
||||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
|
||||||
post_query.get()
|
|
||||||
.then(function(myPosts) {
|
|
||||||
let posts = [];
|
|
||||||
myPosts.forEach(function(doc) {
|
|
||||||
posts.push(doc.data());
|
|
||||||
});
|
|
||||||
return res.status(200).json(posts);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
|
||||||
|
|
||||||
})
|
exports.getPost = (req, res) => {
|
||||||
.catch(function(err) {
|
let postData = {};
|
||||||
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
db.doc(`/posts/${req.params.postId}`)
|
||||||
});
|
.get()
|
||||||
};
|
|
||||||
|
|
||||||
exports.getallPosts = (req, res) => {
|
|
||||||
var post_query = admin.firestore().collection("posts");
|
|
||||||
post_query.get()
|
|
||||||
.then(function(allPosts) {
|
|
||||||
let posts = [];
|
|
||||||
allPosts.forEach(function(doc) {
|
|
||||||
posts.push(doc.data());
|
|
||||||
});
|
|
||||||
return res.status(200).json(posts);
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return res.status(200).json("Successfully retrieved every post from database.");
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
return res.status(500).json("Failed to retrieve posts from database.", err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.quoteWithPost = (req, res) => {
|
|
||||||
|
|
||||||
let quoteData;
|
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
|
||||||
where('userHandle', '==', req.user.handle).
|
|
||||||
where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
if(doc.exists) {
|
if (!doc.exists) {
|
||||||
quoteData = doc.data();
|
return res.status(404).json({error: 'Post is not found'});
|
||||||
return quoteDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
if(data.empty) {
|
|
||||||
return admin.firestore().collection('quote').add({
|
|
||||||
postId : req.params.postId,
|
|
||||||
userHandle : req.user.handle,
|
|
||||||
quotePost : req.body.quotePost
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return admin.firestore().collection('posts').add({
|
|
||||||
quoteData,
|
|
||||||
quoteUser : req.user.handle,
|
|
||||||
quotePost : req.body.quotePost,
|
|
||||||
quotedAt : new Date().toISOString()
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
postData = doc.data();
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
postData.postId = doc.id;
|
||||||
}
|
return res.status(200).json(postData);
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return res.status(500).json({error: err});
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.quoteWithoutPost = (req, res) => {
|
|
||||||
let quoteData;
|
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
|
||||||
where('userHandle', '==', req.user.handle).
|
|
||||||
where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
quoteData = doc.data();
|
|
||||||
return quoteDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
if(data.empty) {
|
|
||||||
return admin.firestore().collection('quote').add({
|
|
||||||
postId : req.params.postId,
|
|
||||||
userHandle : req.user.handle,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return admin.firestore().collection('posts').add({
|
|
||||||
quoteData,
|
|
||||||
quoteUser : req.user.handle,
|
|
||||||
quotedAt : new Date().toISOString()
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Something is wrong'});
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.likePost = (req, res) => {
|
exports.likePost = (req, res) => {
|
||||||
let postData;
|
|
||||||
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.userData.handle)
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
.where('postId', '==', req.params.postId).limit(1);
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||||
|
|
||||||
postDoc.get()
|
likeDoc.get()
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
postData = doc.data();
|
|
||||||
return likeDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.empty) {
|
if (data.empty) {
|
||||||
return admin.firestore().collection('likes').add({
|
admin.firestore().collection('likes').add({
|
||||||
postId : req.params.postId,
|
postId : req.params.postId,
|
||||||
userHandle: req.user.handle
|
userHandle: req.userData.handle
|
||||||
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
postData.likeCount++;
|
return postDoc.update({likeCount : firebase.firestore.FieldValue.increment(1) })
|
||||||
return postDoc.update({likeCount : postData.likeCount})
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(200).json(postData);
|
return res.status(200).json(postDoc);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return res.status(400).json({error: 'Post has already been liked.'})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Something is wrong'});
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.unlikePost = (req, res) => {
|
exports.unlikePost = (re, res) => {
|
||||||
|
|
||||||
let postData;
|
let postData;
|
||||||
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.userData.handle)
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
.where('postId', '==', req.params.postId).limit(1);
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||||
|
|
||||||
postDoc.get()
|
likeDoc.get()
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
postData = doc.data();
|
|
||||||
return likeDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
if (data.empty) {
|
||||||
|
return res.status(400).json({ error: 'Post cannot be unliked because it is not liked at the moment.' });
|
||||||
|
} else {
|
||||||
return db
|
return db
|
||||||
.doc(`/likes/${data.docs[0].id}`)
|
.doc(`/likes/${data.docs[0].id}`)
|
||||||
.delete()
|
.delete()
|
||||||
@@ -231,7 +104,7 @@ exports.unlikePost = (req, res) => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
res.status(200).json(postData);
|
res.status(200).json(postData);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -240,6 +113,61 @@ exports.unlikePost = (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.quotePost = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
|
||||||
|
const likeDoc = admin.firestore().collection('posts').where('postId', '==', req.params.postId).limit(1);
|
||||||
|
|
||||||
|
const quotedPost = {
|
||||||
|
quotingUser : req.userData.handle,
|
||||||
|
quotedAt: new Date().toISOString(),
|
||||||
|
body: req.body.body,
|
||||||
|
|
||||||
|
}
|
||||||
|
admin.firestore().collection('posts').add(quotedPost)
|
||||||
|
.then((doc) => {
|
||||||
|
const resPost = quotedPost;
|
||||||
|
resPost.postId = doc.id;
|
||||||
|
return res.status(200).json(resPost);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.getallPostsforFeed = (req, res) => {
|
||||||
|
admin.firestore().collection('posts').get()
|
||||||
|
.then((data) => {
|
||||||
|
let posts = [];
|
||||||
|
|
||||||
|
data.forEach(function(doc) {
|
||||||
|
posts.push( {
|
||||||
|
microBlogs: doc.data(),
|
||||||
|
id: doc.id,
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
return res.status(200).json(posts);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({error: 'Failed to fetch all posts written by all other users.'})
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getallPostsforUser = (req, res) => {
|
||||||
|
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
|
||||||
|
.then((data) => {
|
||||||
|
let posts = [];
|
||||||
|
data.forEach(function(doc) {
|
||||||
|
posts.push(doc.data());
|
||||||
|
});
|
||||||
|
return res.status(200).json(posts);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,93 +1,53 @@
|
|||||||
|
/* eslint-disable promise/always-return */
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
exports.putTopic = (req, res) => {
|
exports.putTopic = (req, res) => {
|
||||||
let new_following = [];
|
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
|
||||||
userRef
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
new_following = doc.data().followedTopics;
|
|
||||||
new_following.push(req.body.following);
|
|
||||||
|
|
||||||
// add stuff
|
const newTopic = {
|
||||||
userRef
|
topic: req.body.topic
|
||||||
.set({ followedTopics: new_following }, { merge: true })
|
};
|
||||||
.then(doc => {
|
|
||||||
return res
|
admin.firestore().collection('topics').add(newTopic)
|
||||||
.status(201)
|
.then((doc) => {
|
||||||
.json({ message: `Following ${req.body.following}` });
|
const resTopic = newTopic;
|
||||||
})
|
newTopic.topicId = doc.id;
|
||||||
.catch(err => {
|
return res.status(200).json(resTopic);
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(200).json({ message: "OK" });
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
return res.status(500).json({ err });
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: 'something is wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getAllTopics = (req, res) => {
|
exports.getAllTopics = (req, res) => {
|
||||||
admin
|
admin.firestore().collection('topics').get()
|
||||||
.firestore()
|
.then((data) => {
|
||||||
.collection("topics")
|
let topics = [];
|
||||||
.get()
|
data.forEach(function(doc) {
|
||||||
.then(data => {
|
topics.push(doc.data());
|
||||||
let topics = [];
|
|
||||||
data.forEach(function(doc) {
|
|
||||||
topics.push({
|
|
||||||
topic: doc.data().topic,
|
|
||||||
id: doc.id
|
|
||||||
});
|
});
|
||||||
});
|
return res.status(200).json(topics);
|
||||||
return res.status(200).json(topics);
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({error: 'Failed to fetch all topics.'})
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: "Failed to fetch all topics." });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteTopic = (req, res) => {
|
exports.deleteTopic = (req, res) => {
|
||||||
let new_following = [];
|
// TODO: handle add and delete by topic id
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||||
userRef
|
topic.get().then((doc) => {
|
||||||
.get()
|
if (!doc.exists) {
|
||||||
.then(doc => {
|
return res.status(404).json({error: 'Topic not found'});
|
||||||
new_following = doc.data().followedTopics;
|
} else {
|
||||||
// remove username from array
|
return topic.delete();
|
||||||
new_following.forEach(function(follower, index) {
|
|
||||||
if (follower === `${req.body.unfollow}`) {
|
|
||||||
new_following.splice(index, 1);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// update database
|
|
||||||
userRef
|
|
||||||
.set({ followedTopics: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(202)
|
|
||||||
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(200).json({ message: "ok" });
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.then(() => {
|
||||||
return res.status(500).json({ err });
|
res.json({ message: 'Topic successfully deleted!'});
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getUserTopics = (req, res) => {
|
|
||||||
let data = [];
|
|
||||||
db.doc(`/users/${req.body.handle}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
data = doc.data().followedTopics;
|
|
||||||
return res.status(200).json({ data });
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
return res.status(500).json({ err });
|
console.error(err);
|
||||||
});
|
return res.status(500).json({error: 'Failed to delete topic.'})
|
||||||
};
|
})
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable promise/catch-or-return */
|
/* eslint-disable promise/catch-or-return */
|
||||||
|
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
const config = require("../util/config");
|
const config = require("../util/config");
|
||||||
const { validateUpdateProfileInfo } = require("../util/validator");
|
const { validateUpdateProfileInfo } = require("../util/validator");
|
||||||
@@ -6,6 +7,8 @@ const { validateUpdateProfileInfo } = require("../util/validator");
|
|||||||
const firebase = require("firebase");
|
const firebase = require("firebase");
|
||||||
firebase.initializeApp(config);
|
firebase.initializeApp(config);
|
||||||
|
|
||||||
|
var handle2Email = new Map();
|
||||||
|
|
||||||
exports.signup = (req, res) => {
|
exports.signup = (req, res) => {
|
||||||
const newUser = {
|
const newUser = {
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
@@ -54,7 +57,7 @@ exports.signup = (req, res) => {
|
|||||||
|
|
||||||
db.doc(`/users/${newUser.handle}`)
|
db.doc(`/users/${newUser.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then((doc) => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
@@ -64,28 +67,26 @@ exports.signup = (req, res) => {
|
|||||||
.auth()
|
.auth()
|
||||||
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
userId = data.user.uid;
|
userId = data.user.uid;
|
||||||
return data.user.getIdToken();
|
return data.user.getIdToken();
|
||||||
})
|
})
|
||||||
.then(idToken => {
|
.then((idToken) => {
|
||||||
token = idToken;
|
token = idToken;
|
||||||
const defaultImageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/no-img.png?alt=media`;
|
|
||||||
const userCred = {
|
const userCred = {
|
||||||
email: newUser.email,
|
email: newUser.email,
|
||||||
handle: newUser.handle,
|
handle: newUser.handle,
|
||||||
createdAt: newUser.createdAt,
|
createdAt: newUser.createdAt,
|
||||||
userId,
|
userId,
|
||||||
followedTopics: [],
|
followedTopics: []
|
||||||
imageUrl: defaultImageUrl,
|
|
||||||
verified: false
|
|
||||||
};
|
};
|
||||||
|
handle2Email.set(userCred.handle, userCred.email);
|
||||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(201).json({ token });
|
return res.status(201).json({ token });
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/email-already-in-use") {
|
if (err.code === "auth/email-already-in-use") {
|
||||||
return res.status(500).json({ email: "This email is already taken." });
|
return res.status(500).json({ email: "This email is already taken." });
|
||||||
@@ -97,6 +98,7 @@ exports.signup = (req, res) => {
|
|||||||
exports.login = (req, res) => {
|
exports.login = (req, res) => {
|
||||||
const user = {
|
const user = {
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
|
handle: req.body.handle,
|
||||||
password: req.body.password
|
password: req.body.password
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,174 +107,80 @@ exports.login = (req, res) => {
|
|||||||
|
|
||||||
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
|
|
||||||
// Checks if email/username field is empty
|
// Email check
|
||||||
if (user.email.trim() === "") {
|
if (user.email.trim() === "") {
|
||||||
errors.email = "Email must not be blank.";
|
errors.email = "Email must not be blank.";
|
||||||
}
|
}
|
||||||
|
else if (!user.email.match(emailRegEx)) {
|
||||||
|
user.email = handle2Email.get(user.email);
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if password field is empty
|
// Password check
|
||||||
if (user.password.trim() === "") {
|
if (user.password.trim() === "") {
|
||||||
errors.password = "Password must not be blank.";
|
errors.password = "Password must not be blank.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if any of the above two errors were found
|
// Checking if any errors have been raised
|
||||||
if (Object.keys(errors).length > 0) {
|
if (Object.keys(errors).length > 0) {
|
||||||
return res.status(400).json(errors);
|
return res.status(400).json(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Email/username field is username since it's not in email format
|
firebase
|
||||||
if (!user.email.match(emailRegEx)) {
|
.auth()
|
||||||
var userDoc = db.collection("users").doc(`${user.email}`);
|
.signInWithEmailAndPassword(user.email, user.password)
|
||||||
userDoc
|
.then((data) => {
|
||||||
.get()
|
return data.user.getIdToken();
|
||||||
.then(function(doc) {
|
})
|
||||||
if (doc.exists) {
|
.then((token) => {
|
||||||
user.email = doc.data().email;
|
return res.status(200).json({ token });
|
||||||
} else {
|
})
|
||||||
return res
|
.catch((err) => {
|
||||||
.status(403)
|
console.error(err);
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
if (err.code === "auth/wrong-password" || err.code === "auth/invalid-email" || err.code === "auth/user-not-found") {
|
||||||
}
|
return res
|
||||||
return;
|
.status(403)
|
||||||
})
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
|
}
|
||||||
|
return res.status(500).json({ error: err.code });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//Deletes user account
|
||||||
|
exports.deleteUser = (req, res) => {
|
||||||
|
var currentUser;
|
||||||
|
|
||||||
|
firebase.auth().onAuthStateChanged(function(user) {
|
||||||
|
currentUser = user;
|
||||||
|
if (currentUser) {
|
||||||
|
/*db.collection("users").doc(`${currentUser.handle}`).delete()
|
||||||
.then(function() {
|
.then(function() {
|
||||||
firebase
|
res.status(200).send("Removed user from database.");
|
||||||
.auth()
|
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
|
||||||
.then(data => {
|
|
||||||
return data.user.getIdToken();
|
|
||||||
})
|
|
||||||
.then(token => {
|
|
||||||
return res.status(200).json({ token });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
if (
|
|
||||||
err.code === "auth/user-not-found" ||
|
|
||||||
err.code === "auth/invalid-email" ||
|
|
||||||
err.code === "auth/wrong-password"
|
|
||||||
) {
|
|
||||||
return res
|
|
||||||
.status(403)
|
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
|
||||||
}
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
if (!doc.exists) {
|
res.status(500).send("Failed to remove user from database.", err);
|
||||||
return res
|
});*/
|
||||||
.status(403)
|
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
//let ref = db.collection('users');
|
||||||
}
|
//let userDoc = ref.where('userId', '==', currentUser.uid).get();
|
||||||
return res.status(500).send(err);
|
//userDoc.ref.delete();
|
||||||
});
|
|
||||||
}
|
currentUser.delete()
|
||||||
// Email/username field is username
|
.then(function() {
|
||||||
else {
|
console.log("User successfully deleted.");
|
||||||
firebase
|
res.status(200).send("Deleted user.");
|
||||||
.auth()
|
return;
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
|
||||||
.then(data => {
|
|
||||||
return data.user.getIdToken();
|
|
||||||
})
|
})
|
||||||
.then(token => {
|
.catch(function(err) {
|
||||||
return res.status(200).json({ token });
|
console.log("Error deleting user.", err);
|
||||||
})
|
res.status(500).send("Failed to delete user.");
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
if (
|
|
||||||
err.code === "auth/user-not-found" ||
|
|
||||||
err.code === "auth/invalid-email" ||
|
|
||||||
err.code === "auth/wrong-password"
|
|
||||||
) {
|
|
||||||
return res
|
|
||||||
.status(403)
|
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
|
||||||
}
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
else {
|
||||||
|
console.log("Cannot get user.");
|
||||||
//Deletes user account and all associated data
|
res.status(500).send("Cannot get user.");
|
||||||
exports.deleteUser = (req, res) => {
|
}
|
||||||
// Get the profile image filename
|
});
|
||||||
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
|
||||||
let imageFileName;
|
|
||||||
req.userData.imageUrl
|
|
||||||
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
|
|
||||||
: (imageFileName = "no-img.png");
|
|
||||||
|
|
||||||
const userId = req.userData.userId;
|
|
||||||
let errors = {};
|
|
||||||
|
|
||||||
function thenFunction(data) {
|
|
||||||
console.log(`${data} data for ${req.userData.handle} has been deleted.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function catchFunction(data, err) {
|
|
||||||
console.error(err);
|
|
||||||
errors[data] = err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deletes user from authentication
|
|
||||||
let auth = admin.auth().deleteUser(userId);
|
|
||||||
|
|
||||||
// Deletes database data
|
|
||||||
let data = db
|
|
||||||
.collection("users")
|
|
||||||
.doc(`${req.user.handle}`)
|
|
||||||
.delete();
|
|
||||||
|
|
||||||
// Deletes any custom profile image
|
|
||||||
let image;
|
|
||||||
if (imageFileName !== "no-img.png") {
|
|
||||||
image = admin
|
|
||||||
.storage()
|
|
||||||
.bucket()
|
|
||||||
.file(imageFileName)
|
|
||||||
.delete();
|
|
||||||
} else {
|
|
||||||
image = Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deletes all users posts
|
|
||||||
let posts = db
|
|
||||||
.collection("posts")
|
|
||||||
.where("userHandle", "==", req.user.handle)
|
|
||||||
.get()
|
|
||||||
.then(query => {
|
|
||||||
query.forEach(snap => {
|
|
||||||
snap.ref.delete();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
|
|
||||||
let promises = [
|
|
||||||
auth.then(thenFunction("auth")).catch(err => catchFunction("auth", err)),
|
|
||||||
data.then(thenFunction("data")).catch(err => catchFunction("data", err)),
|
|
||||||
image.then(thenFunction("image")).catch(err => catchFunction("image", err)),
|
|
||||||
posts.then(thenFunction("posts")).catch(err => catchFunction("image", err))
|
|
||||||
];
|
|
||||||
|
|
||||||
// Wait for all promises to resolve
|
|
||||||
let waitPromise = Promise.all(promises);
|
|
||||||
|
|
||||||
waitPromise
|
|
||||||
.then(() => {
|
|
||||||
if (Object.keys(errors) > 0) {
|
|
||||||
return res.status(500).json(errors);
|
|
||||||
} else {
|
|
||||||
return res.status(200).json({
|
|
||||||
message: `All data for ${req.userData.handle} has been deleted.`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ error: err });
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns all data in the database for the user who is currently signed in
|
// Returns all data in the database for the user who is currently signed in
|
||||||
@@ -280,10 +188,10 @@ exports.getProfileInfo = (req, res) => {
|
|||||||
db.collection("users")
|
db.collection("users")
|
||||||
.doc(req.user.handle)
|
.doc(req.user.handle)
|
||||||
.get()
|
.get()
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
return res.status(200).json(data.data());
|
return res.status(200).json(data.data());
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json(err);
|
return res.status(500).json(err);
|
||||||
});
|
});
|
||||||
@@ -291,6 +199,8 @@ exports.getProfileInfo = (req, res) => {
|
|||||||
|
|
||||||
// Updates the data in the database of the user who is currently logged in
|
// Updates the data in the database of the user who is currently logged in
|
||||||
exports.updateProfileInfo = (req, res) => {
|
exports.updateProfileInfo = (req, res) => {
|
||||||
|
// TODO: Add functionality for adding/updating profile images
|
||||||
|
|
||||||
// Data validation
|
// Data validation
|
||||||
const { valid, errors, profileData } = validateUpdateProfileInfo(req);
|
const { valid, errors, profileData } = validateUpdateProfileInfo(req);
|
||||||
if (!valid) return res.status(400).json(errors);
|
if (!valid) return res.status(400).json(errors);
|
||||||
@@ -301,11 +211,13 @@ exports.updateProfileInfo = (req, res) => {
|
|||||||
.set(profileData, { merge: true })
|
.set(profileData, { merge: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`${req.user.handle}'s profile info has been updated.`);
|
console.log(`${req.user.handle}'s profile info has been updated.`);
|
||||||
return res.status(201).json({
|
return res
|
||||||
general: `${req.user.handle}'s profile info has been updated.`
|
.status(201)
|
||||||
});
|
.json({
|
||||||
|
general: `${req.user.handle}'s profile info has been updated.`
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
error: "Error updating profile data"
|
error: "Error updating profile data"
|
||||||
@@ -317,15 +229,14 @@ exports.getUserDetails = (req, res) => {
|
|||||||
let userData = {};
|
let userData = {};
|
||||||
db.doc(`/users/${req.body.handle}`)
|
db.doc(`/users/${req.body.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then((doc) => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
userData = doc.data();
|
userData = doc.data();
|
||||||
return res.status(200).json({ userData });
|
return res.status(200).json({userData});
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({ error: "User not found." });
|
return res.status(400).json({error: "User not found."})
|
||||||
}
|
}})
|
||||||
})
|
.catch((err) => {
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
@@ -335,160 +246,17 @@ exports.getAuthenticatedUser = (req, res) => {
|
|||||||
let credentials = {};
|
let credentials = {};
|
||||||
db.doc(`/users/${req.user.handle}`)
|
db.doc(`/users/${req.user.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then((doc) => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
credentials = doc.data();
|
credentials = doc.data();
|
||||||
return res.status(200).json({ credentials });
|
return res.status(200).json({credentials});
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({ error: "User not found." });
|
return res.status(400).json({error: "User not found."})
|
||||||
}
|
}})
|
||||||
})
|
.catch((err) => {
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
|
||||||
// Must be run by the Admin user
|
|
||||||
exports.verifyUser = (req, res) => {
|
|
||||||
if (req.userData.handle !== "Admin") {
|
|
||||||
return res.status(403).json({ error: "This must be done as Admin" });
|
|
||||||
}
|
|
||||||
|
|
||||||
db.doc(`/users/${req.body.user}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
if (doc.exists) {
|
|
||||||
let verifiedUser = doc.data();
|
|
||||||
verifiedUser.verified = true;
|
|
||||||
return db
|
|
||||||
.doc(`/users/${req.body.user}`)
|
|
||||||
.set(verifiedUser, { merge: true });
|
|
||||||
} else {
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ error: `User ${req.body.user} was not found` });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `${req.body.user} is now verified` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Unverifies the user sent to the request
|
|
||||||
// Must be run by admin
|
|
||||||
exports.unverifyUser = (req, res) => {
|
|
||||||
if (req.userData.handle !== "Admin") {
|
|
||||||
return res.status(403).json({ error: "This must be done as Admin" });
|
|
||||||
}
|
|
||||||
|
|
||||||
db.doc(`/users/${req.body.user}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
if (doc.exists) {
|
|
||||||
let unverifiedUser = doc.data();
|
|
||||||
unverifiedUser.verified = false;
|
|
||||||
return db
|
|
||||||
.doc(`/users/${req.body.user}`)
|
|
||||||
.set(unverifiedUser, { merge: true });
|
|
||||||
} else {
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ error: `User ${req.body.user} was not found` });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `${req.body.user} is no longer verified` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.getUserHandles = (req, res) => {
|
|
||||||
db.doc(`/users/${req.body.userHandle}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
if (doc.exists) {
|
|
||||||
let userHandle = doc.data().handle;
|
|
||||||
return res.status(200).json(userHandle);
|
|
||||||
} else {
|
|
||||||
return res.status(404).json({ error: "user not found" });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: "Failed to get all user handles." });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.addSubscription = (req, res) => {
|
|
||||||
let new_following = [];
|
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
|
||||||
userRef.get().then(doc => {
|
|
||||||
new_following = doc.data().following;
|
|
||||||
new_following.push(req.body.following);
|
|
||||||
|
|
||||||
// add stuff
|
|
||||||
userRef
|
|
||||||
.set({ following: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `Following ${req.body.following}` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getSubs = (req, res) => {
|
|
||||||
let data = [];
|
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
data = doc.data().following;
|
|
||||||
return res.status(200).json({ data });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.removeSub = (req, res) => {
|
|
||||||
let new_following = [];
|
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
|
||||||
userRef.get().then(doc => {
|
|
||||||
new_following = doc.data().following;
|
|
||||||
// remove username from array
|
|
||||||
new_following.forEach(function(follower, index) {
|
|
||||||
if (follower === `${req.body.unfollow}`) {
|
|
||||||
new_following.splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// update database
|
|
||||||
userRef
|
|
||||||
.set({ following: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(202)
|
|
||||||
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -16,13 +16,7 @@ const {
|
|||||||
login,
|
login,
|
||||||
signup,
|
signup,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
updateProfileInfo,
|
updateProfileInfo
|
||||||
verifyUser,
|
|
||||||
unverifyUser,
|
|
||||||
getUserHandles,
|
|
||||||
addSubscription,
|
|
||||||
getSubs,
|
|
||||||
removeSub
|
|
||||||
} = require("./handlers/users");
|
} = require("./handlers/users");
|
||||||
|
|
||||||
// Adds a user to the database and registers them in firebase with
|
// Adds a user to the database and registers them in firebase with
|
||||||
@@ -35,9 +29,9 @@ app.post("/signup", signup);
|
|||||||
app.post("/login", login);
|
app.post("/login", login);
|
||||||
|
|
||||||
//Deletes user account
|
//Deletes user account
|
||||||
app.delete("/delete", fbAuth, deleteUser);
|
app.delete("/delete", deleteUser);
|
||||||
|
|
||||||
app.post("/getUserDetails", fbAuth, getUserDetails);
|
app.get("/getUser", fbAuth, getUserDetails);
|
||||||
|
|
||||||
// Returns all profile data of the currently logged in user
|
// Returns all profile data of the currently logged in user
|
||||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||||
@@ -47,54 +41,33 @@ app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
|||||||
|
|
||||||
app.get("/user", fbAuth, getAuthenticatedUser);
|
app.get("/user", fbAuth, getAuthenticatedUser);
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
|
||||||
// Must be run by the Admin user
|
|
||||||
app.post("/verifyUser", fbAuth, verifyUser);
|
|
||||||
|
|
||||||
// Unverifies the user sent to the request
|
|
||||||
// Must be run by admin
|
|
||||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
|
||||||
|
|
||||||
// get user handles with search phase
|
|
||||||
app.post("/getUserHandles", fbAuth, getUserHandles);
|
|
||||||
|
|
||||||
// get user's subscription
|
|
||||||
app.get("/getSubs", fbAuth, getSubs);
|
|
||||||
|
|
||||||
// add user to another user's "following" data field
|
|
||||||
app.post("/addSubscription", fbAuth, addSubscription);
|
|
||||||
|
|
||||||
// remove one subscription
|
|
||||||
app.post("/removeSub", fbAuth, removeSub);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
|
const { getallPostsforUser, putPost, getPost, getallPostsforFeed, likePost, unlikePost, quotePost
|
||||||
|
} = require("./handlers/post");
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
app.get("/getallPosts", getallPosts);
|
app.get("/getallPostsforFeed", fbAuth, getallPostsforFeed);
|
||||||
|
|
||||||
|
app.get("/putPost/:postId", fbAuth, getPost);
|
||||||
|
app.get("/putPost/:postId/like", fbAuth, likePost);
|
||||||
|
app.get("/putPost/:postId/unlike", fbAuth, unlikePost);
|
||||||
|
app.post("/putPost/:postId/quote", fbAuth, quotePost);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post("/putPost", fbAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
|
|
||||||
app.get("/like/:postId", fbAuth, likePost);
|
|
||||||
app.get("/unlike/:postId", fbAuth, unlikePost);
|
|
||||||
|
|
||||||
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
|
||||||
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const {
|
||||||
putTopic,
|
putTopic,
|
||||||
getAllTopics,
|
getAllTopics,
|
||||||
deleteTopic,
|
deleteTopic
|
||||||
getUserTopics
|
|
||||||
} = require("./handlers/topic");
|
} = require("./handlers/topic");
|
||||||
|
|
||||||
// add topic to database
|
// add topic to database
|
||||||
@@ -104,9 +77,6 @@ app.post("/putTopic", fbAuth, putTopic);
|
|||||||
app.get("/getAllTopics", fbAuth, getAllTopics);
|
app.get("/getAllTopics", fbAuth, getAllTopics);
|
||||||
|
|
||||||
// delete a specific topic
|
// delete a specific topic
|
||||||
app.post("/deleteTopic", fbAuth, deleteTopic);
|
app.delete("/deleteTopic/:topicId", fbAuth, deleteTopic);
|
||||||
|
|
||||||
// get topic for this user
|
|
||||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
|
|||||||
198
twistter-frontend/package-lock.json
generated
198
twistter-frontend/package-lock.json
generated
@@ -121,6 +121,16 @@
|
|||||||
"react-is": "^16.8.6"
|
"react-is": "^16.8.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@restart/context": {
|
||||||
|
"version": "2.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@restart/context/-/context-2.1.4.tgz",
|
||||||
|
"integrity": "sha512-INJYZQJP7g+IoDUh/475NlGiTeMfwTXUEr3tmRneckHIxNolGOW9CTq83S8cxq0CgJwwcMzMJFchxvlwe7Rk8Q=="
|
||||||
|
},
|
||||||
|
"@restart/hooks": {
|
||||||
|
"version": "0.3.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/@restart/hooks/-/hooks-0.3.15.tgz",
|
||||||
|
"integrity": "sha512-rVNba1A2oMzKBg16fCrrHmCf4JjOzFhT9TWR8J+Y8iOcY4zffxtP3ke7mEsakvghHZT+9//uDOPSSeuBDW41GQ=="
|
||||||
|
},
|
||||||
"@types/prop-types": {
|
"@types/prop-types": {
|
||||||
"version": "15.7.3",
|
"version": "15.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz",
|
||||||
@@ -1419,6 +1429,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
|
||||||
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24="
|
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24="
|
||||||
},
|
},
|
||||||
|
"bootstrap": {
|
||||||
|
"version": "4.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.3.1.tgz",
|
||||||
|
"integrity": "sha512-rXqOmH1VilAt2DyPzluTi2blhk17bO7ef+zLLPlWvG494pDxcM234pJ8wTc/6R40UWizAIIMgxjvxZg5kmsbag=="
|
||||||
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@@ -1704,6 +1719,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"classnames": {
|
||||||
|
"version": "2.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz",
|
||||||
|
"integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q=="
|
||||||
|
},
|
||||||
"clean-css": {
|
"clean-css": {
|
||||||
"version": "4.2.1",
|
"version": "4.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.1.tgz",
|
||||||
@@ -2228,6 +2248,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"create-react-context": {
|
||||||
|
"version": "0.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/create-react-context/-/create-react-context-0.3.0.tgz",
|
||||||
|
"integrity": "sha512-dNldIoSuNSvlTJ7slIKC/ZFGKexBMBrrcc+TTe1NdmROnaASuLPvqpwj9v4XS4uXZ8+YPu0sNmShX2rXI5LNsw==",
|
||||||
|
"requires": {
|
||||||
|
"gud": "^1.0.0",
|
||||||
|
"warning": "^4.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"cross-spawn": {
|
"cross-spawn": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz",
|
||||||
@@ -3092,6 +3121,11 @@
|
|||||||
"merge": "^1.2.0"
|
"merge": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"exenv": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/exenv/-/exenv-1.2.2.tgz",
|
||||||
|
"integrity": "sha1-KueOhdmJQVhnCwPUe+wfA72Ru50="
|
||||||
|
},
|
||||||
"exit-hook": {
|
"exit-hook": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
||||||
@@ -5290,6 +5324,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
|
||||||
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
|
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
|
||||||
},
|
},
|
||||||
|
"keycode": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/keycode/-/keycode-2.2.0.tgz",
|
||||||
|
"integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ="
|
||||||
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "3.2.2",
|
"version": "3.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
||||||
@@ -6998,6 +7037,25 @@
|
|||||||
"react-is": "^16.8.1"
|
"react-is": "^16.8.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"prop-types-extra": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/prop-types-extra/-/prop-types-extra-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-QFyuDxvMipmIVKD2TwxLVPzMnO4e5oOf1vr3tJIomL8E7d0lr6phTHd5nkPhFIzTD1idBLLEPeylL9g+rrTzRg==",
|
||||||
|
"requires": {
|
||||||
|
"react-is": "^16.3.2",
|
||||||
|
"warning": "^3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"warning": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=",
|
||||||
|
"requires": {
|
||||||
|
"loose-envify": "^1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"proxy-addr": {
|
"proxy-addr": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
|
||||||
@@ -7134,6 +7192,43 @@
|
|||||||
"prop-types": "^15.6.2"
|
"prop-types": "^15.6.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-bootstrap": {
|
||||||
|
"version": "1.0.0-beta.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-1.0.0-beta.14.tgz",
|
||||||
|
"integrity": "sha512-UGK5f78FE8wAei1YL/oSwFlJZLqxJ/h4S8DCwHyY8hQjFCrjEW5PoEBTOOhQ6PQL6WOsZe1jkiOJG7L5TZWu+w==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.4.2",
|
||||||
|
"@restart/context": "^2.1.4",
|
||||||
|
"@restart/hooks": "^0.3.11",
|
||||||
|
"@types/react": "^16.8.23",
|
||||||
|
"classnames": "^2.2.6",
|
||||||
|
"dom-helpers": "^3.4.0",
|
||||||
|
"invariant": "^2.2.4",
|
||||||
|
"keycode": "^2.2.0",
|
||||||
|
"popper.js": "^1.14.7",
|
||||||
|
"prop-types": "^15.7.2",
|
||||||
|
"prop-types-extra": "^1.1.0",
|
||||||
|
"react-overlays": "^1.2.0",
|
||||||
|
"react-transition-group": "^4.0.0",
|
||||||
|
"uncontrollable": "^7.0.0",
|
||||||
|
"warning": "^4.0.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dom-helpers": {
|
||||||
|
"version": "3.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz",
|
||||||
|
"integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"react-context-toolbox": {
|
||||||
|
"version": "2.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-context-toolbox/-/react-context-toolbox-2.0.2.tgz",
|
||||||
|
"integrity": "sha512-tY4j0imkYC3n5ZlYSgFkaw7fmlCp3IoQQ6DxpqeNHzcD0hf+6V+/HeJxviLUZ1Rv1Yn3N3xyO2EhkkZwHn0m1A=="
|
||||||
|
},
|
||||||
"react-dev-utils": {
|
"react-dev-utils": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-0.5.2.tgz",
|
||||||
@@ -7162,11 +7257,82 @@
|
|||||||
"scheduler": "^0.15.0"
|
"scheduler": "^0.15.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-dropdown": {
|
||||||
|
"version": "1.6.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-dropdown/-/react-dropdown-1.6.4.tgz",
|
||||||
|
"integrity": "sha512-zTlNRZ6vzjEPsodBNgh6Xjp9IempEx9sReH3crT2Jw4S6KW2wS/BRIH3d/grYf/iXARadDRD91//uUCs9yjoLg==",
|
||||||
|
"requires": {
|
||||||
|
"classnames": "^2.2.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-is": {
|
"react-is": {
|
||||||
"version": "16.9.0",
|
"version": "16.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz",
|
||||||
"integrity": "sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw=="
|
"integrity": "sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw=="
|
||||||
},
|
},
|
||||||
|
"react-lifecycles-compat": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA=="
|
||||||
|
},
|
||||||
|
"react-modal": {
|
||||||
|
"version": "3.11.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-modal/-/react-modal-3.11.1.tgz",
|
||||||
|
"integrity": "sha512-8uN744Yq0X2lbfSLxsEEc2UV3RjSRb4yDVxRQ1aGzPo86QjNOwhQSukDb8U8kR+636TRTvfMren10fgOjAy9eA==",
|
||||||
|
"requires": {
|
||||||
|
"exenv": "^1.2.0",
|
||||||
|
"prop-types": "^15.5.10",
|
||||||
|
"react-lifecycles-compat": "^3.0.0",
|
||||||
|
"warning": "^4.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"react-overlays": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-i/FCV8wR6aRaI+Kz/dpJhOdyx+ah2tN1RhT9InPrexyC4uzf3N4bNayFTGtUeQVacj57j1Mqh1CwV60/5153Iw==",
|
||||||
|
"requires": {
|
||||||
|
"classnames": "^2.2.6",
|
||||||
|
"dom-helpers": "^3.4.0",
|
||||||
|
"prop-types": "^15.6.2",
|
||||||
|
"prop-types-extra": "^1.1.0",
|
||||||
|
"react-context-toolbox": "^2.0.2",
|
||||||
|
"react-popper": "^1.3.2",
|
||||||
|
"uncontrollable": "^6.0.0",
|
||||||
|
"warning": "^4.0.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dom-helpers": {
|
||||||
|
"version": "3.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz",
|
||||||
|
"integrity": "sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uncontrollable": {
|
||||||
|
"version": "6.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/uncontrollable/-/uncontrollable-6.2.3.tgz",
|
||||||
|
"integrity": "sha512-VgOAoBU2ptCL2bfTG2Mra0I8i1u6Aq84AFonD5tmCAYSfs3hWvr2Rlw0q2ntoxXTHjcQOmZOh3FKaN+UZVyREQ==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.4.5",
|
||||||
|
"invariant": "^2.2.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"react-popper": {
|
||||||
|
"version": "1.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-popper/-/react-popper-1.3.4.tgz",
|
||||||
|
"integrity": "sha512-9AcQB29V+WrBKk6X7p0eojd1f25/oJajVdMZkywIoAV6Ag7hzE1Mhyeup2Q1QnvFRtGQFQvtqfhlEoDAPfKAVA==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.1.2",
|
||||||
|
"create-react-context": "^0.3.0",
|
||||||
|
"popper.js": "^1.14.4",
|
||||||
|
"prop-types": "^15.6.1",
|
||||||
|
"typed-styles": "^0.0.7",
|
||||||
|
"warning": "^4.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-redux": {
|
"react-redux": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.1.1.tgz",
|
||||||
@@ -8155,6 +8321,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-simple-dropdown": {
|
||||||
|
"version": "3.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-simple-dropdown/-/react-simple-dropdown-3.2.3.tgz",
|
||||||
|
"integrity": "sha512-NmyyvA0D4wph5ctzkn8U4wmblOacavJMl9gTOhQR3v8I997mc1FL1NFKkj3Mx+HNysBKRD/HI+kpxXCAgXumPw==",
|
||||||
|
"requires": {
|
||||||
|
"classnames": "^2.1.2",
|
||||||
|
"prop-types": "^15.5.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-transition-group": {
|
"react-transition-group": {
|
||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.3.0.tgz",
|
||||||
@@ -9720,6 +9895,11 @@
|
|||||||
"mime-types": "~2.1.24"
|
"mime-types": "~2.1.24"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"typed-styles": {
|
||||||
|
"version": "0.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/typed-styles/-/typed-styles-0.0.7.tgz",
|
||||||
|
"integrity": "sha512-pzP0PWoZUhsECYjABgCGQlRGL1n7tOHsgwYv3oIiEpJwGhFTuty/YNeduxQYzXXa3Ge5BdT6sHYIQYpl4uJ+5Q=="
|
||||||
|
},
|
||||||
"typedarray": {
|
"typedarray": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||||
@@ -9761,6 +9941,16 @@
|
|||||||
"resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz",
|
||||||
"integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE="
|
"integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE="
|
||||||
},
|
},
|
||||||
|
"uncontrollable": {
|
||||||
|
"version": "7.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uncontrollable/-/uncontrollable-7.0.2.tgz",
|
||||||
|
"integrity": "sha512-7fa8OBQ5+X4VAcp0os6BD74bCeUPQSHmr4Rqy75Me98NnlD5kNShCqqx4xWo4OmlAMiT2/YSMklLFC4FCuoGYg==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.4.5",
|
||||||
|
"invariant": "^2.2.4",
|
||||||
|
"react-lifecycles-compat": "^3.0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"union-value": {
|
"union-value": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
||||||
@@ -9991,6 +10181,14 @@
|
|||||||
"makeerror": "1.0.x"
|
"makeerror": "1.0.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"warning": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==",
|
||||||
|
"requires": {
|
||||||
|
"loose-envify": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"watch": {
|
"watch": {
|
||||||
"version": "0.10.0",
|
"version": "0.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/watch/-/watch-0.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/watch/-/watch-0.10.0.tgz",
|
||||||
|
|||||||
@@ -8,16 +8,21 @@
|
|||||||
"@material-ui/styles": "^4.5.0",
|
"@material-ui/styles": "^4.5.0",
|
||||||
"@material-ui/system": "^4.5.0",
|
"@material-ui/system": "^4.5.0",
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
|
"bootstrap": "^4.3.1",
|
||||||
"clsx": "^1.0.4",
|
"clsx": "^1.0.4",
|
||||||
"create-react-app": "^3.1.2",
|
"create-react-app": "^3.1.2",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"jwt-decode": "^2.2.0",
|
"jwt-decode": "^2.2.0",
|
||||||
"node-pre-gyp": "^0.13.0",
|
"node-pre-gyp": "^0.13.0",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
|
"react-bootstrap": "^1.0.0-beta.14",
|
||||||
"react-dom": "^16.9.0",
|
"react-dom": "^16.9.0",
|
||||||
|
"react-dropdown": "^1.6.4",
|
||||||
|
"react-modal": "^3.11.1",
|
||||||
"react-redux": "^7.1.1",
|
"react-redux": "^7.1.1",
|
||||||
"react-router-dom": "^5.1.0",
|
"react-router-dom": "^5.1.0",
|
||||||
"react-scripts": "0.9.5",
|
"react-scripts": "0.9.5",
|
||||||
|
"react-simple-dropdown": "^3.2.3",
|
||||||
"redux": "^4.0.4",
|
"redux": "^4.0.4",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
"typeface-roboto": "0.0.75"
|
"typeface-roboto": "0.0.75"
|
||||||
@@ -41,5 +46,5 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,14 @@ const reducers = combineReducers({
|
|||||||
UI: uiReducer
|
UI: uiReducer
|
||||||
});
|
});
|
||||||
|
|
||||||
//const store = createStore(reducers, )
|
const store = createStore(
|
||||||
|
reducers,
|
||||||
|
initialState,
|
||||||
|
compose(
|
||||||
|
applyMiddleware(...middleware),
|
||||||
|
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
export default store;
|
||||||
@@ -12,6 +12,12 @@ body {
|
|||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.userhome{
|
||||||
|
display:flex;
|
||||||
|
flex-direction:row;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.authButtons {
|
.authButtons {
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
|
|||||||
@@ -6,32 +6,35 @@ import axios from "axios";
|
|||||||
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
||||||
import Navbar from "./components/layout/NavBar";
|
import Navbar from "./components/layout/NavBar";
|
||||||
import jwtDecode from "jwt-decode";
|
import jwtDecode from "jwt-decode";
|
||||||
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||||
|
import { Button } from 'react-bootstrap';
|
||||||
|
|
||||||
// Redux
|
// Redux
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import store from "./redux/store";
|
import store from "./redux/store";
|
||||||
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
|
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
|
||||||
import createMuiTheme from "@material-ui/core/styles/createMuiTheme";
|
import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
|
||||||
import themeObject from "./util/theme";
|
import themeObject from './util/theme';
|
||||||
import { SET_AUTHENTICATED } from "./redux/types";
|
import { SET_AUTHENTICATED } from './redux/types';
|
||||||
import { logoutUser, getUserData } from "./redux/actions/userActions";
|
import { logoutUser, getUserData } from './redux/actions/userActions';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import AuthRoute from "./util/AuthRoute";
|
import AuthRoute from "./util/AuthRoute";
|
||||||
|
|
||||||
|
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
import home from "./pages/Home";
|
import home from './pages/Home';
|
||||||
import signup from "./pages/Signup";
|
import signup from './pages/Signup';
|
||||||
import login from "./pages/Login";
|
import login from './pages/Login';
|
||||||
import user from "./pages/user";
|
import user from './pages/user';
|
||||||
import logout from "./pages/Logout";
|
import logout from './pages/Logout';
|
||||||
import Delete from "./pages/Delete";
|
import Delete from './pages/Delete';
|
||||||
import writeMicroblog from "./Writing_Microblogs.js";
|
import writeMicroblog from './Writing_Microblogs.js';
|
||||||
import editProfile from "./pages/editProfile";
|
import editProfile from './pages/editProfile';
|
||||||
import userLine from "./Userline.js";
|
import userLine from './Userline.js';
|
||||||
import verify from "./pages/verify";
|
|
||||||
import Search from "./pages/Search.js";
|
import feed from './Feed.js';
|
||||||
import otherUser from "./pages/otherUser";
|
|
||||||
|
|
||||||
const theme = createMuiTheme(themeObject);
|
const theme = createMuiTheme(themeObject);
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ if (token) {
|
|||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
} else {
|
} else {
|
||||||
store.dispatch({ type: SET_AUTHENTICATED });
|
store.dispatch({ type: SET_AUTHENTICATED });
|
||||||
axios.defaults.headers.common["Authorization"] = token;
|
axios.defaults.headers.common['Authorization'] = token;
|
||||||
store.dispatch(getUserData());
|
store.dispatch(getUserData());
|
||||||
}
|
}
|
||||||
} catch (invalidTokenError) {
|
} catch (invalidTokenError) {
|
||||||
@@ -53,35 +56,37 @@ if (token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<MuiThemeProvider theme={theme}>
|
<MuiThemeProvider theme={theme}>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Router>
|
<Router>
|
||||||
<div className="container">
|
<div className='container' >
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
||||||
<AuthRoute exact path="/signup" component={signup} />
|
<AuthRoute exact path="/signup" component={signup} />
|
||||||
<AuthRoute exact path="/login" component={login} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
<AuthRoute exact path="/" component={home} />
|
<Route exact path="/logout" component={logout} />
|
||||||
|
<Route exact path="/delete" component={Delete} />
|
||||||
|
<Route exact path="/user" component={user} />
|
||||||
|
<div className="userhome">
|
||||||
|
<Route exact path="/home" component={writeMicroblog} />
|
||||||
|
<Route exact path="/home" component={feed} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<Route exact path="/logout" component={logout} />
|
<Route exact path="/edit" component={editProfile} />
|
||||||
<Route exact path="/delete" component={Delete} />
|
<Route exact path="/userline" component={userLine} />
|
||||||
|
|
||||||
<Route exact path="/home" component={home} />
|
<AuthRoute exact path="/" component={home}/>
|
||||||
<Route exact path="/user" component={user} />
|
|
||||||
<Route exact path="/edit" component={editProfile} />
|
|
||||||
<Route exact path="/verify" component={verify} />
|
|
||||||
<Route exact path="/search" component={Search} />
|
|
||||||
<Route exact path="/user/:userhandle" component={otherUser} />
|
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home} />
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>
|
</Provider>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
|
|||||||
97
twistter-frontend/src/Feed.js
Normal file
97
twistter-frontend/src/Feed.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
import Box from '@material-ui/core/Box';
|
||||||
|
//import {connect } from 'react-redux';
|
||||||
|
//import { likePost, unlikePost } from '../redux/actions/dataActions';
|
||||||
|
//import PropTypes from 'prop-types';
|
||||||
|
import Like from "./Like.js";
|
||||||
|
import Route from 'react-router-dom/Route';
|
||||||
|
|
||||||
|
import Quote from "./Quote.js";
|
||||||
|
|
||||||
|
class Feed extends Component {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
microBlogs: [],
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
|
||||||
|
axios.get("/getallPostsforFeed")
|
||||||
|
.then((res) => {
|
||||||
|
const post = res.data;
|
||||||
|
this.setState({microBlogs : post})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
|
||||||
|
|
||||||
|
const sortedPosts = (this.state.microBlogs).sort((a,b) =>
|
||||||
|
-a.createdAt.localeCompare(b.createdAt)
|
||||||
|
)
|
||||||
|
|
||||||
|
return(
|
||||||
|
<div>
|
||||||
|
<div style={{fontsize: "13px", marginLeft: "30%", textAlign: "left", }}>
|
||||||
|
<p>Feed</p>
|
||||||
|
</div>
|
||||||
|
<Box width="25%" flex="1" height="auto" marginLeft= "30%" m={2} fontSize="13px" padding="5px" flexWrap= "wrap" flexDirection= "row" >
|
||||||
|
|
||||||
|
<div style={{flexWrap: "wrap", flex: "1", flexDirection: "row", wordBreak: "break-word", textAlign: "left"}}>
|
||||||
|
<p>
|
||||||
|
{sortedPosts.map((microBlog) => <p>Microblog Title: {microBlog.microBlogTitle}
|
||||||
|
<br></br>When post was created: {microBlog.createdAt.substring(0,10) +
|
||||||
|
" " + microBlog.createdAt.substring(11,19)}
|
||||||
|
<br></br>Who wrote the microBlog: {microBlog.userHandle}
|
||||||
|
<br></br>Body of post: {microBlog.body}
|
||||||
|
|
||||||
|
<br></br>Tagged topics: {microBlog.microBlogTopics.join("," + " ")}
|
||||||
|
<br></br><br></br><br></br>
|
||||||
|
<div className="buttons">
|
||||||
|
|
||||||
|
<Like></Like>
|
||||||
|
|
||||||
|
<span>Likes: {microBlog.likeCount}</span>
|
||||||
|
<Quote></Quote>
|
||||||
|
|
||||||
|
<br></br><br></br><br></br><br></br>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</p>)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Box>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Feed.propTypes = {
|
||||||
|
likePost: PropTypes.func.isRequired,
|
||||||
|
unlikePost: PropTypes.func.isRequired,
|
||||||
|
user: PropTypes.object.isRequired,
|
||||||
|
post: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
const mapActionsToProps = {
|
||||||
|
likePost,
|
||||||
|
unlikePost
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapActionsToProps)(Feed); */
|
||||||
|
export default Feed;
|
||||||
54
twistter-frontend/src/Like.js
Normal file
54
twistter-frontend/src/Like.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
|
import Route from 'react-router-dom/Route';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
class Like extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
like : false,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit(){
|
||||||
|
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
like: !this.state.like
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const postId = "AJdhYAE4diocF8UcrHDq"
|
||||||
|
|
||||||
|
if(this.state.like == false)
|
||||||
|
{
|
||||||
|
axios.get(`/putPost/${postId}/like`)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
axios.get(`/putPost/${postId}/unlike`)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const label = this.state.like ? 'Unlike' : 'Like'
|
||||||
|
return (
|
||||||
|
<button onClick = {{backgroundColor: "lightBlue" }} onClick={this.handleSubmit}>{label}</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Like;
|
||||||
78
twistter-frontend/src/Quote.js
Normal file
78
twistter-frontend/src/Quote.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
|
import Route from 'react-router-dom/Route';
|
||||||
|
import axios from 'axios';
|
||||||
|
import Modal from "react-modal";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Quote extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
post: null
|
||||||
|
};
|
||||||
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
|
this.handleSubmit2 = this.handleSubmit2.bind(this);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit2() {
|
||||||
|
const postId = "AJdhYAE4diocF8UcrHDq";
|
||||||
|
const postNoComment = {
|
||||||
|
body : ""
|
||||||
|
}
|
||||||
|
const headers = {
|
||||||
|
headers: { 'Content-Type': 'application/json'}
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.post(`/putPost/${postId}/quote`, postNoComment, headers)
|
||||||
|
.then((res) =>{
|
||||||
|
alert('Quoting was successful!')
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
alert('An error occured.');
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit() {
|
||||||
|
const postId = "AJdhYAE4diocF8UcrHDq";
|
||||||
|
const postComment = {
|
||||||
|
body : ""
|
||||||
|
}
|
||||||
|
const headers = {
|
||||||
|
headers: { 'Content-Type': 'application/json'}
|
||||||
|
}
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post(`/putPost/${postId}/quote`, postComment, headers)
|
||||||
|
.then((res) =>{
|
||||||
|
alert('Quoting was successful!')
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
alert('An error occured.');
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return(
|
||||||
|
<div>
|
||||||
|
<button onClick={this.handleSubmit}>Quote with comment</button>
|
||||||
|
<button onClick={this.handleSubmit2}>Quote without comment</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Quote
|
||||||
@@ -1,128 +1,112 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import Route from "react-router-dom/Route";
|
import Route from 'react-router-dom/Route';
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Writing_Microblogs extends Component {
|
class Writing_Microblogs extends Component {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
value: "",
|
|
||||||
title: "",
|
|
||||||
topics: "",
|
|
||||||
characterCount: 250
|
|
||||||
};
|
|
||||||
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
constructor(props) {
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
super(props);
|
||||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
this.state = {
|
||||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
value: '',
|
||||||
}
|
title: '',
|
||||||
|
topics: '',
|
||||||
|
characterCount: 250
|
||||||
|
|
||||||
handleChange(event) {
|
};
|
||||||
this.setState({ title: event.target.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforTopics(event) {
|
|
||||||
this.setState({ topics: event.target.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit(event) {
|
this.handleChange = this.handleChange.bind(this);
|
||||||
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
const postData = {
|
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||||
body: this.state.value,
|
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||||
userImage: "bing-url",
|
|
||||||
microBlogTitle: this.state.title,
|
|
||||||
microBlogTopics: this.state.topics.split(", ")
|
|
||||||
};
|
|
||||||
const headers = {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
}
|
||||||
.post("/putPost", postData, headers)
|
|
||||||
.then(res => {
|
|
||||||
alert("Post was shared successfully!");
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
alert("An error occured.");
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
handleChange(event) {
|
||||||
this.setState({ value: event.target.value });
|
this.setState( {title: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
handleChangeforTopics(event) {
|
||||||
const charCount = event.target.value.length;
|
this.setState( {topics: event.target.value});
|
||||||
const charRemaining = 250 - charCount;
|
}
|
||||||
this.setState({ characterCount: charRemaining });
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
handleSubmit(event) {
|
||||||
return (
|
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||||
<div>
|
const postData = {
|
||||||
<div
|
body: this.state.value,
|
||||||
style={{
|
userImage: "bing-url",
|
||||||
width: "200px",
|
microBlogTitle: this.state.title,
|
||||||
height: "50px",
|
microBlogTopics: this.state.topics.split(', ')
|
||||||
marginTop: "180px",
|
}
|
||||||
marginLeft: "50px"
|
const headers = {
|
||||||
}}
|
headers: { 'Content-Type': 'application/json'}
|
||||||
>
|
}
|
||||||
<form>
|
|
||||||
<textarea
|
|
||||||
placeholder="Enter Microblog Title"
|
|
||||||
value={this.state.title}
|
|
||||||
required
|
|
||||||
onChange={this.handleChange}
|
|
||||||
cols={30}
|
|
||||||
rows={1}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
|
|
||||||
<form>
|
|
||||||
<textarea
|
|
||||||
placeholder="Enter topics seperated by a comma"
|
|
||||||
value={this.state.topics}
|
|
||||||
required
|
|
||||||
onChange={this.handleChangeforTopics}
|
|
||||||
cols={40}
|
|
||||||
rows={1}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ width: "200px", marginLeft: "50px" }}>
|
axios
|
||||||
<form onSubmit={this.handleSubmit}>
|
.post("/putPost", postData, headers)
|
||||||
<textarea
|
.then((res) =>{
|
||||||
value={this.state.value}
|
alert('Post was shared successfully!')
|
||||||
required
|
console.log(res.data);
|
||||||
maxLength="250"
|
})
|
||||||
placeholder="Write Microblog here..."
|
.catch((err) => {
|
||||||
onChange={e => {
|
alert('An error occured.');
|
||||||
this.handleChangeforPost(e);
|
console.error(err);
|
||||||
this.handleChangeforCharacterCount(e);
|
})
|
||||||
}}
|
event.preventDefault();
|
||||||
cols={40}
|
this.setState({value: '', title: '',characterCount: 250, topics: ''})
|
||||||
rows={20}
|
}
|
||||||
/>
|
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
handleChangeforPost(event) {
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
this.setState({value: event.target.value })
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChangeforCharacterCount(event) {
|
||||||
|
const charCount = event.target.value.length
|
||||||
|
const charRemaining = 250 - charCount
|
||||||
|
this.setState({characterCount: charRemaining })
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
|
||||||
|
<form>
|
||||||
|
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
|
||||||
|
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginRight: "-100px" }}>
|
<div style={{ width: "200px", height: "50px", marginLeft: "50px"}} >
|
||||||
<button onClick>Share Post</button>
|
<form>
|
||||||
</div>
|
<textarea placeholder="Enter topics seperated by a comma" value={this.state.topics} required onChange={this.handleChangeforTopics} cols={40} rows={1} />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
<div style={{ width: "200px", marginLeft: "50px"}}>
|
||||||
}
|
<form onSubmit={this.handleSubmit}>
|
||||||
|
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
|
||||||
|
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
|
||||||
|
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
|
||||||
|
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||||
|
</div>
|
||||||
|
<div style={{ marginRight: "-100px" }}>
|
||||||
|
<button onClick>Share Post</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Writing_Microblogs;
|
export default Writing_Microblogs;
|
||||||
@@ -1,84 +1,81 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from "react";
|
import React, { Component } from 'react';
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from 'react-router-dom';
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
// Material UI stuff
|
// Material UI stuff
|
||||||
import AppBar from "@material-ui/core/AppBar";
|
import AppBar from '@material-ui/core/AppBar';
|
||||||
import ToolBar from "@material-ui/core/Toolbar";
|
import ToolBar from '@material-ui/core/Toolbar';
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from '@material-ui/core/Button';
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { logoutUser } from "../../redux/actions/userActions";
|
// import { logoutUser } from '../../redux/actions/userActions';
|
||||||
import { connect } from "react-redux";
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 30
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
marginBottom: 40
|
marginBottom: 40
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
positon: "relative",
|
positon: "relative",
|
||||||
marginBottom: 30
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Navbar extends Component {
|
|
||||||
render() {
|
|
||||||
const authenticated = this.props.user.authenticated;
|
|
||||||
return (
|
|
||||||
<AppBar>
|
export class Navbar extends Component {
|
||||||
<ToolBar>
|
render() {
|
||||||
<Button component={Link} to="/">
|
const authenticated = this.props.user.authenticated;
|
||||||
Home
|
return (
|
||||||
</Button>
|
<AppBar>
|
||||||
{authenticated && (
|
<ToolBar>
|
||||||
<Button component={Link} to="/user">
|
<Button component={ Link } to='/'>
|
||||||
Profile
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
{!authenticated && <Button component={ Link } to='/login'>
|
||||||
{!authenticated && (
|
Login
|
||||||
<Button component={Link} to="/login">
|
</Button>}
|
||||||
Login
|
{!authenticated && <Button component={ Link } to='/signup'>
|
||||||
</Button>
|
Sign Up
|
||||||
)}
|
</Button>}
|
||||||
{!authenticated && (
|
{authenticated && <Button component={ Link } to='/logout'>
|
||||||
<Button component={Link} to="/signup">
|
Logout
|
||||||
Sign Up
|
</Button>}
|
||||||
</Button>
|
{/* Commented out the delete button, because it should probably go on
|
||||||
)}
|
the profile or editProfile page instead of the NavBar */}
|
||||||
{authenticated && (
|
{/* <Button component={ Link } to='/delete'>
|
||||||
<Button component={Link} to="/search">
|
Delete Account
|
||||||
Search
|
</Button> */}
|
||||||
</Button>
|
</ToolBar>
|
||||||
)}
|
</AppBar>
|
||||||
{authenticated && (
|
)
|
||||||
<Button component={Link} to="/logout">
|
}
|
||||||
Logout
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</ToolBar>
|
|
||||||
</AppBar>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
});
|
})
|
||||||
|
|
||||||
|
// const mapActionsToProps = { logoutUser };
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
};
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|
||||||
|
// export default Navbar;
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ import Button from "@material-ui/core/Button";
|
|||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
//import { logoutUser } from "../redux/actions/userActions";
|
import { logoutUser } from "../redux/actions/userActions";
|
||||||
import { deleteUser } from "../redux/actions/userActions";
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@@ -33,8 +32,7 @@ const styles = {
|
|||||||
export class Delete extends Component {
|
export class Delete extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
//this.props.logoutUser();
|
this.props.logoutUser();
|
||||||
this.props.deleteUser();
|
|
||||||
this.props.history.push('/');
|
this.props.history.push('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,12 +45,10 @@ const mapStateToProps = (state) => ({
|
|||||||
user: state.user
|
user: state.user
|
||||||
});
|
});
|
||||||
|
|
||||||
//const mapActionsToProps = { logoutUser };
|
const mapActionsToProps = { logoutUser };
|
||||||
const mapActionsToProps = { deleteUser };
|
|
||||||
|
|
||||||
Delete.propTypes = {
|
Delete.propTypes = {
|
||||||
//logoutUser: PropTypes.func.isRequired,
|
logoutUser: PropTypes.func.isRequired,
|
||||||
deleteUser: PropTypes.func.isRequired,
|
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,86 +1,12 @@
|
|||||||
/* eslint-disable */
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
// Material UI and React Router
|
|
||||||
import Grid from '@material-ui/core/Grid';
|
|
||||||
import Card from '@material-ui/core/Card';
|
|
||||||
import CardContent from '@material-ui/core/CardContent';
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
|
|
||||||
// component
|
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
import noImage from '../images/no-img.png';
|
|
||||||
import Writing_Microblogs from '../Writing_Microblogs';
|
|
||||||
import ReactModal from 'react-modal';
|
|
||||||
|
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
state = {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
axios
|
|
||||||
.get("/getallPosts")
|
|
||||||
.then(res => {
|
|
||||||
console.log(res.data);
|
|
||||||
this.setState({
|
|
||||||
posts: res.data
|
|
||||||
})
|
|
||||||
this.setState({posts: (this.state.posts).sort((a,b) =>
|
|
||||||
-a.createdAt.localeCompare(b.createdAt))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let authenticated = this.props.user.authenticated;
|
|
||||||
|
|
||||||
let postMarkup = this.state.posts ? (
|
|
||||||
this.state.posts.map(post =>
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<Typography>
|
|
||||||
{
|
|
||||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
|
||||||
(<img src={noImage} height="50" width="50"/>)
|
|
||||||
}
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
|
|
||||||
" " + post.createdAt.substring(11,19)}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
|
||||||
<Like microBlog = {post.postId}></Like>
|
|
||||||
<Quote microblog = {post.postId}></Quote>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
) : (<p>My Posts</p>);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
authenticated ?
|
|
||||||
<Grid container spacing={16}>
|
|
||||||
<Grid item sm={4} xs={8}>
|
|
||||||
<Writing_Microblogs />
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm={4} xs={8}>
|
|
||||||
{postMarkup}
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
:
|
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
@@ -105,179 +31,7 @@ class Home extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
|
||||||
user: state.user
|
|
||||||
})
|
|
||||||
|
|
||||||
Home.propTypes = {
|
|
||||||
user: PropTypes.object.isRequired
|
|
||||||
}
|
|
||||||
|
|
||||||
class Quote extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
characterCount: 250,
|
|
||||||
showModal: false,
|
|
||||||
value: ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
|
|
||||||
this.handleOpenModal = this.handleOpenModal.bind(this);
|
|
||||||
this.handleCloseModal = this.handleCloseModal.bind(this);
|
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmitWithoutPost(event) {
|
export default Home;
|
||||||
const headers = {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
};
|
|
||||||
axios.post(`/quoteWithoutPost/${this.props.microblog}`, headers)
|
|
||||||
.then((res) => {
|
|
||||||
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
handleOpenModal() {
|
|
||||||
this.setState({ showModal: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCloseModal() {
|
|
||||||
this.setState({ showModal: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
|
||||||
this.setState({ value: event.target.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
|
||||||
const charCount = event.target.value.length;
|
|
||||||
const charRemaining = 250 - charCount;
|
|
||||||
this.setState({ characterCount: charRemaining });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit(event) {
|
|
||||||
const quotedPost = {
|
|
||||||
quotePost: this.state.value,
|
|
||||||
};
|
|
||||||
const headers = {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
};
|
|
||||||
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
|
|
||||||
.then((res) => {
|
|
||||||
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({ showModal: false, characterCount: 250, value: "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<button onClick={this.handleOpenModal}>Quote with Post</button>
|
|
||||||
<ReactModal
|
|
||||||
isOpen={this.state.showModal}
|
|
||||||
style={{content: {height: "50%", width: "25%", marginTop: "auto", marginLeft: "auto", marginRight: "auto", marginBottom : "auto"}}}
|
|
||||||
>
|
|
||||||
<div style={{ width: "200px", marginLeft: "50px" }}>
|
|
||||||
<form>
|
|
||||||
<textarea
|
|
||||||
value={this.state.value}
|
|
||||||
required
|
|
||||||
maxLength="250"
|
|
||||||
placeholder="Write Quoted Post here..."
|
|
||||||
onChange={e => {
|
|
||||||
this.handleChangeforPost(e);
|
|
||||||
this.handleChangeforCharacterCount(e);
|
|
||||||
|
|
||||||
}}
|
|
||||||
cols={40}
|
|
||||||
rows={20}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
|
||||||
</div>
|
|
||||||
<button onClick={this.handleSubmit}>Share Quoted Post</button>
|
|
||||||
|
|
||||||
<button onClick={this.handleCloseModal}>Cancel</button>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</ReactModal>
|
|
||||||
<button onClick={this.handleSubmitWithoutPost}>Quote without Post</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Like extends Component {
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
this.state = {
|
|
||||||
like: false
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleClick = this.handleClick.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClick(){
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
like: !this.state.like
|
|
||||||
});
|
|
||||||
|
|
||||||
if(this.state.like == false)
|
|
||||||
{
|
|
||||||
|
|
||||||
axios.get(`/like/${this.props.microBlog}`)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
axios.get(`/unlike/${this.props.microBlog}`)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
const label = this.state.like ? 'Unlike' : 'Like'
|
|
||||||
return(
|
|
||||||
<div>
|
|
||||||
<button onClick={this.handleClick}>{label}</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Home);
|
|
||||||
@@ -16,15 +16,13 @@ import withStyles from "@material-ui/core/styles/withStyles";
|
|||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { loginUser } from '../redux/actions/userActions';
|
import { loginUser } from '../redux/actions/userActions';
|
||||||
import { fontFamily } from '@material-ui/system';
|
|
||||||
|
|
||||||
//Theme
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 20
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
// marginTop: 20,
|
// marginTop: 20,
|
||||||
@@ -36,9 +34,6 @@ const styles = {
|
|||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
},
|
|
||||||
p: {
|
|
||||||
fontFamily: "cursive",
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,12 +104,9 @@ export class Login extends Component {
|
|||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br></br>
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
<Typography variant="p" className={classes.pageTitle} fontFamily = "Georgia, serif">
|
Log in to Twistter
|
||||||
<b>Log in to Twistter</b>
|
|
||||||
<br></br>
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<br></br>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
<TextField
|
<TextField
|
||||||
id="email"
|
id="email"
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
import React, { Component } from "react";
|
|
||||||
// import props
|
|
||||||
import { TextField, Button } from "@material-ui/core";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
import Axios from "axios";
|
|
||||||
|
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
|
||||||
|
|
||||||
export class Search extends Component {
|
|
||||||
state = {
|
|
||||||
searchPhase: null,
|
|
||||||
searchResult: null
|
|
||||||
};
|
|
||||||
|
|
||||||
handleSearch = () => {
|
|
||||||
console.log(this.state.searchPhase);
|
|
||||||
Axios.post("/getUserHandles", {
|
|
||||||
userHandle: this.state.searchPhase
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log(res);
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
searchResult: res.data
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
handleInput(event) {
|
|
||||||
this.setState({
|
|
||||||
searchPhase: event.target.value
|
|
||||||
});
|
|
||||||
console.log(this.state.searchPhase);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleRedirect() {
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let resultMarkup = this.state.searchResult ? (
|
|
||||||
<Router>
|
|
||||||
<div>
|
|
||||||
<a href={`/user/${this.state.searchResult}`}>
|
|
||||||
{this.state.searchResult}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</Router>
|
|
||||||
) : (
|
|
||||||
// console.log(this.state.searchResult)
|
|
||||||
<p> No result </p>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid>
|
|
||||||
<Grid>
|
|
||||||
<TextField
|
|
||||||
id="standard-required"
|
|
||||||
label="Search"
|
|
||||||
defaultValue="username"
|
|
||||||
margin="normal"
|
|
||||||
value={this.state.searchPhase}
|
|
||||||
onChange={event => this.handleInput(event)}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid>
|
|
||||||
<Button color="primary" onClick={this.handleSearch}>
|
|
||||||
Search
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
<Grid>{resultMarkup}</Grid>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Search;
|
|
||||||
@@ -16,17 +16,13 @@ import withStyles from "@material-ui/core/styles/withStyles";
|
|||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { signupUser } from '../redux/actions/userActions';
|
import { signupUser } from '../redux/actions/userActions';
|
||||||
import { border } from '@material-ui/system';
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 20,
|
marginBottom: 30
|
||||||
//border: "1px solid #234",
|
|
||||||
display: "inline-block",
|
|
||||||
boxSizing: "border-box",
|
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
marginBottom: 40
|
marginBottom: 40
|
||||||
@@ -37,14 +33,6 @@ const styles = {
|
|||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
},
|
|
||||||
div: {
|
|
||||||
borderRadius: "5px",
|
|
||||||
backgroundColor: "grey",
|
|
||||||
padding: "20px",
|
|
||||||
},
|
|
||||||
p: {
|
|
||||||
fontFamily: "Segoe UI",
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,12 +92,9 @@ export class Signup extends Component {
|
|||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br></br>
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
<Typography variant="p" className={classes.pageTitle}>
|
Create a new account
|
||||||
<b>Create a new account</b>
|
|
||||||
<br></br>
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<br></br>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
<TextField
|
<TextField
|
||||||
id="handle"
|
id="handle"
|
||||||
@@ -161,8 +146,6 @@ export class Signup extends Component {
|
|||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<br></br>
|
|
||||||
<br></br>
|
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@@ -221,34 +220,12 @@ export class edit extends Component {
|
|||||||
color="primary"
|
color="primary"
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
//component={ Link }
|
|
||||||
//to='/user'
|
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
{loading && (
|
{loading && (
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
//variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/user'
|
|
||||||
>
|
|
||||||
Back to Profile
|
|
||||||
</Button>
|
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/delete'
|
|
||||||
>
|
|
||||||
Delete Account
|
|
||||||
</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
import React, { Component } from "react";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import axios from "axios";
|
|
||||||
//import '../App.css';
|
|
||||||
|
|
||||||
// Material UI and React Router
|
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import Card from "@material-ui/core/Card";
|
|
||||||
import CardMedia from "@material-ui/core/CardMedia";
|
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
|
|
||||||
import Chip from "@material-ui/core/Chip";
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import AddCircle from "@material-ui/icons/AddCircle";
|
|
||||||
import TextField from "@material-ui/core/TextField";
|
|
||||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
|
||||||
|
|
||||||
// component
|
|
||||||
import "../App.css";
|
|
||||||
import noImage from "../images/no-img.png";
|
|
||||||
import Writing_Microblogs from "../Writing_Microblogs";
|
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
|
||||||
margin: 2,
|
|
||||||
color: "primary"
|
|
||||||
});
|
|
||||||
|
|
||||||
class user extends Component {
|
|
||||||
state = {
|
|
||||||
profile: window.location.pathname.split("/").pop(),
|
|
||||||
imageUrl: null,
|
|
||||||
topics: null,
|
|
||||||
user: null,
|
|
||||||
following: null
|
|
||||||
};
|
|
||||||
|
|
||||||
handleSub = () => {
|
|
||||||
if (this.state.following === true) {
|
|
||||||
axios
|
|
||||||
.post("/removeSub", {
|
|
||||||
unfollow: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log("removed sub");
|
|
||||||
this.setState({
|
|
||||||
following: false
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
axios
|
|
||||||
.post("/addSubscription", {
|
|
||||||
following: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log("adding sub");
|
|
||||||
this.setState({
|
|
||||||
following: true
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
axios
|
|
||||||
.post("/getUserDetails", {
|
|
||||||
handle: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
this.setState({
|
|
||||||
imageUrl: res.data.userData.imageUrl,
|
|
||||||
topics: res.data.userData.followedTopics
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
|
|
||||||
axios
|
|
||||||
.get("/user")
|
|
||||||
.then(res => {
|
|
||||||
this.setState({
|
|
||||||
following: res.data.credentials.following.includes(this.state.profile)
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let profileMarkup = this.state.profile ? (
|
|
||||||
<div>
|
|
||||||
<Typography variant="h5">
|
|
||||||
@{this.state.profile}{" "}
|
|
||||||
{this.state.verified ? (
|
|
||||||
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
|
||||||
) : null}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p>loading username...</p>
|
|
||||||
);
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
|
||||||
this.state.topics.map(
|
|
||||||
topic => <MyChip label={topic} key={{ topic }.topic.id} /> // console.log({ topic }.topic.id)
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<p> loading topics...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
|
||||||
<img src={this.state.imageUrl} height="150" width="150" />
|
|
||||||
) : (
|
|
||||||
<img src={noImage} height="150" width="150" />
|
|
||||||
);
|
|
||||||
|
|
||||||
let followMarkup = this.state.following ? (
|
|
||||||
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
|
||||||
unfollow
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
|
||||||
follow
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(this.state.following);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid container spacing={24}>
|
|
||||||
<Grid item sm={4} xs={8}>
|
|
||||||
{imageMarkup}
|
|
||||||
{profileMarkup}
|
|
||||||
{followMarkup}
|
|
||||||
{topicsMarkup}
|
|
||||||
<br />
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
|
||||||
user: state.user
|
|
||||||
});
|
|
||||||
|
|
||||||
user.propTypes = {
|
|
||||||
user: PropTypes.object.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(user);
|
|
||||||
@@ -1,304 +1,117 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from "react";
|
import React, { Component } from 'react';
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from "react-redux";
|
import axios from 'axios';
|
||||||
import axios from "axios";
|
|
||||||
//import '../App.css';
|
//import '../App.css';
|
||||||
// Material-UI
|
import { makeStyles, styled } from '@material-ui/core/styles';
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import Grid from '@material-ui/core/Grid';
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
import Card from '@material-ui/core/Card';
|
||||||
import { Link } from "react-router-dom";
|
import CardMedia from '@material-ui/core/CardMedia';
|
||||||
import Card from "@material-ui/core/Card";
|
import CardContent from '@material-ui/core/CardContent';
|
||||||
import CardMedia from "@material-ui/core/CardMedia";
|
import Chip from '@material-ui/core/Chip';
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
import Paper from '@material-ui/core/Paper';
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
|
|
||||||
import Chip from "@material-ui/core/Chip";
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import AddCircle from "@material-ui/icons/AddCircle";
|
import AddCircle from '@material-ui/icons/AddCircle';
|
||||||
import TextField from "@material-ui/core/TextField";
|
|
||||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
|
||||||
import Paper from "@material-ui/core/Paper";
|
|
||||||
import GridList from "@material-ui/core/GridList";
|
|
||||||
import GridListTile from "@material-ui/core/GridListTile";
|
|
||||||
import GridListTileBar from "@material-ui/core/GridListTileBar";
|
|
||||||
import Container from "@material-ui/core/Container";
|
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import "../App.css";
|
import Profile from '../components/profile/Profile';
|
||||||
import noImage from "../images/no-img.png";
|
import Userline from '../Userline';
|
||||||
import Writing_Microblogs from "../Writing_Microblogs";
|
import noImage from '../images/no-img.png';
|
||||||
|
|
||||||
|
|
||||||
|
const PostCard = styled(Card)({
|
||||||
|
background: 'linear-gradient(45deg, #1da1f2 90%)',
|
||||||
|
border: 3,
|
||||||
|
borderRadius: 3,
|
||||||
|
height:325,
|
||||||
|
width: 345,
|
||||||
|
padding: '0 30px',
|
||||||
|
});
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: "primary"
|
color: 'primary'
|
||||||
});
|
});
|
||||||
|
|
||||||
const styles = {
|
|
||||||
button: {
|
const styles = (theme) => ({
|
||||||
positon: "relative",
|
...theme
|
||||||
float: "left",
|
});
|
||||||
marginLeft: 30,
|
|
||||||
marginTop: 20
|
const handleDelete = () => {
|
||||||
},
|
alert("Delete this topic!");
|
||||||
paper: {
|
}
|
||||||
// marginLeft: "10%",
|
|
||||||
// marginRight: "10%"
|
const handleAddCircle = () => {
|
||||||
},
|
alert("Add topic");
|
||||||
card: {
|
}
|
||||||
marginBottom: 10
|
|
||||||
},
|
|
||||||
profileImage: {
|
|
||||||
marginTop: 20
|
|
||||||
},
|
|
||||||
topicsContainer: {
|
|
||||||
border: "lightgray solid 1px",
|
|
||||||
marginTop: 20,
|
|
||||||
paddingTop: 10,
|
|
||||||
paddingBottom: 10,
|
|
||||||
height: 300
|
|
||||||
},
|
|
||||||
addCircle: {
|
|
||||||
width: 65,
|
|
||||||
height: 65,
|
|
||||||
marginTop: 10
|
|
||||||
},
|
|
||||||
username: {
|
|
||||||
marginBottom: 100
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class user extends Component {
|
class user extends Component {
|
||||||
state = {
|
state = {
|
||||||
profile: null,
|
profile: null,
|
||||||
imageUrl: null,
|
topics: null
|
||||||
topics: null,
|
|
||||||
newTopic: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = topic => {
|
|
||||||
console.log(topic);
|
|
||||||
axios
|
|
||||||
.post(`/deleteTopic`, {
|
|
||||||
unfollow: topic
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
location.reload();
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
handleAddCircle = () => {
|
|
||||||
axios
|
|
||||||
.post("/putTopic", {
|
|
||||||
following: this.state.newTopic
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
location.reload();
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
handleChange(event) {
|
|
||||||
this.setState({
|
|
||||||
newTopic: event.target.value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
console.log(res.data.credentials.handle);
|
||||||
this.setState({
|
this.setState({
|
||||||
profile: res.data.credentials.handle,
|
profile: res.data.credentials.handle
|
||||||
imageUrl: res.data.credentials.imageUrl,
|
|
||||||
verified: res.data.credentials.verified
|
|
||||||
? res.data.credentials.verified
|
|
||||||
: false,
|
|
||||||
topics: res.data.credentials.followedTopics
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/getallPostsforUser")
|
.get("/getAllTopics")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log(res.data);
|
console.log(res.data[1]);
|
||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
topics: res.data
|
||||||
})
|
|
||||||
this.setState({posts: (this.state.posts).sort((a,b) =>
|
|
||||||
-a.createdAt.localeCompare(b.createdAt))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const classes = this.props;
|
||||||
let authenticated = this.props.user.authenticated;
|
|
||||||
|
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<div>
|
<p>
|
||||||
<Typography variant="h5" className={classes.username}>
|
<Typography variant='h5'>{this.state.profile}</Typography>
|
||||||
@{this.state.profile}{" "}
|
</p>) : (<p>loading username...</p>);
|
||||||
{this.state.verified ? (
|
|
||||||
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
|
||||||
) : null}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p className={classes.username}>loading username...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(topic => <MyChip
|
||||||
topic => (
|
label={{topic}.topic.topic}
|
||||||
<MyChip
|
onDelete={handleDelete}/>)
|
||||||
label={topic}
|
) : (<p> loading topics...</p>);
|
||||||
key={topic.id}
|
|
||||||
onDelete={key => this.handleDelete(topic)}
|
|
||||||
/>
|
|
||||||
) // console.log({ topic }.topic.id)
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<p> loading topics...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
|
||||||
<img
|
|
||||||
className={classes.profileImage}
|
|
||||||
src={this.state.imageUrl}
|
|
||||||
height="250"
|
|
||||||
width="250"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<img
|
|
||||||
className={classes.profileImage}
|
|
||||||
src={noImage}
|
|
||||||
height="250"
|
|
||||||
width="250"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
let postMarkup = this.state.posts ? (
|
|
||||||
this.state.posts.map(post => (
|
|
||||||
<Card className={classes.card}>
|
|
||||||
<CardContent>
|
|
||||||
<Typography>
|
|
||||||
{this.state.imageUrl ? (
|
|
||||||
<img src={this.state.imageUrl} height="50" width="50" />
|
|
||||||
) : (
|
|
||||||
<img src={noImage} height="50" width="50" />
|
|
||||||
)}
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="h7">
|
|
||||||
<b>{post.userHandle}</b>
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
|
||||||
{post.createdAt}
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
|
|
||||||
" " + post.createdAt.substring(11,19)}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body1">
|
|
||||||
<b>{post.microBlogTitle}</b>
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</Typography>
|
|
||||||
<br />
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<p>My Posts</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
// FIX: This needs to check if user's profile page being displayed
|
|
||||||
// is the same as the user who is logged in
|
|
||||||
// Can't check for that right now, because this page is always
|
|
||||||
// showing the logged in users profile, instead of retreiving the
|
|
||||||
// profile based on the URL entered
|
|
||||||
let editButtonMarkup = true ? (
|
|
||||||
<Link to="/edit">
|
|
||||||
<Button className={classes.button} variant="outlined" color="primary">
|
|
||||||
Edit Profile
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Grid container spacing={16}>
|
||||||
{/* <Paper className={classes.paper}> */}
|
<Grid item sm={8} xs={12}>
|
||||||
<Grid container direction="column">
|
<p>Post</p>
|
||||||
<Grid item>
|
|
||||||
<Grid container>
|
|
||||||
<Grid item sm>
|
|
||||||
{editButtonMarkup}
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm>
|
|
||||||
{/* <Grid container direction="column"> */}
|
|
||||||
{/* <Grid item sm> */}
|
|
||||||
{imageMarkup}
|
|
||||||
{profileMarkup}
|
|
||||||
{/* </Grid> */}
|
|
||||||
{/* <Grid item sm> */}
|
|
||||||
{/* {postMarkup} */}
|
|
||||||
{/* </Grid> */}
|
|
||||||
{/* </Grid> */}
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm>
|
|
||||||
<Container className={classes.topicsContainer} maxWidth="xs">
|
|
||||||
{topicsMarkup}
|
|
||||||
</Container>
|
|
||||||
<TextField
|
|
||||||
id="newTopic"
|
|
||||||
label="new topic"
|
|
||||||
defaultValue=""
|
|
||||||
margin="normal"
|
|
||||||
variant="outlined"
|
|
||||||
value={this.state.newTopic}
|
|
||||||
onChange={event => this.handleChange(event)}
|
|
||||||
/>
|
|
||||||
<AddCircle
|
|
||||||
className={classes.addCircle}
|
|
||||||
color="primary"
|
|
||||||
// iconStyle={classes.addCircle}
|
|
||||||
clickable
|
|
||||||
onClick={this.handleAddCircle}
|
|
||||||
cursor="pointer"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<Grid container>
|
|
||||||
<Grid item sm />
|
|
||||||
<Grid item>{postMarkup}</Grid>
|
|
||||||
<Grid item sm />
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
<Grid item sm={4} xs={12}>
|
||||||
|
<img src={noImage}/>
|
||||||
|
{profileMarkup}
|
||||||
|
{topicsMarkup}
|
||||||
|
<MyChip
|
||||||
|
icon={<AddCircle />}
|
||||||
|
clickable
|
||||||
|
onClick={handleAddCircle}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
Userline.PropTypes = {
|
||||||
|
handle: PropTypes.object.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
});
|
});
|
||||||
|
|
||||||
user.propTypes = {
|
export default user;
|
||||||
user: PropTypes.object.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
import React, { Component } from "react";
|
|
||||||
import axios from "axios";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
// TODO: Add a read-only '@' in the left side of the handle input
|
|
||||||
// TODO: Add a cancel button, that takes the user back to their profile page
|
|
||||||
|
|
||||||
// Material-UI stuff
|
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
import TextField from "@material-ui/core/TextField";
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
|
||||||
|
|
||||||
const styles = {
|
|
||||||
form: {
|
|
||||||
textAlign: "center"
|
|
||||||
},
|
|
||||||
textField: {
|
|
||||||
marginBottom: 30
|
|
||||||
},
|
|
||||||
pageTitle: {
|
|
||||||
// marginTop: 20,
|
|
||||||
marginBottom: 40
|
|
||||||
},
|
|
||||||
button: {
|
|
||||||
positon: "relative",
|
|
||||||
marginBottom: 10
|
|
||||||
},
|
|
||||||
progress: {
|
|
||||||
position: "absolute"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export class verify extends Component {
|
|
||||||
|
|
||||||
// Constructor for the state
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.state = {
|
|
||||||
handle: "",
|
|
||||||
loading: false,
|
|
||||||
errors: {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// // Runs whenever the submit button is clicked.
|
|
||||||
handleSubmit = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
const verifyHandle = {
|
|
||||||
user: this.state.handle
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
|
||||||
.post("/verifyUser", verifyHandle)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res);
|
|
||||||
this.setState({
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
// this.props.history.push('/');
|
|
||||||
// TODO: Need to redirect user to their profile page
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
this.setState({
|
|
||||||
errors: err.response.data,
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Updates the state whenever one of the textboxes changes.
|
|
||||||
// The key is the name of the textbox and the value is the
|
|
||||||
// value in the text box.
|
|
||||||
// Also sets errors to null of textboxes that have been edited
|
|
||||||
handleChange = (event) => {
|
|
||||||
this.setState({
|
|
||||||
[event.target.name]: event.target.value,
|
|
||||||
errors: {
|
|
||||||
[event.target.name]: null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { classes } = this.props;
|
|
||||||
const { errors, loading } = this.state;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid container className={classes.form}>
|
|
||||||
<Grid item sm />
|
|
||||||
<Grid item sm>
|
|
||||||
<Typography variant="h4" className={classes.pageTitle}>
|
|
||||||
Verify Users
|
|
||||||
</Typography>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
|
||||||
<TextField
|
|
||||||
id="handle"
|
|
||||||
name="handle"
|
|
||||||
label="Username"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.handle}
|
|
||||||
// helperText={errors.handle}
|
|
||||||
// error={errors.handle ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<Grid container direction="column">
|
|
||||||
<Grid item>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.button}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
{loading && (
|
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<Button
|
|
||||||
variant="oulined"
|
|
||||||
color="primary"
|
|
||||||
// className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/user'
|
|
||||||
>
|
|
||||||
Back to Profile
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</form>
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm />
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
verify.propTypes = {
|
|
||||||
classes: PropTypes.object.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default withStyles(styles)(verify);
|
|
||||||
Reference in New Issue
Block a user