mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Merge branch 'master' into dms
This commit is contained in:
commit
88064c55a3
@ -1,6 +1,8 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/always-return */
|
||||
const admin = require('firebase-admin');
|
||||
const { db } = require('../util/admin');
|
||||
|
||||
|
||||
exports.putPost = (req, res) => {
|
||||
const newPost = {
|
||||
@ -12,7 +14,8 @@ exports.putPost = (req, res) => {
|
||||
createdAt: new Date().toISOString(),
|
||||
likeCount: 0,
|
||||
commentCount: 0,
|
||||
microBlogTopics: req.body.microBlogTopics
|
||||
microBlogTopics: req.body.microBlogTopics,
|
||||
quoteBody: null
|
||||
};
|
||||
|
||||
admin.firestore().collection('posts').add(newPost)
|
||||
@ -30,6 +33,7 @@ exports.putPost = (req, res) => {
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||
|
||||
post_query.get()
|
||||
.then(function(myPosts) {
|
||||
let posts = [];
|
||||
@ -39,11 +43,11 @@ exports.getallPostsforUser = (req, res) => {
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||
return;
|
||||
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
||||
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve user's posts from database.", err);
|
||||
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
||||
});
|
||||
};
|
||||
|
||||
@ -58,14 +62,236 @@ exports.getallPosts = (req, res) => {
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
res.status(200).send("Successfully retrieved every post from database.");
|
||||
return;
|
||||
return res.status(200).json("Successfully retrieved every post from database.");
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve posts from database.", 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({
|
||||
quoteId : req.params.postId,
|
||||
userHandle : req.user.handle,
|
||||
quoteBody : req.body.quoteBody
|
||||
})
|
||||
.then(() => {
|
||||
const post = {
|
||||
body: quoteData.body,
|
||||
userHandle : req.user.handle,
|
||||
quoteBody: req.body.quoteBody,
|
||||
createdAt : new Date().toISOString(),
|
||||
userImage: req.body.userImage,
|
||||
likeCount: 0,
|
||||
commentCount: 0,
|
||||
userID: req.user.uid,
|
||||
microBlogTitle: quoteData.microBlogTitle,
|
||||
microBlogTopics: quoteData.microBlogTopics,
|
||||
quoteId: req.params.postId
|
||||
}
|
||||
return admin.firestore().collection('posts').add(post)
|
||||
.then((doc) => {
|
||||
doc.update({postId: doc.id})
|
||||
const resPost = post;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
})
|
||||
}
|
||||
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({
|
||||
quoteId : req.params.postId,
|
||||
userHandle : req.user.handle,
|
||||
quoteBody: null
|
||||
})
|
||||
.then(() => {
|
||||
const post = {
|
||||
userHandle : req.user.handle,
|
||||
body: quoteData.body,
|
||||
quoteBody: null,
|
||||
createdAt : new Date().toISOString(),
|
||||
likeCount: 0,
|
||||
commentCount: 0,
|
||||
userID: req.user.uid,
|
||||
userImage: req.body.userImage,
|
||||
microBlogTitle: quoteData.microBlogTitle,
|
||||
microBlogTopics: quoteData.microBlogTopics,
|
||||
quoteId: req.params.postId
|
||||
}
|
||||
return admin.firestore().collection('posts').add(post)
|
||||
.then((doc) => {
|
||||
doc.update({postId: doc.id})
|
||||
const resPost = post;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
else {
|
||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.status(500).json({error: 'Something is wrong'});
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
exports.checkforLikePost = (req, res) => {
|
||||
const likedPostDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||
.where('postId', '==', req.params.postId).limit(1);
|
||||
let result;
|
||||
|
||||
likedPostDoc.get()
|
||||
.then((data) => {
|
||||
if (data.empty) {
|
||||
result = false;
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Something is wrong'});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
exports.getFilteredPosts = (req, res) => {
|
||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
||||
};
|
||||
|
||||
@ -1,20 +1,28 @@
|
||||
const { admin, db } = require("../util/admin");
|
||||
exports.putTopic = (req, res) => {
|
||||
const newTopic = {
|
||||
topic: req.body.topic
|
||||
};
|
||||
|
||||
admin
|
||||
.firestore()
|
||||
.collection("topics")
|
||||
.add(newTopic)
|
||||
let new_following = [];
|
||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||
userRef
|
||||
.get()
|
||||
.then(doc => {
|
||||
const resTopic = newTopic;
|
||||
return res.status(200).json(resTopic);
|
||||
new_following = doc.data().followedTopics;
|
||||
new_following.push(req.body.following);
|
||||
|
||||
// add stuff
|
||||
userRef
|
||||
.set({ followedTopics: 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(200).json({ message: "OK" });
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "something is wrong" });
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
};
|
||||
|
||||
@ -40,21 +48,46 @@ exports.getAllTopics = (req, res) => {
|
||||
};
|
||||
|
||||
exports.deleteTopic = (req, res) => {
|
||||
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||
topic
|
||||
let new_following = [];
|
||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||
userRef
|
||||
.get()
|
||||
.then(doc => {
|
||||
if (!doc.exists) {
|
||||
return res.status(404).json({ error: "Topic not found" });
|
||||
} else {
|
||||
return topic.delete();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
return res.json({ message: "Topic successfully deleted!" });
|
||||
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}` });
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
return res.status(200).json({ message: "ok" });
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Failed to delete topic." });
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
};
|
||||
|
||||
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 });
|
||||
});
|
||||
};
|
||||
|
||||
@ -203,9 +203,9 @@ 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'
|
||||
req.userData.imageUrl
|
||||
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
|
||||
: (imageFileName = "no-img.png");
|
||||
|
||||
const userId = req.userData.userId;
|
||||
let errors = {};
|
||||
@ -223,56 +223,58 @@ exports.deleteUser = (req, res) => {
|
||||
let auth = admin.auth().deleteUser(userId);
|
||||
|
||||
// Deletes database data
|
||||
let data = db.collection("users").doc(`${req.user.handle}`).delete();
|
||||
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()
|
||||
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")
|
||||
let posts = db
|
||||
.collection("posts")
|
||||
.where("userHandle", "==", req.user.handle)
|
||||
.get()
|
||||
.then((query) => {
|
||||
query.forEach((snap) => {
|
||||
.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))
|
||||
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});
|
||||
})
|
||||
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
|
||||
@ -353,55 +355,67 @@ exports.getAuthenticatedUser = (req, res) => {
|
||||
// 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"});
|
||||
return res.status(403).json({ error: "This must be done as Admin" });
|
||||
}
|
||||
|
||||
db.doc(`/users/${req.body.user}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
.then(doc => {
|
||||
if (doc.exists) {
|
||||
let verifiedUser = doc.data();
|
||||
verifiedUser.verified = true;
|
||||
return db.doc(`/users/${req.body.user}`).set(verifiedUser, {merge: 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`});
|
||||
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`});
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: `${req.body.user} is now verified` });
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: err.code});
|
||||
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"});
|
||||
return res.status(403).json({ error: "This must be done as Admin" });
|
||||
}
|
||||
|
||||
db.doc(`/users/${req.body.user}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
.then(doc => {
|
||||
if (doc.exists) {
|
||||
let unverifiedUser = doc.data();
|
||||
unverifiedUser.verified = false;
|
||||
return db.doc(`/users/${req.body.user}`).set(unverifiedUser, {merge: true});
|
||||
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`});
|
||||
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`});
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: `${req.body.user} is no longer verified` });
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: err.code});
|
||||
return res.status(500).json({ error: err.code });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Returns all the DMs that the user is currently participating in
|
||||
exports.getDirectMessages = (req, res) => {
|
||||
@ -931,19 +945,80 @@ exports.checkDirectMessagesEnabled = (req, res) => {
|
||||
}
|
||||
|
||||
exports.getUserHandles = (req, res) => {
|
||||
admin
|
||||
.firestore()
|
||||
.collection("users")
|
||||
db.doc(`/users/${req.body.userHandle}`)
|
||||
.get()
|
||||
.then(data => {
|
||||
let users = [];
|
||||
data.forEach(function(doc) {
|
||||
users.push(doc.data().handle);
|
||||
});
|
||||
return res.status(200).json(users);
|
||||
.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(200).json({ message: "ok" });
|
||||
});
|
||||
};
|
||||
|
||||
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(200).json({ message: "ok" });
|
||||
});
|
||||
};
|
||||
|
||||
@ -24,7 +24,10 @@ const {
|
||||
updateProfileInfo,
|
||||
verifyUser,
|
||||
unverifyUser,
|
||||
getUserHandles
|
||||
getUserHandles,
|
||||
addSubscription,
|
||||
getSubs,
|
||||
removeSub
|
||||
} = require("./handlers/users");
|
||||
|
||||
// Adds a user to the database and registers them in firebase with
|
||||
@ -56,6 +59,8 @@ app.post("/dms/toggle", fbAuth, toggleDirectMessages);
|
||||
|
||||
app.get("/getUser", fbAuth, getUserDetails);
|
||||
|
||||
app.post("/getUserDetails", fbAuth, getUserDetails);
|
||||
|
||||
// Returns all profile data of the currently logged in user
|
||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||
|
||||
@ -74,13 +79,22 @@ app.post("/verifyUser", fbAuth, verifyUser);
|
||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
||||
|
||||
// get user handles with search phase
|
||||
app.get("/getUserHandles", fbAuth, getUserHandles);
|
||||
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 *
|
||||
*------------------------------------------------------------------*/
|
||||
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
|
||||
|
||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||
|
||||
@ -89,11 +103,23 @@ app.get("/getallPosts", getallPosts);
|
||||
// Adds one post to the database
|
||||
app.post("/putPost", fbAuth, putPost);
|
||||
|
||||
app.get("/like/:postId", fbAuth, likePost);
|
||||
app.get("/unlike/:postId", fbAuth, unlikePost);
|
||||
app.get("/checkforLikePost/:postId", fbAuth, checkforLikePost);
|
||||
|
||||
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
||||
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/topic.js *
|
||||
*------------------------------------------------------------------*/
|
||||
const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic");
|
||||
const {
|
||||
putTopic,
|
||||
getAllTopics,
|
||||
deleteTopic,
|
||||
getUserTopics
|
||||
} = require("./handlers/topic");
|
||||
|
||||
// add topic to database
|
||||
app.post("/putTopic", fbAuth, putTopic);
|
||||
@ -102,6 +128,9 @@ app.post("/putTopic", fbAuth, putTopic);
|
||||
app.get("/getAllTopics", fbAuth, getAllTopics);
|
||||
|
||||
// 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);
|
||||
|
||||
@ -43,5 +43,5 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
||||
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
||||
}
|
||||
|
||||
@ -19,8 +19,6 @@ import { logoutUser, getUserData } from "./redux/actions/userActions";
|
||||
// Components
|
||||
import AuthRoute from "./util/AuthRoute";
|
||||
|
||||
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||
|
||||
// Pages
|
||||
import home from "./pages/Home";
|
||||
import signup from "./pages/Signup";
|
||||
@ -34,6 +32,7 @@ import userLine from "./Userline.js";
|
||||
import verify from "./pages/verify";
|
||||
import Search from "./pages/Search.js";
|
||||
import directMessages from "./pages/directMessages";
|
||||
import otherUser from "./pages/otherUser";
|
||||
|
||||
const theme = createMuiTheme(themeObject);
|
||||
|
||||
@ -66,11 +65,10 @@ class App extends Component {
|
||||
</div>
|
||||
<div className="app" style={{height: "700"}}>
|
||||
<Switch>
|
||||
|
||||
{/* 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="/login" component={login} />
|
||||
<AuthRoute exact path="/" component={home}/>
|
||||
<AuthRoute exact path="/" component={home} />
|
||||
|
||||
<Route exact path="/logout" component={logout} />
|
||||
<Route exact path="/delete" component={Delete} />
|
||||
@ -78,12 +76,12 @@ class App extends Component {
|
||||
<Route exact path="/home" component={home} />
|
||||
<Route exact path="/user" component={user} />
|
||||
<Route exact path="/edit" component={editProfile} />
|
||||
<Route exact path="/verify" component={verify}/>
|
||||
<Route exact path="/verify" component={verify} />
|
||||
<Route exact path="/search" component={Search} />
|
||||
<Route exact path="/dm" component={directMessages} />
|
||||
<Route exact path="/user/:userhandle" component={otherUser} />
|
||||
|
||||
<AuthRoute exact path="/" component={home} />
|
||||
|
||||
</Switch>
|
||||
</div>
|
||||
</Router>
|
||||
|
||||
@ -1,71 +1,84 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
// Material UI stuff
|
||||
import AppBar from '@material-ui/core/AppBar';
|
||||
import ToolBar from '@material-ui/core/Toolbar';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import AppBar from "@material-ui/core/AppBar";
|
||||
import ToolBar from "@material-ui/core/Toolbar";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import withStyles from "@material-ui/core/styles/withStyles";
|
||||
|
||||
// Redux stuff
|
||||
import { logoutUser } from '../../redux/actions/userActions';
|
||||
import { connect } from 'react-redux';
|
||||
import { logoutUser } from "../../redux/actions/userActions";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
const styles = {
|
||||
form: {
|
||||
textAlign: "center"
|
||||
},
|
||||
textField: {
|
||||
marginBottom: 30
|
||||
},
|
||||
pageTitle: {
|
||||
marginBottom: 40
|
||||
},
|
||||
button: {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
}
|
||||
};
|
||||
form: {
|
||||
textAlign: "center"
|
||||
},
|
||||
textField: {
|
||||
marginBottom: 30
|
||||
},
|
||||
pageTitle: {
|
||||
marginBottom: 40
|
||||
},
|
||||
button: {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
}
|
||||
};
|
||||
|
||||
export class Navbar extends Component {
|
||||
render() {
|
||||
const authenticated = this.props.user.authenticated;
|
||||
return (
|
||||
<AppBar>
|
||||
<ToolBar>
|
||||
<Button component={ Link } to='/'>
|
||||
Home
|
||||
</Button>
|
||||
{authenticated && <Button component={ Link } to='/user'>
|
||||
Profile
|
||||
</Button>}
|
||||
{!authenticated && <Button component={ Link } to='/login'>
|
||||
Login
|
||||
</Button>}
|
||||
{!authenticated && <Button component={ Link } to='/signup'>
|
||||
Sign Up
|
||||
</Button>}
|
||||
{authenticated && <Button component={ Link } to='/logout'>
|
||||
Logout
|
||||
</Button>}
|
||||
</ToolBar>
|
||||
</AppBar>
|
||||
)
|
||||
}
|
||||
render() {
|
||||
const authenticated = this.props.user.authenticated;
|
||||
return (
|
||||
<AppBar>
|
||||
<ToolBar>
|
||||
<Button component={Link} to="/">
|
||||
Home
|
||||
</Button>
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/user">
|
||||
Profile
|
||||
</Button>
|
||||
)}
|
||||
{!authenticated && (
|
||||
<Button component={Link} to="/login">
|
||||
Login
|
||||
</Button>
|
||||
)}
|
||||
{!authenticated && (
|
||||
<Button component={Link} to="/signup">
|
||||
Sign Up
|
||||
</Button>
|
||||
)}
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/search">
|
||||
Search
|
||||
</Button>
|
||||
)}
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/logout">
|
||||
Logout
|
||||
</Button>
|
||||
)}
|
||||
</ToolBar>
|
||||
</AppBar>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
user: state.user
|
||||
})
|
||||
const mapStateToProps = state => ({
|
||||
user: state.user
|
||||
});
|
||||
|
||||
Navbar.propTypes = {
|
||||
user: PropTypes.object.isRequired,
|
||||
classes: PropTypes.object.isRequired
|
||||
}
|
||||
user: PropTypes.object.isRequired,
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||
|
||||
@ -15,9 +15,14 @@ import '../App.css';
|
||||
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 {
|
||||
state = {};
|
||||
state = {
|
||||
|
||||
};
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
axios
|
||||
@ -31,9 +36,10 @@ class Home extends Component {
|
||||
.catch(err => console.log(err));
|
||||
}
|
||||
|
||||
render() {
|
||||
let authenticated = this.props.user.authenticated;
|
||||
|
||||
render() {
|
||||
let authenticated = this.props.user.authenticated;
|
||||
let username = this.props.user.credentials.handle;
|
||||
let postMarkup = this.state.posts ? (
|
||||
this.state.posts.map(post =>
|
||||
<Card>
|
||||
@ -48,11 +54,15 @@ class Home extends Component {
|
||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
||||
<br />
|
||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
|
||||
{/* <Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography> */}
|
||||
<Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like>
|
||||
<Quote microblog = {post.postId}></Quote>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
@ -96,6 +106,217 @@ class Home extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 post = {
|
||||
|
||||
userImage: "bing-url",
|
||||
}
|
||||
const headers = {
|
||||
headers: { "Content-Type": "application/json" }
|
||||
};
|
||||
axios.post(`/quoteWithoutPost/${this.props.microblog}`, post, 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 = {
|
||||
quoteBody: this.state.value,
|
||||
userImage: "bing-url",
|
||||
};
|
||||
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 = {
|
||||
num : this.props.count,
|
||||
|
||||
}
|
||||
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
like: localStorage.getItem(this.props.microBlog + this.props.name) === "false"
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleClick(){
|
||||
|
||||
this.setState({
|
||||
like: !this.state.like
|
||||
});
|
||||
localStorage.setItem(this.props.microBlog + this.props.name, this.state.like.toString())
|
||||
|
||||
if(this.state.like == false)
|
||||
{
|
||||
this.setState(() => {
|
||||
return {num: this.state.num + 1}
|
||||
});
|
||||
axios.get(`/like/${this.props.microBlog}`)
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setState(() => {
|
||||
return {num: this.state.num - 1}
|
||||
});
|
||||
axios.get(`/unlike/${this.props.microBlog}`)
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* componentDidMount() {
|
||||
axios.get(`/checkforLikePost/${this.props.microBlog}`)
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
like2: res.data
|
||||
})
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
if (this.state.like2 === this.state.like)
|
||||
{
|
||||
this.setState({
|
||||
like: false
|
||||
})
|
||||
}
|
||||
} */
|
||||
|
||||
render() {
|
||||
|
||||
const label = this.state.like ? 'Unlike' : 'Like'
|
||||
return(
|
||||
|
||||
|
||||
<div>
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {this.state.num}</Typography>
|
||||
<button onClick={this.handleClick}>{label}</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
user: state.user
|
||||
})
|
||||
@ -104,4 +325,12 @@ Home.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(Home);
|
||||
Like.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
Quote.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(Home, Like, Quote);
|
||||
@ -1,17 +1,10 @@
|
||||
import React, { Component } from "react";
|
||||
// import props
|
||||
import { TextField, Paper } from "@material-ui/core";
|
||||
import { TextField, Button } from "@material-ui/core";
|
||||
import Grid from "@material-ui/core/Grid";
|
||||
import Axios from "axios";
|
||||
import user from "./user.js";
|
||||
|
||||
import {
|
||||
BrowserRouter as Router,
|
||||
Switch,
|
||||
Route,
|
||||
Link,
|
||||
useRouteMatch
|
||||
} from "react-router-dom";
|
||||
import { BrowserRouter as Router } from "react-router-dom";
|
||||
|
||||
export class Search extends Component {
|
||||
state = {
|
||||
@ -19,20 +12,28 @@ export class Search extends Component {
|
||||
searchResult: null
|
||||
};
|
||||
|
||||
handleSearch(event) {
|
||||
Axios.get("/getUserHandles").then(res => {
|
||||
this.setState({
|
||||
searchResult: res.data
|
||||
});
|
||||
});
|
||||
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
|
||||
});
|
||||
this.handleSearch();
|
||||
console.log(this.state.searchPhase);
|
||||
}
|
||||
|
||||
handleRedirect() {
|
||||
@ -41,16 +42,16 @@ export class Search extends Component {
|
||||
|
||||
render() {
|
||||
let resultMarkup = this.state.searchResult ? (
|
||||
this.state.searchResult.map(result => (
|
||||
<Router>
|
||||
<div>
|
||||
<Link to={`/user`}>{result}</Link>
|
||||
</div>
|
||||
</Router>
|
||||
))
|
||||
<Router>
|
||||
<div>
|
||||
<a href={`/user/${this.state.searchResult}`}>
|
||||
{this.state.searchResult}
|
||||
</a>
|
||||
</div>
|
||||
</Router>
|
||||
) : (
|
||||
// console.log(this.state.searchResult)
|
||||
<p> searching... </p>
|
||||
<p> No result </p>
|
||||
);
|
||||
|
||||
return (
|
||||
@ -65,6 +66,11 @@ export class Search extends Component {
|
||||
onChange={event => this.handleInput(event)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<Button color="primary" onClick={this.handleSearch}>
|
||||
Search
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid>{resultMarkup}</Grid>
|
||||
</Grid>
|
||||
);
|
||||
|
||||
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,47 +1,101 @@
|
||||
/* 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 React, { Component } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { connect } from "react-redux";
|
||||
import axios from "axios";
|
||||
//import '../App.css';
|
||||
// Material-UI
|
||||
import withStyles from "@material-ui/core/styles/withStyles";
|
||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
||||
import { Link } from 'react-router-dom';
|
||||
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 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';
|
||||
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
|
||||
import '../App.css';
|
||||
import noImage from '../images/no-img.png';
|
||||
import Writing_Microblogs from '../Writing_Microblogs';
|
||||
import "../App.css";
|
||||
import noImage from "../images/no-img.png";
|
||||
import Writing_Microblogs from "../Writing_Microblogs";
|
||||
|
||||
const MyChip = styled(Chip)({
|
||||
margin: 2,
|
||||
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 {
|
||||
state = {
|
||||
profile: null,
|
||||
imageUrl: null,
|
||||
topics: null,
|
||||
newTopic: null
|
||||
};
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
profile: null,
|
||||
imageUrl: null,
|
||||
topics: null,
|
||||
newTopic: null
|
||||
};
|
||||
}
|
||||
|
||||
handleDelete = topic => {
|
||||
console.log(topic);
|
||||
axios
|
||||
.delete(`/deleteTopic/${topic.id}`)
|
||||
.then(function() {
|
||||
location.reload();
|
||||
.post(`/deleteTopic`, {
|
||||
unfollow: topic
|
||||
})
|
||||
.then(() => {
|
||||
let tempTopics = this.state.topics;
|
||||
tempTopics.forEach((oldTopic, index) => {
|
||||
if (oldTopic === topic) {
|
||||
tempTopics.splice(index, 1);
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
topics: tempTopics
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
@ -51,10 +105,15 @@ class user extends Component {
|
||||
handleAddCircle = () => {
|
||||
axios
|
||||
.post("/putTopic", {
|
||||
topic: this.state.newTopic
|
||||
following: this.state.newTopic
|
||||
})
|
||||
.then(function() {
|
||||
location.reload();
|
||||
.then(() => {
|
||||
let tempTopics = this.state.topics;
|
||||
tempTopics.push(this.state.newTopic);
|
||||
this.setState({
|
||||
topics: tempTopics,
|
||||
newTopic: ""
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
@ -74,16 +133,10 @@ class user extends Component {
|
||||
this.setState({
|
||||
profile: res.data.credentials.handle,
|
||||
imageUrl: res.data.credentials.imageUrl,
|
||||
verified: res.data.credentials.verified ? res.data.credentials.verified : false
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
axios
|
||||
.get("/getAllTopics")
|
||||
.then(res => {
|
||||
this.setState({
|
||||
topics: res.data
|
||||
verified: res.data.credentials.verified
|
||||
? res.data.credentials.verified
|
||||
: false,
|
||||
topics: res.data.credentials.followedTopics
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
@ -91,7 +144,7 @@ class user extends Component {
|
||||
axios
|
||||
.get("/getallPostsforUser")
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
// console.log(res.data);
|
||||
this.setState({
|
||||
posts: res.data
|
||||
})
|
||||
@ -100,20 +153,28 @@ class user extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
let authenticated = this.props.user.authenticated;
|
||||
let classes = this.props;
|
||||
|
||||
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>);
|
||||
<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 ? (
|
||||
this.state.topics.map(
|
||||
topic => (
|
||||
<MyChip
|
||||
label={{ topic }.topic.topic}
|
||||
key={{ topic }.topic.id}
|
||||
label={topic}
|
||||
key={topic.id}
|
||||
onDelete={key => this.handleDelete(topic)}
|
||||
/>
|
||||
) // console.log({ topic }.topic.id)
|
||||
@ -122,103 +183,135 @@ class user extends Component {
|
||||
<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 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>
|
||||
this.state.posts.map(post => (
|
||||
<Card className={classes.card}>
|
||||
<CardContent>
|
||||
<Typography>
|
||||
{
|
||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
}
|
||||
{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}
|
||||
</Typography>
|
||||
|
||||
|
||||
<br />
|
||||
<Typography variant="body1">
|
||||
<b>{post.microBlogTitle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body2">{post.quoteBody}</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}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
) : (<p>My Posts</p>);
|
||||
))
|
||||
) : (
|
||||
<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 (
|
||||
<Grid container spacing={24}>
|
||||
<Grid item sm={4} xs={8}>
|
||||
{imageMarkup}
|
||||
{profileMarkup}
|
||||
{topicsMarkup}
|
||||
<TextField
|
||||
id="newTopic"
|
||||
label="new topic"
|
||||
defaultValue=""
|
||||
margin="normal"
|
||||
variant="outlined"
|
||||
value={this.state.newTopic}
|
||||
onChange={(event) => this.handleChange(event)}
|
||||
/>
|
||||
<AddCircle
|
||||
color="primary"
|
||||
clickable
|
||||
onClick={this.handleAddCircle}
|
||||
/>
|
||||
<br />
|
||||
<Grid container direction="column">
|
||||
<Grid item>
|
||||
{
|
||||
authenticated &&
|
||||
<Button
|
||||
style={{width:150, marginBottom: 10, marginTop: 5}}
|
||||
component={ Link }
|
||||
to='/edit'
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
>
|
||||
Edit Profile
|
||||
</Button>}
|
||||
<div>
|
||||
{/* <Paper className={classes.paper}> */}
|
||||
<Grid container direction="column">
|
||||
<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 item>
|
||||
{
|
||||
authenticated &&
|
||||
this.state.profile === 'Admin' &&
|
||||
<Button
|
||||
style={{width:150}}
|
||||
component={ Link }
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
|
||||
to='/verify'
|
||||
>
|
||||
Verify Users
|
||||
</Button>}
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Grid container>
|
||||
<Grid item sm />
|
||||
<Grid item>{postMarkup}</Grid>
|
||||
<Grid item sm />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item sm={4} xs={8}>
|
||||
{postMarkup}
|
||||
</Grid>
|
||||
<Grid item sm={4} xs={8}>
|
||||
<Writing_Microblogs />
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
const mapStateToProps = state => ({
|
||||
user: state.user
|
||||
})
|
||||
});
|
||||
|
||||
user.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(user);
|
||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user