mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Compare commits
61 Commits
Beautify
...
engage_mic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a2af4e9bb | ||
|
|
c34f06f130 | ||
|
|
64cc9bd156 | ||
|
|
6a78d74930 | ||
|
|
4e817c9647 | ||
|
|
7976110e2b | ||
|
|
3da2449050 | ||
|
|
607ea3fd55 | ||
|
|
e8110d643f | ||
|
|
c3091cc10a | ||
|
|
81749c19ce | ||
|
|
1ccc195036 | ||
|
|
0aaa9014b9 | ||
|
|
2de3da928a | ||
|
|
42c53fdbc4 | ||
|
|
c8aa1fd050 | ||
|
|
c6022dbc38 | ||
|
|
1d26eb97ad | ||
| 9372a092ad | |||
| 7a6ac8499c | |||
| 6149e15b35 | |||
| 80670d054e | |||
| 947e5b01a4 | |||
| 7cc8a3f11f | |||
| 7476833f0a | |||
| 903ea35662 | |||
| e644498108 | |||
| 97bc9c4fb1 | |||
|
|
f2dac314e5 | ||
| b01aa92f96 | |||
| d6876eab0b | |||
| f4bedea2c7 | |||
| d4ea00d2e9 | |||
| acd33d6a96 | |||
| f1e4362205 | |||
| 1e4b2d16ef | |||
| e8e69cec31 | |||
|
|
ae89e3d63b | ||
|
|
f60c045483 | ||
|
|
1842eef2f8 | ||
| 56323801aa | |||
| ce984df437 | |||
| 112988c8fb | |||
| 325d37f0de | |||
|
|
35e5cf8e9d | ||
|
|
649b9b4a69 | ||
|
|
e73b2d02f3 | ||
|
|
50bc73870b | ||
| ca1d86acf1 | |||
|
|
da14700987 | ||
|
|
26afabe709 | ||
|
|
a61c296ddf | ||
|
|
1337071bec | ||
|
|
cd19364efc | ||
| 3c31db9bf5 | |||
|
|
8438ce27cf | ||
|
|
6db14e3868 | ||
| 3d875e2bde | |||
|
|
b20408c144 | ||
|
|
97998a8f09 | ||
|
|
13a1401759 |
@@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable prefer-arrow-callback */
|
/* 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');
|
||||||
|
|
||||||
|
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
const newPost = {
|
const newPost = {
|
||||||
@@ -17,30 +19,226 @@ exports.putPost = (req, res) => {
|
|||||||
|
|
||||||
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 is wrong'});
|
return res.status(500).json({ error: 'something went wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
|
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||||
.then((data) => {
|
post_query.get()
|
||||||
|
.then(function(myPosts) {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
data.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
|
.then(function() {
|
||||||
|
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
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,
|
||||||
|
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 {
|
||||||
|
return res.status(400).json({ error: 'Post has already been quoted.' });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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) => {
|
||||||
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.likePost = (req, res) => {
|
||||||
|
let postData;
|
||||||
|
const likeDoc = admin.firestore().collection('likes').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) {
|
||||||
|
postData = doc.data();
|
||||||
|
return likeDoc.get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return res.status(404).json({error: 'Post not found'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
if (data.empty) {
|
||||||
|
return admin.firestore().collection('likes').add({
|
||||||
|
postId : req.params.postId,
|
||||||
|
userHandle: req.user.handle
|
||||||
|
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
postData.likeCount++;
|
||||||
|
return postDoc.update({likeCount : postData.likeCount})
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return res.status(200).json(postData);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.unlikePost = (req, res) => {
|
||||||
|
|
||||||
|
let postData;
|
||||||
|
const likeDoc = admin.firestore().collection('likes').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) {
|
||||||
|
postData = doc.data();
|
||||||
|
return likeDoc.get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return res.status(404).json({error: 'Post not found'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
return db
|
||||||
|
.doc(`/likes/${data.docs[0].id}`)
|
||||||
|
.delete()
|
||||||
|
.then(() => {
|
||||||
|
postData.likeCount--;
|
||||||
|
return postDoc.update({ likeCount: postData.likeCount });
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
res.status(200).json(postData);
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
})
|
})
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.getFilteredPosts = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
||||||
|
|||||||
@@ -1,52 +1,93 @@
|
|||||||
/* 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);
|
||||||
|
|
||||||
const newTopic = {
|
// add stuff
|
||||||
topic: req.body.topic
|
userRef
|
||||||
};
|
.set({ followedTopics: new_following }, { merge: true })
|
||||||
|
.then(doc => {
|
||||||
admin.firestore().collection('topics').add(newTopic)
|
return res
|
||||||
.then((doc) => {
|
.status(201)
|
||||||
const resTopic = newTopic;
|
.json({ message: `Following ${req.body.following}` });
|
||||||
newTopic.topicId = doc.id;
|
|
||||||
return res.status(200).json(resTopic);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
return res.status(500).json({ err });
|
||||||
return res.status(500).json({ error: 'something is wrong'});
|
});
|
||||||
|
return res.status(200).json({ message: "OK" });
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getAllTopics = (req, res) => {
|
exports.getAllTopics = (req, res) => {
|
||||||
admin.firestore().collection('topics').get()
|
admin
|
||||||
.then((data) => {
|
.firestore()
|
||||||
|
.collection("topics")
|
||||||
|
.get()
|
||||||
|
.then(data => {
|
||||||
let topics = [];
|
let topics = [];
|
||||||
data.forEach(function(doc) {
|
data.forEach(function(doc) {
|
||||||
topics.push(doc.data());
|
topics.push({
|
||||||
|
topic: doc.data().topic,
|
||||||
|
id: doc.id
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return res.status(200).json(topics);
|
return res.status(200).json(topics);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Failed to fetch all topics.'})
|
return res.status(500).json({ error: "Failed to fetch all topics." });
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteTopic = (req, res) => {
|
exports.deleteTopic = (req, res) => {
|
||||||
const topic = db.doc(`/topics/${req.params.topicId}`);
|
let new_following = [];
|
||||||
topic.get().then((doc) => {
|
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||||
if (!doc.exists) {
|
userRef
|
||||||
return res.status(404).json({error: 'Topic not found'});
|
.get()
|
||||||
} else {
|
.then(doc => {
|
||||||
return topic.delete();
|
new_following = doc.data().followedTopics;
|
||||||
|
// remove username from array
|
||||||
|
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}` });
|
||||||
})
|
})
|
||||||
.then(() => {
|
.catch(err => {
|
||||||
res.json({ message: 'Topic successfully deleted!'});
|
return res.status(500).json({ err });
|
||||||
|
});
|
||||||
|
return res.status(200).json({ message: "ok" });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
return res.status(500).json({ err });
|
||||||
return res.status(500).json({error: 'Failed to delete topic.'})
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
return res.status(500).json({ err });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/* 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");
|
||||||
@@ -55,7 +54,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)
|
||||||
@@ -65,25 +64,28 @@ 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
|
||||||
};
|
};
|
||||||
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." });
|
||||||
@@ -121,13 +123,15 @@ exports.login = (req, res) => {
|
|||||||
// Email/username field is username since it's not in email format
|
// Email/username field is username since it's not in email format
|
||||||
if (!user.email.match(emailRegEx)) {
|
if (!user.email.match(emailRegEx)) {
|
||||||
var userDoc = db.collection("users").doc(`${user.email}`);
|
var userDoc = db.collection("users").doc(`${user.email}`);
|
||||||
userDoc.get()
|
userDoc
|
||||||
|
.get()
|
||||||
.then(function(doc) {
|
.then(function(doc) {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
user.email = doc.data().email;
|
user.email = doc.data().email;
|
||||||
}
|
} else {
|
||||||
else {
|
return res
|
||||||
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
.status(403)
|
||||||
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
@@ -135,16 +139,22 @@ exports.login = (req, res) => {
|
|||||||
firebase
|
firebase
|
||||||
.auth()
|
.auth()
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
.signInWithEmailAndPassword(user.email, user.password)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return data.user.getIdToken();
|
return data.user.getIdToken();
|
||||||
})
|
})
|
||||||
.then((token) => {
|
.then(token => {
|
||||||
return res.status(200).json({ token });
|
return res.status(200).json({ token });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
if (
|
||||||
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
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 res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
@@ -152,7 +162,9 @@ exports.login = (req, res) => {
|
|||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
if (!doc.exists) {
|
if (!doc.exists) {
|
||||||
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
return res
|
||||||
|
.status(403)
|
||||||
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
}
|
}
|
||||||
return res.status(500).send(err);
|
return res.status(500).send(err);
|
||||||
});
|
});
|
||||||
@@ -162,15 +174,19 @@ exports.login = (req, res) => {
|
|||||||
firebase
|
firebase
|
||||||
.auth()
|
.auth()
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
.signInWithEmailAndPassword(user.email, user.password)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return data.user.getIdToken();
|
return data.user.getIdToken();
|
||||||
})
|
})
|
||||||
.then((token) => {
|
.then(token => {
|
||||||
return res.status(200).json({ token });
|
return res.status(200).json({ token });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
if (
|
||||||
|
err.code === "auth/user-not-found" ||
|
||||||
|
err.code === "auth/invalid-email" ||
|
||||||
|
err.code === "auth/wrong-password"
|
||||||
|
) {
|
||||||
return res
|
return res
|
||||||
.status(403)
|
.status(403)
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
@@ -180,56 +196,82 @@ exports.login = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Deletes user account
|
//Deletes user account and all associated data
|
||||||
exports.deleteUser = (req, res) => {
|
exports.deleteUser = (req, res) => {
|
||||||
var currentUser;
|
// Get the profile image filename
|
||||||
firebase.auth().onAuthStateChanged(function(user) {
|
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
||||||
currentUser = user;
|
let imageFileName;
|
||||||
if (currentUser) {
|
req.userData.imageUrl
|
||||||
var post_query = db.collection("posts").where("userHandle", "==", req.user.handle);
|
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
|
||||||
post_query.get()
|
: (imageFileName = "no-img.png");
|
||||||
.then(function(myPosts) {
|
|
||||||
myPosts.forEach(function(doc) {
|
const userId = req.userData.userId;
|
||||||
doc.ref.delete();
|
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;
|
return;
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
res.status(200).send("Successfully removed all user's posts from database.");
|
|
||||||
return;
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
res.status(500).send("Failed to remove all user's posts from database.", err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
db.collection("users").doc(`${req.user.handle}`).delete()
|
waitPromise
|
||||||
.then(function() {
|
.then(() => {
|
||||||
res.status(200).send("Sucessfully removed user from database.");
|
if (Object.keys(errors) > 0) {
|
||||||
return;
|
return res.status(500).json(errors);
|
||||||
})
|
} else {
|
||||||
.catch(function(err) {
|
return res.status(200).json({
|
||||||
res.status(500).send("Failed to remove user from database.", err);
|
message: `All data for ${req.userData.handle} has been deleted.`
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentUser.delete()
|
|
||||||
.then(function() {
|
|
||||||
console.log("Successfully deleted user.");
|
|
||||||
res.status(200).send("Sucessfully deleted user.");
|
|
||||||
return;
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log("Failed to delete user.", err);
|
|
||||||
res.status(500).send("Failed to delete user.");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
})
|
||||||
console.log("Failed to deleter user or cannot get user.");
|
.catch(err => {
|
||||||
res.status(500).send("Failed to deleter user or cannot get user.");
|
return res.status(500).json({ error: err });
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -238,10 +280,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);
|
||||||
});
|
});
|
||||||
@@ -259,13 +301,11 @@ 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
|
return res.status(201).json({
|
||||||
.status(201)
|
|
||||||
.json({
|
|
||||||
general: `${req.user.handle}'s profile info has been updated.`
|
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"
|
||||||
@@ -277,14 +317,15 @@ 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 });
|
||||||
});
|
});
|
||||||
@@ -294,17 +335,160 @@ 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,7 +16,13 @@ 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
|
||||||
@@ -31,7 +37,7 @@ app.post("/login", login);
|
|||||||
//Deletes user account
|
//Deletes user account
|
||||||
app.delete("/delete", fbAuth, deleteUser);
|
app.delete("/delete", fbAuth, deleteUser);
|
||||||
|
|
||||||
app.get("/getUser", fbAuth, getUserDetails);
|
app.post("/getUserDetails", 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);
|
||||||
@@ -41,24 +47,54 @@ 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, putPost
|
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
|
||||||
} = require("./handlers/post");
|
|
||||||
|
|
||||||
app.get("/getallPostsforUser", getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
|
app.get("/getallPosts", getallPosts);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -68,6 +104,9 @@ app.post("/putTopic", fbAuth, putTopic);
|
|||||||
app.get("/getAllTopics", fbAuth, getAllTopics);
|
app.get("/getAllTopics", fbAuth, getAllTopics);
|
||||||
|
|
||||||
// delete a specific topic
|
// delete a specific topic
|
||||||
app.delete("/deleteTopic/:topicId", fbAuth, deleteTopic);
|
app.post("/deleteTopic", fbAuth, deleteTopic);
|
||||||
|
|
||||||
|
// get topic for this user
|
||||||
|
app.post("/getUserTopics", fbAuth, getUserTopics);
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
|
|||||||
@@ -41,5 +41,5 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,33 +10,33 @@ import jwtDecode from "jwt-decode";
|
|||||||
// 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 otherUser from "./pages/otherUser";
|
||||||
|
|
||||||
const theme = createMuiTheme(themeObject);
|
const theme = createMuiTheme(themeObject);
|
||||||
|
|
||||||
const token = localStorage.FBIdToken;
|
const token = localStorage.FBIdToken;
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decodedToken = jwtDecode(token);
|
const decodedToken = jwtDecode(token);
|
||||||
if (decodedToken.exp * 1000 < Date.now()) {
|
if (decodedToken.exp * 1000 < Date.now()) {
|
||||||
@@ -44,7 +44,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,33 +53,35 @@ 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="/logout" component={logout} />
|
||||||
<Route exact path="/delete" component={Delete} />
|
<Route exact path="/delete" component={Delete} />
|
||||||
|
|
||||||
|
<Route exact path="/home" component={home} />
|
||||||
<Route exact path="/user" component={user} />
|
<Route exact path="/user" component={user} />
|
||||||
<Route exact path="/home" component={writeMicroblog} />
|
|
||||||
<Route exact path="/edit" component={editProfile} />
|
<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} />
|
<AuthRoute exact path="/" component={home} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>
|
</Provider>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
|
|||||||
@@ -1,27 +1,22 @@
|
|||||||
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) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
value: '',
|
value: "",
|
||||||
title: '',
|
title: "",
|
||||||
topics: '',
|
topics: "",
|
||||||
characterCount: 250
|
characterCount: 250
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(event) {
|
handleChange(event) {
|
||||||
@@ -33,61 +28,90 @@ class Writing_Microblogs extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
|
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||||
const postData = {
|
const postData = {
|
||||||
body: this.state.value,
|
body: this.state.value,
|
||||||
userImage: "bing-url",
|
userImage: "bing-url",
|
||||||
microBlogTitle: this.state.title,
|
microBlogTitle: this.state.title,
|
||||||
microBlogTopics: this.state.topics.split(', ')
|
microBlogTopics: this.state.topics.split(", ")
|
||||||
}
|
};
|
||||||
const headers = {
|
const headers = {
|
||||||
headers: { 'Content-Type': 'application/json'}
|
headers: { "Content-Type": "application/json" }
|
||||||
}
|
};
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post("/putPost", postData, headers)
|
.post("/putPost", postData, headers)
|
||||||
.then((res) =>{
|
.then(res => {
|
||||||
alert('Post was shared successfully!')
|
alert("Post was shared successfully!");
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
alert('An error occured.');
|
alert("An error occured.");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
})
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({value: '', title: '',characterCount: 250, topics: ''})
|
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
handleChangeforPost(event) {
|
||||||
this.setState({value: event.target.value })
|
this.setState({ value: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
handleChangeforCharacterCount(event) {
|
||||||
const charCount = event.target.value.length
|
const charCount = event.target.value.length;
|
||||||
const charRemaining = 250 - charCount
|
const charRemaining = 250 - charCount;
|
||||||
this.setState({characterCount: charRemaining })
|
this.setState({ characterCount: charRemaining });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
width: "200px",
|
||||||
|
height: "50px",
|
||||||
|
marginTop: "180px",
|
||||||
|
marginLeft: "50px"
|
||||||
|
}}
|
||||||
|
>
|
||||||
<form>
|
<form>
|
||||||
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
|
<textarea
|
||||||
|
placeholder="Enter Microblog Title"
|
||||||
|
value={this.state.title}
|
||||||
|
required
|
||||||
|
onChange={this.handleChange}
|
||||||
|
cols={30}
|
||||||
|
rows={1}
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
|
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
|
||||||
<form>
|
<form>
|
||||||
<textarea placeholder="Enter topics seperated by a comma" value={this.state.topics} required onChange={this.handleChangeforTopics} cols={40} rows={1} />
|
<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 style={{ width: "200px", marginLeft: "50px" }}>
|
<div style={{ width: "200px", marginLeft: "50px" }}>
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
|
<textarea
|
||||||
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
|
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" }}>
|
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||||
</div>
|
</div>
|
||||||
@@ -97,11 +121,8 @@ class Writing_Microblogs extends Component {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Writing_Microblogs;
|
export default Writing_Microblogs;
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
/* 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: {
|
||||||
@@ -38,38 +38,47 @@ export class Navbar extends Component {
|
|||||||
return (
|
return (
|
||||||
<AppBar>
|
<AppBar>
|
||||||
<ToolBar>
|
<ToolBar>
|
||||||
<Button component={ Link } to='/'>
|
<Button component={Link} to="/">
|
||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
{!authenticated && <Button component={ Link } to='/login'>
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/user">
|
||||||
|
Profile
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{!authenticated && (
|
||||||
|
<Button component={Link} to="/login">
|
||||||
Login
|
Login
|
||||||
</Button>}
|
</Button>
|
||||||
{!authenticated && <Button component={ Link } to='/signup'>
|
)}
|
||||||
|
{!authenticated && (
|
||||||
|
<Button component={Link} to="/signup">
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>}
|
</Button>
|
||||||
{authenticated && <Button component={ Link } to='/logout'>
|
)}
|
||||||
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/search">
|
||||||
|
Search
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/logout">
|
||||||
Logout
|
Logout
|
||||||
</Button>}
|
</Button>
|
||||||
{authenticated && <Button component={ Link } to='/delete'>
|
)}
|
||||||
Delete Account
|
|
||||||
</Button>}
|
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</AppBar>
|
</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;
|
|
||||||
|
|||||||
@@ -1,12 +1,86 @@
|
|||||||
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import '../App.css';
|
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 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" />
|
||||||
@@ -34,4 +108,176 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Home;
|
|
||||||
|
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) {
|
||||||
|
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);
|
||||||
80
twistter-frontend/src/pages/Search.js
Normal file
80
twistter-frontend/src/pages/Search.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
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;
|
||||||
@@ -6,6 +6,7 @@ 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";
|
||||||
@@ -220,12 +221,34 @@ 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 />
|
||||||
|
|||||||
158
twistter-frontend/src/pages/otherUser.js
Normal file
158
twistter-frontend/src/pages/otherUser.js
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/* 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,25 +1,74 @@
|
|||||||
/* 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 axios from 'axios';
|
import { connect } from "react-redux";
|
||||||
|
import axios from "axios";
|
||||||
//import '../App.css';
|
//import '../App.css';
|
||||||
import { makeStyles, styled } from '@material-ui/core/styles';
|
// Material-UI
|
||||||
import Grid from '@material-ui/core/Grid';
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
import Card from '@material-ui/core/Card';
|
import { makeStyles, styled } from "@material-ui/core/styles";
|
||||||
import Chip from '@material-ui/core/Chip';
|
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 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 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 Userline from '../Userline';
|
import "../App.css";
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from "../images/no-img.png";
|
||||||
|
import Writing_Microblogs from "../Writing_Microblogs";
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: 'primary'
|
color: "primary"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
button: {
|
||||||
|
positon: "relative",
|
||||||
|
float: "left",
|
||||||
|
marginLeft: 30,
|
||||||
|
marginTop: 20
|
||||||
|
},
|
||||||
|
paper: {
|
||||||
|
// marginLeft: "10%",
|
||||||
|
// marginRight: "10%"
|
||||||
|
},
|
||||||
|
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,
|
||||||
@@ -28,13 +77,11 @@ class user extends Component {
|
|||||||
newTopic: null
|
newTopic: null
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = (topic) => {
|
handleDelete = topic => {
|
||||||
alert(`Delete topic: ${topic}!`);
|
console.log(topic);
|
||||||
}
|
axios
|
||||||
|
.post(`/deleteTopic`, {
|
||||||
handleAddCircle = () => {
|
unfollow: topic
|
||||||
axios.post('/putTopic', {
|
|
||||||
topic: this.state.newTopic
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
location.reload();
|
location.reload();
|
||||||
@@ -42,12 +89,25 @@ class user extends Component {
|
|||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
handleAddCircle = () => {
|
||||||
|
axios
|
||||||
|
.post("/putTopic", {
|
||||||
|
following: this.state.newTopic
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
location.reload();
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
handleChange(event) {
|
handleChange(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
newTopic: event.target.value
|
newTopic: event.target.value
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -56,51 +116,150 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
profile: res.data.credentials.handle,
|
profile: res.data.credentials.handle,
|
||||||
imageUrl: res.data.credentials.imageUrl
|
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("/getAllTopics")
|
.get("/getallPostsforUser")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
// console.log(res.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
topics: res.data
|
posts: 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() {
|
|
||||||
const classes = this.props;
|
|
||||||
let profileMarkup = this.state.profile ? (
|
|
||||||
<p>
|
|
||||||
<Typography variant='h5'>{this.state.profile}</Typography>
|
|
||||||
</p>) : (<p>loading username...</p>);
|
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { classes } = this.props;
|
||||||
|
let authenticated = this.props.user.authenticated;
|
||||||
|
|
||||||
|
let profileMarkup = this.state.profile ? (
|
||||||
|
<div>
|
||||||
|
<Typography variant="h5" className={classes.username}>
|
||||||
|
@{this.state.profile}{" "}
|
||||||
|
{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(topic => <MyChip
|
this.state.topics.map(
|
||||||
label={{topic}.topic.topic}
|
topic => (
|
||||||
key={{topic}.topic.topicId}
|
<MyChip
|
||||||
onDelete={ (topic) => this.handleDelete(topic)}/>)
|
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 ? (
|
let imageMarkup = this.state.imageUrl ? (
|
||||||
<img
|
<img
|
||||||
|
className={classes.profileImage}
|
||||||
src={this.state.imageUrl}
|
src={this.state.imageUrl}
|
||||||
height="250"
|
height="250"
|
||||||
width="250"
|
width="250"
|
||||||
/>
|
/>
|
||||||
) : (<img src={noImage}/>);
|
) : (
|
||||||
|
<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 (
|
||||||
<Grid container spacing={16}>
|
<div>
|
||||||
<Grid item sm={8} xs={12}>
|
{/* <Paper className={classes.paper}> */}
|
||||||
<p>Post</p>
|
<Grid container direction="column">
|
||||||
|
<Grid item>
|
||||||
|
<Grid container>
|
||||||
|
<Grid item sm>
|
||||||
|
{editButtonMarkup}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={4} xs={12}>
|
<Grid item sm>
|
||||||
|
{/* <Grid container direction="column"> */}
|
||||||
|
{/* <Grid item sm> */}
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
|
{/* </Grid> */}
|
||||||
|
{/* <Grid item sm> */}
|
||||||
|
{/* {postMarkup} */}
|
||||||
|
{/* </Grid> */}
|
||||||
|
{/* </Grid> */}
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm>
|
||||||
|
<Container className={classes.topicsContainer} maxWidth="xs">
|
||||||
{topicsMarkup}
|
{topicsMarkup}
|
||||||
|
</Container>
|
||||||
<TextField
|
<TextField
|
||||||
id="newTopic"
|
id="newTopic"
|
||||||
label="new topic"
|
label="new topic"
|
||||||
@@ -108,17 +267,38 @@ class user extends Component {
|
|||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={this.state.newTopic}
|
value={this.state.newTopic}
|
||||||
onChange={ (event) => this.handleChange(event)}
|
onChange={event => this.handleChange(event)}
|
||||||
/>
|
/>
|
||||||
<AddCircle
|
<AddCircle
|
||||||
|
className={classes.addCircle}
|
||||||
color="primary"
|
color="primary"
|
||||||
|
// iconStyle={classes.addCircle}
|
||||||
clickable
|
clickable
|
||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
|
cursor="pointer"
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Grid container>
|
||||||
|
<Grid item sm />
|
||||||
|
<Grid item>{postMarkup}</Grid>
|
||||||
|
<Grid item sm />
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default user;
|
const mapStateToProps = state => ({
|
||||||
|
user: state.user
|
||||||
|
});
|
||||||
|
|
||||||
|
user.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||||
|
|||||||
153
twistter-frontend/src/pages/verify.js
Normal file
153
twistter-frontend/src/pages/verify.js
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
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