Compare commits
56 Commits
impDarkThe
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74cbf124b3 | ||
|
|
d1f42aa5cd | ||
|
|
f118ed76d1 | ||
|
|
b9cbd610a9 | ||
| daabbf80f6 | |||
| f9acefaafb | |||
| 948eff32c2 | |||
| 6de219505a | |||
| 7132a2ab45 | |||
| 5474543af4 | |||
| 6f77d03e2d | |||
| da6e7436ea | |||
| e7afac9a19 | |||
|
|
9449d3544b | ||
| 4f2e07756d | |||
|
|
f2cf7542a8 | ||
| ff7677bfb3 | |||
| 978af53a74 | |||
| a0a522f1d2 | |||
|
|
988c807af2 | ||
|
|
01b449d01d | ||
| f30a9ae27c | |||
| a459e6581e | |||
|
|
b769ab930a | ||
|
|
116f97bf64 | ||
|
|
a4efc15d58 | ||
|
|
39613584e7 | ||
| a1f9a4bef3 | |||
| c85eeccd4c | |||
|
|
bb50e0fa5d | ||
|
|
f111553827 | ||
|
|
5e935f3508 | ||
|
|
80a2e1894c | ||
| 8acd29e842 | |||
| b402c96864 | |||
|
|
76792148cd | ||
|
|
a92681451f | ||
|
|
e3522876d7 | ||
|
|
c7859e0f0a | ||
|
|
aad9dc0273 | ||
|
|
30df98343e | ||
| 719294f0ed | |||
| fc9994d42e | |||
|
|
de72bd9223 | ||
| b85bee7cba | |||
| 76330fd234 | |||
| b007666317 | |||
| a0d2532c22 | |||
| 739b1cc92a | |||
| 57087a5ea3 | |||
|
|
3424a7d34f | ||
| 1aff5ba99b | |||
|
|
2bcf6bfcb3 | ||
|
|
bae2947003 | ||
|
|
96423cee8a | ||
|
|
6924af58a7 |
14
README.md
@@ -1,2 +1,14 @@
|
||||
# CS307-Team24
|
||||
CS307 Team 24 Twistter website.
|
||||
CS307 Team 24 Twistter website
|
||||
|
||||
### Images
|
||||
<p>
|
||||
<img alt="00.png" src="./screenshots/00.png" width="1000">
|
||||
<img alt="01.png" src="./screenshots/01.png" width="1000">
|
||||
<img alt="02.png" src="./screenshots/02.png" width="1000">
|
||||
<img alt="03.png" src="./screenshots/03.png" width="1000">
|
||||
<img alt="04.png" src="./screenshots/04.png" width="1000">
|
||||
<img alt="05.png" src="./screenshots/05.png" width="1000">
|
||||
<img alt="06.png" src="./screenshots/06.png" width="1000">
|
||||
<img alt="07.png" src="./screenshots/07.png" width="1000">
|
||||
</p>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/always-return */
|
||||
const admin = require("firebase-admin");
|
||||
const { db } = require("../util/admin");
|
||||
const { admin, db } = require("../util/admin");
|
||||
|
||||
|
||||
exports.putPost = (req, res) => {
|
||||
const newPost = {
|
||||
@@ -33,6 +33,18 @@ exports.putPost = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.deletePost = (req, res) => {
|
||||
let posts = db.collection("posts")
|
||||
.where("userHandle", "==", req.user.handle)
|
||||
.get()
|
||||
.then((query) => {
|
||||
query.forEach((snap) => {
|
||||
snap.ref.delete();
|
||||
});
|
||||
return;
|
||||
})
|
||||
};
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
var post_query = admin
|
||||
.firestore()
|
||||
@@ -46,6 +58,106 @@ exports.getallPostsforUser = (req, res) => {
|
||||
myPosts.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||
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({message: "Failed to retrieve user's posts from database.", error: err});
|
||||
});
|
||||
};
|
||||
|
||||
exports.hidePost = (req, res) => {
|
||||
/* db
|
||||
.collection("posts")
|
||||
.doc(${req.params.postId}) */
|
||||
const postId = req.body.postId;
|
||||
db.doc(`/posts/${postId}`)
|
||||
.update({
|
||||
hidden: true
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(200).json({message: "ok"});
|
||||
})
|
||||
.catch((error) => {
|
||||
return res.status(500).json(error);
|
||||
})
|
||||
};
|
||||
|
||||
exports.getallPosts = (req, res) => {
|
||||
let posts = [];
|
||||
let users = {};
|
||||
|
||||
// Get all the posts
|
||||
var postsPromise = new Promise((resolve, reject) => {
|
||||
db.collection("posts")
|
||||
.get()
|
||||
.then(allPosts => {
|
||||
allPosts.forEach(post => {
|
||||
posts.push(post.data());
|
||||
});
|
||||
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
// Get all users
|
||||
var usersPromise = new Promise((resolve, reject) => {
|
||||
db.collection("users")
|
||||
.get()
|
||||
.then(allUsers => {
|
||||
allUsers.forEach(user => {
|
||||
users[user.data().handle] = user.data();
|
||||
});
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
// Wait for the two promises
|
||||
Promise.all([postsPromise, usersPromise])
|
||||
.then(() => {
|
||||
let newPosts = [];
|
||||
// Add the image url of the person who made the post to all of the post objects
|
||||
posts.forEach(post => {
|
||||
post.profileImage = users[post.userHandle].imageUrl
|
||||
? users[post.userHandle].imageUrl
|
||||
: null;
|
||||
newPosts.push(post);
|
||||
});
|
||||
return res.status(200).json(newPosts);
|
||||
})
|
||||
.catch(error => {
|
||||
return res.status(500).json({ error });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getAlert = (req, res) => {
|
||||
var post_query = admin
|
||||
.firestore()
|
||||
.collection("posts")
|
||||
.where("microBlogTitle", "==", "Alert");
|
||||
|
||||
post_query
|
||||
.get()
|
||||
.then(function(myPosts) {
|
||||
let posts = [];
|
||||
myPosts.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
@@ -60,59 +172,16 @@ exports.getallPostsforUser = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.getallPosts = (req, res) => {
|
||||
let posts = [];
|
||||
let users = {};
|
||||
|
||||
// Get all the posts
|
||||
var postsPromise = new Promise((resolve, reject) => {
|
||||
db.collection("posts").get()
|
||||
.then((allPosts) => {
|
||||
allPosts.forEach((post) => {
|
||||
posts.push(post.data());
|
||||
});
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
})
|
||||
});
|
||||
|
||||
// Get all users
|
||||
var usersPromise = new Promise((resolve, reject) => {
|
||||
db.collection("users").get()
|
||||
.then((allUsers) => {
|
||||
allUsers.forEach((user) => {
|
||||
users[user.data().handle] = user.data();
|
||||
})
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
})
|
||||
});
|
||||
|
||||
// Wait for the two promises
|
||||
Promise.all([postsPromise, usersPromise])
|
||||
.then(() => {
|
||||
let newPosts = []
|
||||
// Add the image url of the person who made the post to all of the post objects
|
||||
posts.forEach((post) => {
|
||||
post.profileImage = users[post.userHandle].imageUrl ? users[post.userHandle].imageUrl : null;
|
||||
newPosts.push(post);
|
||||
});
|
||||
return res.status(200).json(newPosts);
|
||||
})
|
||||
.catch((error) => {
|
||||
return res.status(500).json({error});
|
||||
})
|
||||
};
|
||||
|
||||
exports.getOtherUsersPosts = (req, res) => {
|
||||
var post_query = admin
|
||||
.firestore()
|
||||
.collection("posts")
|
||||
.where("userHandle", "==", req.body.handle);
|
||||
|
||||
// post_query += admin
|
||||
// .firestore()
|
||||
// .collection("posts")
|
||||
// .where("microBlogTitle", "==", "Alert").where("userHandle", "==", "Admin");
|
||||
|
||||
post_query
|
||||
.get()
|
||||
@@ -121,6 +190,7 @@ exports.getOtherUsersPosts = (req, res) => {
|
||||
myPosts.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
@@ -136,23 +206,25 @@ exports.getOtherUsersPosts = (req, res) => {
|
||||
};
|
||||
|
||||
exports.quoteWithPost = (req, res) => {
|
||||
let quoteData;
|
||||
const quoteDoc = admin.firestore().collection('quote').
|
||||
where('userHandle', '==', req.user.handle).
|
||||
where('quoteId', '==', req.params.postId).limit(1);
|
||||
let quoteData;
|
||||
const quoteDoc = admin
|
||||
.firestore()
|
||||
.collection("quote")
|
||||
.where("userHandle", "==", req.user.handle)
|
||||
.where("quoteId", "==", req.params.postId)
|
||||
.limit(1);
|
||||
|
||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||
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'});
|
||||
}
|
||||
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) {
|
||||
@@ -200,23 +272,25 @@ exports.quoteWithPost = (req, res) => {
|
||||
};
|
||||
|
||||
exports.quoteWithoutPost = (req, res) => {
|
||||
let quoteData;
|
||||
const quoteDoc = admin.firestore().collection('quote').
|
||||
where('userHandle', '==', req.user.handle).
|
||||
where('quoteId', '==', req.params.postId).limit(1);
|
||||
let quoteData;
|
||||
const quoteDoc = admin
|
||||
.firestore()
|
||||
.collection("quote")
|
||||
.where("userHandle", "==", req.user.handle)
|
||||
.where("quoteId", "==", req.params.postId)
|
||||
.limit(1);
|
||||
|
||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||
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'});
|
||||
}
|
||||
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) {
|
||||
@@ -258,7 +332,7 @@ exports.quoteWithoutPost = (req, res) => {
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
// return res.status(500).json({ error: "Something is wrong" });
|
||||
// return res.status(500).json({ error: "Something is wrong" });
|
||||
return res.status(500).json({ error: err });
|
||||
});
|
||||
};
|
||||
@@ -272,202 +346,198 @@ exports.checkforLikePost = (req, res) => {
|
||||
.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);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
likedPostDoc
|
||||
.get()
|
||||
.then(data => {
|
||||
if (data.empty) {
|
||||
result = false;
|
||||
return res.status(200).json(result);
|
||||
} else {
|
||||
result = true;
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
return res.status(500).json({error: err});
|
||||
})
|
||||
return res.status(500).json({ error: err });
|
||||
});
|
||||
};
|
||||
|
||||
exports.likePost = (req, res) => {
|
||||
const postId = req.params.postId;
|
||||
let likedPostDoc;
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then(userDoc => {
|
||||
let likes = userDoc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
|
||||
const postId = req.params.postId;
|
||||
let likedPostDoc;
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then((userDoc) => {
|
||||
let likes = userDoc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
if (likes.includes(postId)) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "This user has already liked this post" });
|
||||
}
|
||||
|
||||
if (likes.includes(postId)) {
|
||||
return res.status(400).json({error: "This user has already liked this post"});
|
||||
}
|
||||
likes.push(postId);
|
||||
|
||||
likes.push(postId);
|
||||
return userDoc.ref.update({ likes });
|
||||
})
|
||||
.then(() => {
|
||||
return db.doc(`/posts/${postId}`).get();
|
||||
})
|
||||
.then(postDoc => {
|
||||
let postData = postDoc.data();
|
||||
postData.likeCount++;
|
||||
likedPostDoc = postData;
|
||||
return postDoc.ref.update({ likeCount: postData.likeCount });
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(201).json(likedPostDoc);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
return res.status(500).json({ error: err });
|
||||
});
|
||||
|
||||
return userDoc.ref.update({likes})
|
||||
})
|
||||
.then(() => {
|
||||
return db.doc(`/posts/${postId}`).get()
|
||||
|
||||
})
|
||||
.then((postDoc) => {
|
||||
let postData = postDoc.data();
|
||||
postData.likeCount++;
|
||||
likedPostDoc = postData;
|
||||
return postDoc.ref.update({likeCount : postData.likeCount})
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(201).json(likedPostDoc);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
return res.status(500).json({error: err});
|
||||
})
|
||||
// let postData;
|
||||
// const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||
// .where('postId', '==', req.params.postId).limit(1);
|
||||
|
||||
// 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}`);
|
||||
|
||||
// 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'});
|
||||
// })
|
||||
|
||||
}
|
||||
// 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) => {
|
||||
const postId = req.params.postId;
|
||||
let likedPostDoc;
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then(userDoc => {
|
||||
let likes = userDoc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
|
||||
const postId = req.params.postId;
|
||||
let likedPostDoc;
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then((userDoc) => {
|
||||
let likes = userDoc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
if (!likes.includes(postId)) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "This user hasn't liked this post yet" });
|
||||
}
|
||||
|
||||
if (!likes.includes(postId)) {
|
||||
return res.status(400).json({error: "This user hasn't liked this post yet"});
|
||||
}
|
||||
let i;
|
||||
for (i = 0; i < likes.length; i++) {
|
||||
if (likes[i] === postId) {
|
||||
likes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
let i;
|
||||
for (i = 0; i < likes.length; i++) {
|
||||
if (likes[i] === postId) {
|
||||
likes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
return userDoc.ref.update({ likes });
|
||||
})
|
||||
.then(() => {
|
||||
return db.doc(`/posts/${postId}`).get();
|
||||
})
|
||||
.then(postDoc => {
|
||||
let postData = postDoc.data();
|
||||
postData.likeCount--;
|
||||
likedPostDoc = postData;
|
||||
return postDoc.ref.update({ likeCount: postData.likeCount });
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(201).json(likedPostDoc);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
return res.status(500).json({ error: err });
|
||||
});
|
||||
|
||||
return userDoc.ref.update({likes})
|
||||
})
|
||||
.then(() => {
|
||||
return db.doc(`/posts/${postId}`).get()
|
||||
|
||||
})
|
||||
.then((postDoc) => {
|
||||
let postData = postDoc.data();
|
||||
postData.likeCount--;
|
||||
likedPostDoc = postData;
|
||||
return postDoc.ref.update({likeCount : postData.likeCount})
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(201).json(likedPostDoc);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
return res.status(500).json({error: err});
|
||||
})
|
||||
// let postData;
|
||||
// const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||
// .where('postId', '==', req.params.postId).limit(1);
|
||||
|
||||
// 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}`);
|
||||
|
||||
// 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'});
|
||||
// })
|
||||
|
||||
}
|
||||
// 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.getLikes = (req, res) => {
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
let likes = doc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
return res.status(200).json({likes});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
return res.status(500).json({error: err});
|
||||
})
|
||||
}
|
||||
db.doc(`/users/${req.userData.handle}`)
|
||||
.get()
|
||||
.then(doc => {
|
||||
let likes = doc.data().likes;
|
||||
if (likes === undefined || likes === null) {
|
||||
likes = [];
|
||||
}
|
||||
return res.status(200).json({ likes });
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
return res.status(500).json({ error: err });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getFilteredPosts = (req, res) => {
|
||||
|
||||
admin
|
||||
.firestore()
|
||||
.collection("posts")
|
||||
.where("userHandle", "==", "new user")
|
||||
.where("microBlogTopics", "==");
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,41 @@ exports.putTopic = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.putNewTopic = (req, res) => {
|
||||
let new_following = [];
|
||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||
userRef
|
||||
.get()
|
||||
.then(doc => {
|
||||
let topics = [];
|
||||
new_following = doc.data().following;
|
||||
// new_following.push(req.body.following);
|
||||
new_following.forEach(follow => {
|
||||
if (follow.handle === req.body.handle) {
|
||||
// topics = follow.topics;
|
||||
follow.topics.push(req.body.topic);
|
||||
}
|
||||
});
|
||||
// return res.status(201).json({ new_following });
|
||||
|
||||
// add stuff
|
||||
userRef
|
||||
.set({ following: new_following }, { merge: true })
|
||||
.then(doc => {
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: `Following ${req.body.topic}` });
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
return res.status(200).json({ message: "OK" });
|
||||
})
|
||||
.catch(err => {
|
||||
return res.status(500).json({ err });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getAllTopics = (req, res) => {
|
||||
admin
|
||||
.firestore()
|
||||
|
||||
@@ -100,18 +100,33 @@ app.post("/addSubscription", fbAuth, addSubscription);
|
||||
// remove one subscription
|
||||
app.post("/removeSub", fbAuth, removeSub);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/post.js *
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, getLikes, quoteWithPost, quoteWithoutPost, checkforLikePost, getOtherUsersPosts} = require("./handlers/post");
|
||||
|
||||
const {
|
||||
getallPostsforUser,
|
||||
getallPosts,
|
||||
putPost,
|
||||
hidePost,
|
||||
likePost,
|
||||
unlikePost,
|
||||
getLikes,
|
||||
quoteWithPost,
|
||||
quoteWithoutPost,
|
||||
checkforLikePost,
|
||||
getOtherUsersPosts,
|
||||
getAlert
|
||||
} = require("./handlers/post");
|
||||
|
||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||
|
||||
app.get("/getallPosts", getallPosts);
|
||||
|
||||
//Hides Post
|
||||
app.post("/hidePost", fbAuth, hidePost);
|
||||
|
||||
// Adds one post to the database
|
||||
app.post("/putPost", fbAuth, putPost);
|
||||
|
||||
@@ -125,6 +140,8 @@ app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
||||
|
||||
app.post("/getOtherUsersPosts", fbAuth, getOtherUsersPosts);
|
||||
|
||||
app.get("/getAlert", fbAuth, getAlert);
|
||||
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/topic.js *
|
||||
*------------------------------------------------------------------*/
|
||||
@@ -132,7 +149,8 @@ const {
|
||||
putTopic,
|
||||
getAllTopics,
|
||||
deleteTopic,
|
||||
getUserTopics
|
||||
getUserTopics,
|
||||
putNewTopic
|
||||
} = require("./handlers/topic");
|
||||
|
||||
// add topic to database
|
||||
@@ -147,4 +165,6 @@ app.post("/deleteTopic", fbAuth, deleteTopic);
|
||||
// get topic for this user
|
||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
||||
|
||||
app.post("/putNewTopic", fbAuth, putNewTopic);
|
||||
|
||||
exports.api = functions.https.onRequest(app);
|
||||
|
||||
41
functions/package-lock.json
generated
@@ -673,6 +673,14 @@
|
||||
"readable-stream": "~1.0.32"
|
||||
}
|
||||
},
|
||||
"busboy": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
|
||||
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
|
||||
"requires": {
|
||||
"dicer": "0.3.0"
|
||||
}
|
||||
},
|
||||
"bytebuffer": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz",
|
||||
@@ -1910,10 +1918,6 @@
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"bundled": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.3.5",
|
||||
"bundled": true,
|
||||
@@ -1929,19 +1933,6 @@
|
||||
"minipass": "^2.2.1"
|
||||
}
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"bundled": true
|
||||
@@ -2735,18 +2726,16 @@
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
|
||||
"dev": true
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||
"dev": true,
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
"minimist": "^1.2.6"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
|
||||
BIN
screenshots/00.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
screenshots/01.png
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
screenshots/02.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
screenshots/03.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
screenshots/04.png
Normal file
|
After Width: | Height: | Size: 184 KiB |
BIN
screenshots/05.png
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
screenshots/06.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
screenshots/07.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
1177
twistter-frontend/package-lock.json
generated
@@ -8,6 +8,7 @@ import TextField from '@material-ui/core/TextField';
|
||||
// import Typography from '@material-ui/core/Typography';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import withStyles from "@material-ui/styles/withStyles";
|
||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||
|
||||
const styles = {
|
||||
container: {
|
||||
@@ -21,6 +22,13 @@ const styles = {
|
||||
},
|
||||
textField: {
|
||||
marginBottom: 15
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
},
|
||||
button: {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +39,8 @@ class Writing_Microblogs extends Component {
|
||||
value: "",
|
||||
title: "",
|
||||
topics: "",
|
||||
characterCount: 250
|
||||
characterCount: 250,
|
||||
loading: false
|
||||
};
|
||||
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
@@ -56,11 +65,15 @@ class Writing_Microblogs extends Component {
|
||||
microBlogTitle: this.state.title,
|
||||
microBlogTopics: this.state.topics.split(", ")
|
||||
};
|
||||
|
||||
this.setState({
|
||||
loading: true
|
||||
})
|
||||
const headers = {
|
||||
headers: { "Content-Type": "application/json" }
|
||||
};
|
||||
|
||||
axios
|
||||
let postPromise = axios
|
||||
.post("/putPost", postData, headers) // TODO: add topics
|
||||
.then(res => {
|
||||
// alert("Post was shared successfully!");
|
||||
@@ -71,20 +84,35 @@ class Writing_Microblogs extends Component {
|
||||
console.error(err);
|
||||
});
|
||||
console.log(postData.microBlogTopics);
|
||||
postData.microBlogTopics.forEach(topic => {
|
||||
axios
|
||||
.post("/putTopic", {
|
||||
following: topic
|
||||
})
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
// let topicPromises = [];
|
||||
// postData.microBlogTopics.forEach(topic => {
|
||||
// topicPromises.push(axios
|
||||
// .post("/putTopic", {
|
||||
// following: topic
|
||||
// })
|
||||
// .then(res => {
|
||||
// console.log(res.data);
|
||||
// })
|
||||
// .catch(err => {
|
||||
// console.error(err);
|
||||
// })
|
||||
// )
|
||||
// });
|
||||
event.preventDefault();
|
||||
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
||||
// topicPromises.push(postPromise);
|
||||
Promise.all([postPromise])
|
||||
.then(() => {
|
||||
this.setState({
|
||||
value: "",
|
||||
title: "",
|
||||
characterCount: 250,
|
||||
topics: "",
|
||||
loading: false
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
})
|
||||
}
|
||||
|
||||
handleChangeforPost(event) {
|
||||
@@ -149,12 +177,14 @@ class Writing_Microblogs extends Component {
|
||||
autoComplete='off'
|
||||
/>
|
||||
<Button
|
||||
className={classes.button}
|
||||
onClick={this.handleSubmit}
|
||||
// disabled={loading}
|
||||
disabled={this.state.loading}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
>
|
||||
Share Post
|
||||
{this.state.loading && <CircularProgress size={30} className={classes.progress} />}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -6,78 +6,134 @@ import axios from "axios";
|
||||
|
||||
// Material UI and React Router
|
||||
|
||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import Grid from "@material-ui/core/Grid";
|
||||
import Card from "@material-ui/core/Card";
|
||||
import CardContent from "@material-ui/core/CardContent";
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
import TextField from "@material-ui/core/TextField";
|
||||
|
||||
import Typography from "@material-ui/core/Typography";
|
||||
import withStyles from '@material-ui/styles/withStyles';
|
||||
import withStyles from "@material-ui/styles/withStyles";
|
||||
|
||||
// component
|
||||
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';
|
||||
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";
|
||||
|
||||
// Redux
|
||||
import { likePost, unlikePost, getLikes } from '../redux/actions/userActions';
|
||||
|
||||
import { likePost, unlikePost, getLikes } from "../redux/actions/userActions";
|
||||
|
||||
const styles = {
|
||||
card: {
|
||||
marginBottom: 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Home extends Component {
|
||||
state = {
|
||||
likes: []
|
||||
likes: [],
|
||||
loading: false,
|
||||
following: null,
|
||||
topics: null
|
||||
};
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
axios
|
||||
.get("/getallPosts")
|
||||
this.setState({ loading: true });
|
||||
let userPromise = axios
|
||||
.get("/user")
|
||||
.then(res => {
|
||||
// console.log(res.data);
|
||||
console.log(res.data.credentials.following);
|
||||
let list = [];
|
||||
res.data.credentials.following.forEach(element => {
|
||||
list.push(element.handle);
|
||||
});
|
||||
this.setState({
|
||||
posts: res.data
|
||||
following: list,
|
||||
topics: res.data.credentials.followedTopics
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
let allPosts;
|
||||
let postPromise = axios
|
||||
.get("/getallPosts")
|
||||
.then(res => {
|
||||
// console.log(res.data);
|
||||
// this.setState({
|
||||
// posts: res.data
|
||||
// });
|
||||
allPosts = res.data;
|
||||
// console.log(allPosts)
|
||||
return axios.get("/getAlert")
|
||||
})
|
||||
.then((res) => {
|
||||
// console.log(res.data)
|
||||
// res.data.forEach((adminAlert) => {
|
||||
// allPosts.push(adminAlert);
|
||||
// })
|
||||
this.setState({
|
||||
posts: allPosts
|
||||
});
|
||||
})
|
||||
|
||||
.catch(err => console.log(err));
|
||||
|
||||
Promise.all([userPromise, postPromise])
|
||||
.then(() => {
|
||||
this.setState({
|
||||
loading: false
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
this.props.getLikes();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState({
|
||||
likes: nextProps.user.likes
|
||||
});
|
||||
}
|
||||
|
||||
flagPost = (event) => {
|
||||
// Flags a post
|
||||
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
|
||||
console.log(postId);
|
||||
axios.post(`/hidePost`, {postId})
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
// event.preventDefault();
|
||||
}
|
||||
|
||||
handleClickLikeButton = (event) => {
|
||||
// Need the ternary if statement because the user can click on the text or body of the
|
||||
// Button and they are two different html elements
|
||||
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
|
||||
console.log(postId)
|
||||
let postId = event.target.dataset.key
|
||||
? event.target.dataset.key
|
||||
: event.target.parentNode.dataset.key;
|
||||
console.log(postId);
|
||||
|
||||
let doc = document.getElementById(postId);
|
||||
// console.log(postId);
|
||||
if (this.state.likes.includes(postId)) {
|
||||
this.props.unlikePost(postId, this.state.likes)
|
||||
this.props.unlikePost(postId, this.state.likes);
|
||||
doc.dataset.likes--;
|
||||
} else {
|
||||
this.props.likePost(postId, this.state.likes)
|
||||
} else {
|
||||
this.props.likePost(postId, this.state.likes);
|
||||
doc.dataset.likes++;
|
||||
}
|
||||
|
||||
doc.innerHTML = "Likes " + doc.dataset.likes;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
formatDate(dateString) {
|
||||
let newDate = new Date(Date.parse(dateString));
|
||||
@@ -85,96 +141,133 @@ class Home extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const { UI:{ loading } } = this.props;
|
||||
const {
|
||||
UI: { loading }
|
||||
} = this.props;
|
||||
let authenticated = this.props.user.authenticated;
|
||||
let {classes} = this.props;
|
||||
let { classes } = this.props;
|
||||
let username = this.props.user.credentials.handle;
|
||||
console.log(username);
|
||||
var hiddenBool = true;
|
||||
if (username === "Admin") {
|
||||
hiddenBool = false;
|
||||
}
|
||||
|
||||
let postMarkup = this.state.posts ? (
|
||||
this.state.posts.map(post =>
|
||||
<Card className={classes.card} key={post.postId}>
|
||||
<CardContent>
|
||||
<Typography>
|
||||
{/* {
|
||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
} */}
|
||||
{
|
||||
post.profileImage ? (<img src={post.profileImage} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
}
|
||||
</Typography>
|
||||
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(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 id={post.postId} data-likes={post.likeCount} variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
|
||||
<Button
|
||||
onClick={this.handleClickLikeButton}
|
||||
data-key={post.postId}
|
||||
disabled={loading}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
>{
|
||||
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
|
||||
}</Button>
|
||||
<Quote microblog = {post.postId}></Quote>
|
||||
console.log(hiddenBool);
|
||||
let postMarkup = this.state.posts ? ( this.state.following === undefined || this.state.following === null ? <Typography>You aren't following anybody right now</Typography> :
|
||||
this.state.posts.map(post => !post.hidden && this.state.following && (this.state.following.includes(post.userHandle) || post.userHandle === "Admin") ? (
|
||||
<Card className={classes.card} key={post.postId}>
|
||||
<CardContent>
|
||||
<Typography>
|
||||
{/* {
|
||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
} */}
|
||||
{
|
||||
post.profileImage ? (<img src={post.profileImage} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
}
|
||||
</Typography>
|
||||
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(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.join(", ")}</Typography>
|
||||
<br />
|
||||
{!hiddenBool &&
|
||||
<Button
|
||||
onClick={this.flagPost}
|
||||
data-key={post.postId}
|
||||
variant = "contained"
|
||||
color = "primary"
|
||||
>
|
||||
Hide Post
|
||||
</Button>
|
||||
}
|
||||
|
||||
<Typography id={post.postId} data-likes={post.likeCount} variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
|
||||
<Button
|
||||
onClick={this.handleClickLikeButton}
|
||||
data-key={post.postId}
|
||||
disabled={loading}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
>{
|
||||
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
|
||||
}</Button>
|
||||
<Quote microblog = {post.postId}></Quote>
|
||||
|
||||
{/* <button>Quote</button> */}
|
||||
{/* <button>Quote</button> */}
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
{/* <Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography> */}
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<p></p>
|
||||
)
|
||||
)
|
||||
) : (
|
||||
<p>Loading post...</p>
|
||||
);
|
||||
|
||||
return (
|
||||
authenticated ? (
|
||||
<Grid container>
|
||||
<Grid item sm={4} xs={8}>
|
||||
<Writing_Microblogs />
|
||||
return authenticated ? (
|
||||
this.state.loading ? (
|
||||
<CircularProgress
|
||||
size={60}
|
||||
style={{ marginTop: "300px" }}
|
||||
></CircularProgress>
|
||||
) : (
|
||||
<Grid container>
|
||||
<Grid item sm={4} xs={8}>
|
||||
<Writing_Microblogs />
|
||||
</Grid>
|
||||
<Grid item sm={4} xs={8}>
|
||||
{postMarkup}
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item sm={4} xs={8}>
|
||||
{postMarkup}
|
||||
</Grid>
|
||||
</Grid>
|
||||
) : loading ?
|
||||
(<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>)
|
||||
:
|
||||
(
|
||||
<div>
|
||||
<div>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br/><br/>
|
||||
<b>Welcome to Twistter!</b>
|
||||
<br/><br/>
|
||||
<b>See the most interesting topics people are following right now.</b>
|
||||
</div>
|
||||
)
|
||||
) : loading ? (
|
||||
<CircularProgress
|
||||
size={60}
|
||||
style={{ marginTop: "300px" }}
|
||||
></CircularProgress>
|
||||
) : (
|
||||
<div>
|
||||
<div>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br />
|
||||
<br />
|
||||
<b>Welcome to Twistter!</b>
|
||||
<br />
|
||||
<br />
|
||||
<b>See the most interesting topics people are following right now.</b>
|
||||
</div>
|
||||
|
||||
<br/><br/><br/><br/>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<div>
|
||||
<b>Join today or sign in if you already have an account.</b>
|
||||
<br/><br/>
|
||||
<form action="./signup">
|
||||
<button className="authButtons signup">Sign up</button>
|
||||
</form>
|
||||
<br/>
|
||||
<form action="./login">
|
||||
<button className="authButtons login">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
));
|
||||
<div>
|
||||
<b>Join today or sign in if you already have an account.</b>
|
||||
<br />
|
||||
<br />
|
||||
<form action="./signup">
|
||||
<button className="authButtons signup">Sign up</button>
|
||||
</form>
|
||||
<br />
|
||||
<form action="./login">
|
||||
<button className="authButtons login">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,38 +278,36 @@ class Quote extends Component {
|
||||
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);
|
||||
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",
|
||||
}
|
||||
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);
|
||||
});
|
||||
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, characterCount: 250, value: "" });
|
||||
}
|
||||
@@ -234,20 +325,19 @@ class Quote extends Component {
|
||||
handleSubmit(event) {
|
||||
const quotedPost = {
|
||||
quoteBody: this.state.value,
|
||||
userImage: "bing-url",
|
||||
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);
|
||||
});
|
||||
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: "" });
|
||||
}
|
||||
@@ -255,14 +345,29 @@ class Quote extends Component {
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Button variant="outlined" color="primary" 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"}}}
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
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 style={{ width: "350px"}}>
|
||||
{/* <textarea
|
||||
<form style={{ width: "350px" }}>
|
||||
{/* <textarea
|
||||
value={this.state.value}
|
||||
required
|
||||
maxLength="250"
|
||||
@@ -275,101 +380,109 @@ class Quote extends Component {
|
||||
cols={40}
|
||||
rows={20}
|
||||
/> */}
|
||||
<TextField
|
||||
style={{width: 300}}
|
||||
value={this.state.value}
|
||||
label="Write Quoted Post here..."
|
||||
required
|
||||
multiline
|
||||
color="primary"
|
||||
rows="14"
|
||||
variant="outlined"
|
||||
inputProps={{
|
||||
maxLength: 250
|
||||
}}
|
||||
onChange={e => {
|
||||
this.handleChangeforPost(e);
|
||||
this.handleChangeforCharacterCount(e);
|
||||
}}
|
||||
autoComplete='off'
|
||||
></TextField>
|
||||
|
||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||
</div>
|
||||
<Button variant="outlined" color="primary" onClick={this.handleSubmit}>Share Quoted Post</Button>
|
||||
|
||||
<Button variant="outlined" color="primary" onClick={this.handleCloseModal}>Cancel</Button>
|
||||
<TextField
|
||||
style={{ width: 300 }}
|
||||
value={this.state.value}
|
||||
label="Write Quoted Post here..."
|
||||
required
|
||||
multiline
|
||||
color="primary"
|
||||
rows="14"
|
||||
variant="outlined"
|
||||
inputProps={{
|
||||
maxLength: 250
|
||||
}}
|
||||
onChange={e => {
|
||||
this.handleChangeforPost(e);
|
||||
this.handleChangeforCharacterCount(e);
|
||||
}}
|
||||
autoComplete="off"
|
||||
></TextField>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||
</div>
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={this.handleSubmit}
|
||||
>
|
||||
Share Quoted Post
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={this.handleCloseModal}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</ReactModal>
|
||||
<Button variant="outlined" color="primary" onClick={this.handleSubmitWithoutPost}>Quote without Post</Button>
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={this.handleSubmitWithoutPost}
|
||||
>
|
||||
Quote without Post
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Like extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
super(props);
|
||||
this.state = {
|
||||
num : this.props.count,
|
||||
|
||||
}
|
||||
num: this.props.count
|
||||
};
|
||||
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
like: localStorage.getItem(this.props.microBlog + this.props.name) === "false"
|
||||
|
||||
})
|
||||
|
||||
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())
|
||||
});
|
||||
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);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
@@ -390,33 +503,30 @@ class Like extends Component {
|
||||
})
|
||||
}
|
||||
} */
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
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) => ({
|
||||
const mapStateToProps = state => ({
|
||||
user: state.user,
|
||||
UI: state.UI
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
const mapActionsToProps = {
|
||||
likePost,
|
||||
unlikePost,
|
||||
getLikes
|
||||
}
|
||||
};
|
||||
|
||||
Home.propTypes = {
|
||||
user: PropTypes.object.isRequired,
|
||||
@@ -425,16 +535,17 @@ Home.propTypes = {
|
||||
getLikes: PropTypes.func.isRequired,
|
||||
classes: PropTypes.object.isRequired,
|
||||
UI: PropTypes.object.isRequired
|
||||
}
|
||||
};
|
||||
|
||||
Like.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
};
|
||||
|
||||
Quote.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
|
||||
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Home, Like, Quote));
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapActionsToProps
|
||||
)(withStyles(styles)(Home, Like, Quote));
|
||||
|
||||
@@ -83,6 +83,10 @@ const styles = {
|
||||
wordBreak: "break-all",
|
||||
color: 'black'
|
||||
},
|
||||
dmRecentMessageDisabled: {
|
||||
wordBreak: "break-all",
|
||||
color: 'red'
|
||||
},
|
||||
dmListItemContainer: {
|
||||
height: 100
|
||||
},
|
||||
@@ -105,7 +109,7 @@ const styles = {
|
||||
fontSize: 20,
|
||||
backgroundColor: '#1da1f2',
|
||||
width: 300
|
||||
},
|
||||
},
|
||||
messagesGrid: {
|
||||
// // margin: "auto"
|
||||
// height: "auto",
|
||||
@@ -377,7 +381,7 @@ export class directMessages extends Component {
|
||||
const open = Boolean(this.state.anchorEl);
|
||||
const id = open ? 'simple-popover' : undefined;
|
||||
|
||||
let dmListMarkup = this.state.dmData ? (
|
||||
let dmListMarkup = this.state.dmData ? (
|
||||
this.state.dmData.map((channel) => (
|
||||
<Card
|
||||
onClick={this.handleClickChannel}
|
||||
@@ -426,13 +430,19 @@ export class directMessages extends Component {
|
||||
<Typography
|
||||
className={
|
||||
this.state.selectedChannel && this.state.selectedChannel.dmId === channel.dmId ? (
|
||||
classes.dmRecentMessageSelected
|
||||
channel.hasDirectMessagesEnabled ?
|
||||
classes.dmRecentMessageSelected
|
||||
:
|
||||
classes.dmRecentMessageDisabled
|
||||
) : (
|
||||
classes.dmRecentMessageUnselected
|
||||
channel.hasDirectMessagesEnabled ?
|
||||
classes.dmRecentMessageUnselected
|
||||
:
|
||||
classes.dmRecentMessageDisabled
|
||||
)
|
||||
}
|
||||
>
|
||||
{
|
||||
{!channel.hasDirectMessagesEnabled ? "This user has DMs disabled" :
|
||||
!channel.recentMessage ?
|
||||
'No messages'
|
||||
:
|
||||
@@ -524,35 +534,35 @@ export class directMessages extends Component {
|
||||
onChange={this.handleChangeAddDMUsername}
|
||||
value={this.state.createDMUsername}
|
||||
label="Username"
|
||||
variant="outlined"
|
||||
helperText={errors.createDirectMessage}
|
||||
error={errors.createDirectMessage ? true : false}
|
||||
variant="outlined"
|
||||
helperText={errors.createDirectMessage}
|
||||
error={errors.createDirectMessage ? true : false}
|
||||
style={{
|
||||
width: 265,
|
||||
marginRight: 10,
|
||||
marginLeft: 10,
|
||||
textAlign: 'center',
|
||||
width: 265,
|
||||
marginRight: 10,
|
||||
marginLeft: 10,
|
||||
textAlign: 'center',
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Button
|
||||
className={classes.createButton}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={this.handleClickCreate}
|
||||
disabled={
|
||||
creatingDirectMessage ||
|
||||
this.state.createDMUsername === ""
|
||||
}
|
||||
>
|
||||
Create
|
||||
{creatingDirectMessage &&
|
||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||
// Won't accept classes style for some reason
|
||||
}
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Button
|
||||
className={classes.createButton}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={this.handleClickCreate}
|
||||
disabled={
|
||||
creatingDirectMessage ||
|
||||
this.state.createDMUsername === ""
|
||||
}
|
||||
>
|
||||
Create
|
||||
{creatingDirectMessage &&
|
||||
// Won't accept classes style for some reason
|
||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||
}
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item sm />
|
||||
@@ -572,13 +582,13 @@ export class directMessages extends Component {
|
||||
<Grid item className={classes.dmItemsUpper} id="dmItemsUpper">
|
||||
{dmListMarkup}
|
||||
</Grid>
|
||||
<Grid item className={classes.dmItemsLower}>
|
||||
<Card key="5555" data-key="5555" className={classes.dmCardUnselected}>
|
||||
<Box className={classes.dmListItemContainer}>
|
||||
{addDMMarkup}
|
||||
</Box>
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid item className={classes.dmItemsLower}>
|
||||
<Card key="5555" data-key="5555" className={classes.dmCardUnselected}>
|
||||
<Box className={classes.dmListItemContainer}>
|
||||
{addDMMarkup}
|
||||
</Box>
|
||||
</Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item className={classes.messagesGrid} sm>
|
||||
@@ -596,30 +606,39 @@ export class directMessages extends Component {
|
||||
variant="outlined"
|
||||
multiline
|
||||
rows={2}
|
||||
margin="dense"
|
||||
value={this.state.drafts[this.state.selectedChannel.dmId] ? this.state.drafts[this.state.selectedChannel.dmId] : ""}
|
||||
onChange={this.handleChangeMessage}
|
||||
margin="dense"
|
||||
disabled={!this.state.selectedChannel.hasDirectMessagesEnabled}
|
||||
value={
|
||||
!this.state.selectedChannel.hasDirectMessagesEnabled ?
|
||||
"This user has DMs disabled"
|
||||
:
|
||||
this.state.drafts[this.state.selectedChannel.dmId] ?
|
||||
this.state.drafts[this.state.selectedChannel.dmId]
|
||||
:
|
||||
""
|
||||
}
|
||||
onChange={this.handleChangeMessage}
|
||||
/>
|
||||
<Fab
|
||||
className={classes.messageButton}
|
||||
onClick={this.handleClickSend}
|
||||
disabled={
|
||||
sendingDirectMessage ||
|
||||
!this.state.drafts[this.state.selectedChannel.dmId] ||
|
||||
this.state.drafts[this.state.selectedChannel.dmId] === ""
|
||||
}
|
||||
>
|
||||
<Fab
|
||||
className={classes.messageButton}
|
||||
onClick={this.handleClickSend}
|
||||
disabled={
|
||||
sendingDirectMessage ||
|
||||
!this.state.drafts[this.state.selectedChannel.dmId] ||
|
||||
this.state.drafts[this.state.selectedChannel.dmId] === ""
|
||||
}
|
||||
>
|
||||
<SendIcon style={{ color: '#FFFFFF' }} />
|
||||
{
|
||||
sendingDirectMessage &&
|
||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||
// Won't accept classes style for some reason
|
||||
}
|
||||
{
|
||||
sendingDirectMessage &&
|
||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||
// Won't accept classes style for some reason
|
||||
}
|
||||
</Fab>
|
||||
</Box>
|
||||
</Card>
|
||||
)}
|
||||
{!this.state.hasChannelSelected &&
|
||||
{!this.state.hasChannelSelected &&
|
||||
this.state.dmData && <Typography>Select a DM on the left</Typography>}
|
||||
</Box>
|
||||
</Grid>
|
||||
|
||||
@@ -22,6 +22,7 @@ import AddCircle from "@material-ui/icons/AddCircle";
|
||||
import TextField from "@material-ui/core/TextField";
|
||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
||||
import DoneIcon from "@material-ui/icons/Done";
|
||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||
|
||||
// component
|
||||
import "../App.css";
|
||||
@@ -77,7 +78,9 @@ class user extends Component {
|
||||
user: null,
|
||||
following: null,
|
||||
posts: null,
|
||||
myTopics: null
|
||||
myTopics: null,
|
||||
followingList: null,
|
||||
loading: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +93,8 @@ class user extends Component {
|
||||
.then(res => {
|
||||
console.log("removed sub");
|
||||
this.setState({
|
||||
following: false
|
||||
following: false,
|
||||
myTopics: []
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
@@ -113,8 +117,27 @@ class user extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
handleAdd = newTopic => {
|
||||
axios
|
||||
.post("/putNewTopic", {
|
||||
handle: this.state.profile,
|
||||
topic: newTopic
|
||||
})
|
||||
.then(() => {
|
||||
let temp = this.state.myTopics;
|
||||
temp.push(newTopic);
|
||||
this.setState({
|
||||
myTopics: temp
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.err(err);
|
||||
});
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({ loading: true });
|
||||
let otherUserPromise = axios
|
||||
.post("/getUserDetails", {
|
||||
handle: this.state.profile
|
||||
})
|
||||
@@ -126,19 +149,26 @@ class user extends Component {
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
axios
|
||||
let userPromise = axios
|
||||
.get("/user")
|
||||
.then(res => {
|
||||
let list = [];
|
||||
let fol = false;
|
||||
res.data.credentials.following.forEach(follow => {
|
||||
// console.log(follow);
|
||||
if (this.state.profile === follow.handle) {
|
||||
fol = true;
|
||||
list = follow.topics;
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
following: res.data.credentials.following.includes(
|
||||
this.state.profile
|
||||
),
|
||||
myTopics: res.data.credentials.followedTopics
|
||||
following: fol,
|
||||
myTopics: list
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
axios
|
||||
let posts = axios
|
||||
.post("/getOtherUsersPosts", {
|
||||
handle: this.state.profile
|
||||
})
|
||||
@@ -149,6 +179,44 @@ class user extends Component {
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
// Only add Admin posts if this is not the Admin account
|
||||
let alertPromise;
|
||||
if (this.state.profile !== "Admin") {
|
||||
alertPromise = axios
|
||||
.get("/getAlert")
|
||||
.then(res => {
|
||||
let temp = this.state.posts;
|
||||
// console.log(res.data);
|
||||
res.data.forEach(element => {
|
||||
element ? temp.push(element) : console.err;
|
||||
});
|
||||
// temp.push(res.data[0]);
|
||||
this.setState({
|
||||
posts: temp
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
alertPromise = new Promise((resolve, reject) => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
Promise.all([otherUserPromise, userPromise, posts, alertPromise])
|
||||
.then(() => {
|
||||
this.setState({ loading: false });
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
formatDate(dateString) {
|
||||
let newDate = new Date(Date.parse(dateString));
|
||||
return newDate.toDateString();
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -177,8 +245,8 @@ class user extends Component {
|
||||
<p>loading username...</p>
|
||||
);
|
||||
|
||||
console.log(this.state.topics);
|
||||
console.log(this.state.myTopics);
|
||||
// console.log(this.state.topics);
|
||||
// console.log(this.state.myTopics);
|
||||
let topicsMarkup = this.state.topics ? (
|
||||
this.state.topics.map(
|
||||
topic =>
|
||||
@@ -186,16 +254,20 @@ class user extends Component {
|
||||
this.state.myTopics.includes(topic) ? (
|
||||
<MyChip
|
||||
label={topic}
|
||||
key={{ topic }.topic.id}
|
||||
key={{ topic }.id}
|
||||
onDelete
|
||||
deleteIcon={<DoneIcon />}
|
||||
/>
|
||||
) : (
|
||||
) : this.state.following ? (
|
||||
<MyChip
|
||||
label={topic}
|
||||
key={{ topic }.topic.id}
|
||||
key={{ topic }.id}
|
||||
color="secondary"
|
||||
clickable
|
||||
onClick={key => this.handleAdd(topic)}
|
||||
/>
|
||||
) : (
|
||||
<MyChip label={topic} key={{ topic }.id} color="secondary" />
|
||||
)
|
||||
) : (
|
||||
<p></p>
|
||||
@@ -211,10 +283,10 @@ class user extends Component {
|
||||
) : (
|
||||
<img src={noImage} height="150" width="150" />
|
||||
);
|
||||
|
||||
//(this.state.posts);
|
||||
let postMarkup = this.state.posts ? (
|
||||
this.state.posts.map(post => (
|
||||
<Card className={classes.card}>
|
||||
<Card className={classes.card} key={post.postId} data-key={post.postId}>
|
||||
<CardContent>
|
||||
<Typography>
|
||||
{this.state.imageUrl ? (
|
||||
@@ -223,11 +295,11 @@ class user extends Component {
|
||||
<img src={noImage} height="50" width="50" />
|
||||
)}
|
||||
</Typography>
|
||||
<Typography variant="h7">
|
||||
<Typography variant="h4">
|
||||
<b>{post.userHandle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
{post.createdAt}
|
||||
{this.formatDate(post.createdAt)}
|
||||
</Typography>
|
||||
|
||||
<br />
|
||||
@@ -240,7 +312,7 @@ class user extends Component {
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">
|
||||
<b>Topics:</b> {post.microBlogTopics}
|
||||
<b>Topics:</b> {post.microBlogTopics.join(", ")}
|
||||
</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
@@ -253,8 +325,13 @@ class user extends Component {
|
||||
<p>Posts</p>
|
||||
);
|
||||
|
||||
return (
|
||||
<Grid container spacing={24}>
|
||||
return this.state.loading ? (
|
||||
<CircularProgress
|
||||
size={60}
|
||||
style={{ marginTop: "300px" }}
|
||||
></CircularProgress>
|
||||
) : (
|
||||
<Grid container spacing={10}>
|
||||
<Grid item sm={4} xs={8}>
|
||||
{imageMarkup}
|
||||
{profileMarkup}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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 CircularProgress from "@material-ui/core/CircularProgress";
|
||||
|
||||
import Chip from "@material-ui/core/Chip";
|
||||
import Typography from "@material-ui/core/Typography";
|
||||
@@ -76,7 +77,8 @@ class user extends Component {
|
||||
profile: null,
|
||||
imageUrl: null,
|
||||
topics: null,
|
||||
newTopic: ""
|
||||
newTopic: "",
|
||||
loading: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,7 +129,8 @@ class user extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
axios
|
||||
this.setState({loading: true})
|
||||
let userPromise = axios
|
||||
.get("/user")
|
||||
.then(res => {
|
||||
this.setState({
|
||||
@@ -141,7 +144,7 @@ class user extends Component {
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
axios
|
||||
let postsPromise = axios
|
||||
.get("/getallPostsforUser")
|
||||
.then(res => {
|
||||
// console.log(res.data);
|
||||
@@ -150,6 +153,14 @@ class user extends Component {
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
|
||||
Promise.all([userPromise, postsPromise])
|
||||
.then(() => {
|
||||
this.setState({loading: false});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
|
||||
formatDate(dateString) {
|
||||
@@ -219,7 +230,7 @@ class user extends Component {
|
||||
<b>{post.userHandle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
{post.createdAt}
|
||||
{this.formatDate(post.createdAt) }
|
||||
</Typography>
|
||||
|
||||
<br />
|
||||
@@ -232,7 +243,7 @@ class user extends Component {
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">
|
||||
<b>Topics:</b> {post.microBlogTopics}
|
||||
<b>Topics:</b> {post.microBlogTopics.join(", ")}
|
||||
</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
@@ -258,7 +269,17 @@ class user extends Component {
|
||||
</Link>
|
||||
) : null;
|
||||
|
||||
let verifyButtonMarkup = this.state.profile === "Admin" ?
|
||||
<Link to="/verify">
|
||||
<Button className={classes.button} variant="outlined" color="primary">
|
||||
Verify Users
|
||||
</Button>
|
||||
</Link>
|
||||
:
|
||||
null
|
||||
|
||||
return (
|
||||
this.state.loading ? <CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress> :
|
||||
<div>
|
||||
{/* <Paper className={classes.paper}> */}
|
||||
<Grid container direction="column">
|
||||
@@ -266,6 +287,7 @@ class user extends Component {
|
||||
<Grid container>
|
||||
<Grid item sm>
|
||||
{editButtonMarkup}
|
||||
{verifyButtonMarkup}
|
||||
</Grid>
|
||||
<Grid item sm>
|
||||
{/* <Grid container direction="column"> */}
|
||||
|
||||
@@ -142,5 +142,6 @@ export const sendDirectMessage = (user, message) => (dispatch) => {
|
||||
sendDirectMessage: err.response.data
|
||||
}
|
||||
})
|
||||
dispatch({type: SET_NOT_LOADING_UI_4});
|
||||
})
|
||||
}
|
||||
@@ -36,6 +36,7 @@ export const getUserData = () => (dispatch) => {
|
||||
|
||||
// Sends login data to firebase and sets the user data in Redux
|
||||
export const loginUser = (loginData, history) => (dispatch) => {
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/login", loginData)
|
||||
@@ -57,6 +58,7 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
||||
|
||||
// Sends signup data to firebase and sets the user data in Redux
|
||||
export const signupUser = (newUserData, history) => (dispatch) => {
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/signup", newUserData)
|
||||
|
||||