Compare commits
57 Commits
impDarkThe
...
969ea4037b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
969ea4037b | ||
|
|
d1f42aa5cd | ||
|
|
f118ed76d1 | ||
|
|
858bdcce1a | ||
|
|
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-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 prefer-arrow-callback */
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
const admin = require("firebase-admin");
|
const { admin, db } = require("../util/admin");
|
||||||
const { db } = require("../util/admin");
|
|
||||||
|
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
const newPost = {
|
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) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
var post_query = admin
|
var post_query = admin
|
||||||
.firestore()
|
.firestore()
|
||||||
@@ -46,6 +58,106 @@ exports.getallPostsforUser = (req, res) => {
|
|||||||
myPosts.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
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);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.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) => {
|
exports.getOtherUsersPosts = (req, res) => {
|
||||||
var post_query = admin
|
var post_query = admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection("posts")
|
.collection("posts")
|
||||||
.where("userHandle", "==", req.body.handle);
|
.where("userHandle", "==", req.body.handle);
|
||||||
|
|
||||||
|
// post_query += admin
|
||||||
|
// .firestore()
|
||||||
|
// .collection("posts")
|
||||||
|
// .where("microBlogTitle", "==", "Alert").where("userHandle", "==", "Admin");
|
||||||
|
|
||||||
post_query
|
post_query
|
||||||
.get()
|
.get()
|
||||||
@@ -121,6 +190,7 @@ exports.getOtherUsersPosts = (req, res) => {
|
|||||||
myPosts.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
|
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
@@ -136,23 +206,25 @@ exports.getOtherUsersPosts = (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.quoteWithPost = (req, res) => {
|
exports.quoteWithPost = (req, res) => {
|
||||||
let quoteData;
|
let quoteData;
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
const quoteDoc = admin
|
||||||
where('userHandle', '==', req.user.handle).
|
.firestore()
|
||||||
where('quoteId', '==', req.params.postId).limit(1);
|
.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()
|
postDoc
|
||||||
.then((doc) => {
|
.get()
|
||||||
if(doc.exists) {
|
.then(doc => {
|
||||||
quoteData = doc.data();
|
if (doc.exists) {
|
||||||
return quoteDoc.get();
|
quoteData = doc.data();
|
||||||
}
|
return quoteDoc.get();
|
||||||
else
|
} else {
|
||||||
{
|
return res.status(404).json({ error: "Post not found" });
|
||||||
return res.status(404).json({error: 'Post not found'});
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.empty) {
|
if (data.empty) {
|
||||||
@@ -200,23 +272,25 @@ exports.quoteWithPost = (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.quoteWithoutPost = (req, res) => {
|
exports.quoteWithoutPost = (req, res) => {
|
||||||
let quoteData;
|
let quoteData;
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
const quoteDoc = admin
|
||||||
where('userHandle', '==', req.user.handle).
|
.firestore()
|
||||||
where('quoteId', '==', req.params.postId).limit(1);
|
.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()
|
postDoc
|
||||||
.then((doc) => {
|
.get()
|
||||||
if(doc.exists) {
|
.then(doc => {
|
||||||
quoteData = doc.data();
|
if (doc.exists) {
|
||||||
return quoteDoc.get();
|
quoteData = doc.data();
|
||||||
}
|
return quoteDoc.get();
|
||||||
else
|
} else {
|
||||||
{
|
return res.status(404).json({ error: "Post not found" });
|
||||||
return res.status(404).json({error: 'Post not found'});
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.empty) {
|
if (data.empty) {
|
||||||
@@ -258,7 +332,7 @@ exports.quoteWithoutPost = (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.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 });
|
return res.status(500).json({ error: err });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -272,202 +346,198 @@ exports.checkforLikePost = (req, res) => {
|
|||||||
.limit(1);
|
.limit(1);
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
likedPostDoc.get().then(data => {
|
likedPostDoc
|
||||||
if (data.empty) {
|
.get()
|
||||||
result = false;
|
.then(data => {
|
||||||
return res.status(200).json(result);
|
if (data.empty) {
|
||||||
} else {
|
result = false;
|
||||||
result = true;
|
return res.status(200).json(result);
|
||||||
return res.status(200).json(result);
|
} else {
|
||||||
}
|
result = true;
|
||||||
})
|
return res.status(200).json(result);
|
||||||
.catch((err) => {
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.status(500).json({error: err});
|
return res.status(500).json({ error: err });
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.likePost = (req, res) => {
|
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;
|
if (likes.includes(postId)) {
|
||||||
let likedPostDoc;
|
return res
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
.status(400)
|
||||||
.get()
|
.json({ error: "This user has already liked this post" });
|
||||||
.then((userDoc) => {
|
}
|
||||||
let likes = userDoc.data().likes;
|
|
||||||
if (likes === undefined || likes === null) {
|
|
||||||
likes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (likes.includes(postId)) {
|
likes.push(postId);
|
||||||
return res.status(400).json({error: "This user has already liked this post"});
|
|
||||||
}
|
|
||||||
|
|
||||||
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})
|
// let postData;
|
||||||
})
|
// const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||||
.then(() => {
|
// .where('postId', '==', req.params.postId).limit(1);
|
||||||
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 postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||||
// 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) => {
|
||||||
// postDoc.get()
|
// if(doc.exists) {
|
||||||
// .then((doc) => {
|
// postData = doc.data();
|
||||||
// if(doc.exists) {
|
// return likeDoc.get();
|
||||||
// postData = doc.data();
|
// }
|
||||||
// return likeDoc.get();
|
// else
|
||||||
// }
|
// {
|
||||||
// else
|
// return res.status(404).json({error: 'Post not found'});
|
||||||
// {
|
// }
|
||||||
// return res.status(404).json({error: 'Post not found'});
|
// })
|
||||||
// }
|
// .then((data) => {
|
||||||
// })
|
// if (data.empty) {
|
||||||
// .then((data) => {
|
// return admin.firestore().collection('likes').add({
|
||||||
// if (data.empty) {
|
// postId : req.params.postId,
|
||||||
// return admin.firestore().collection('likes').add({
|
// userHandle: req.user.handle
|
||||||
// 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'});
|
|
||||||
// })
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// })
|
||||||
|
// .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) => {
|
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;
|
if (!likes.includes(postId)) {
|
||||||
let likedPostDoc;
|
return res
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
.status(400)
|
||||||
.get()
|
.json({ error: "This user hasn't liked this post yet" });
|
||||||
.then((userDoc) => {
|
}
|
||||||
let likes = userDoc.data().likes;
|
|
||||||
if (likes === undefined || likes === null) {
|
|
||||||
likes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!likes.includes(postId)) {
|
let i;
|
||||||
return res.status(400).json({error: "This user hasn't liked this post yet"});
|
for (i = 0; i < likes.length; i++) {
|
||||||
}
|
if (likes[i] === postId) {
|
||||||
|
likes.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let i;
|
return userDoc.ref.update({ likes });
|
||||||
for (i = 0; i < likes.length; i++) {
|
})
|
||||||
if (likes[i] === postId) {
|
.then(() => {
|
||||||
likes.splice(i, 1);
|
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})
|
// let postData;
|
||||||
})
|
// const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||||
.then(() => {
|
// .where('postId', '==', req.params.postId).limit(1);
|
||||||
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 postDoc = db.doc(`/posts/${req.params.postId}`);
|
||||||
// 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) => {
|
||||||
// postDoc.get()
|
// if(doc.exists) {
|
||||||
// .then((doc) => {
|
// postData = doc.data();
|
||||||
// if(doc.exists) {
|
// return likeDoc.get();
|
||||||
// postData = doc.data();
|
// }
|
||||||
// return likeDoc.get();
|
// else
|
||||||
// }
|
// {
|
||||||
// else
|
// return res.status(404).json({error: 'Post not found'});
|
||||||
// {
|
// }
|
||||||
// return res.status(404).json({error: 'Post not found'});
|
// })
|
||||||
// }
|
// .then((data) => {
|
||||||
// })
|
// return db
|
||||||
// .then((data) => {
|
// .doc(`/likes/${data.docs[0].id}`)
|
||||||
// return db
|
// .delete()
|
||||||
// .doc(`/likes/${data.docs[0].id}`)
|
// .then(() => {
|
||||||
// .delete()
|
// postData.likeCount--;
|
||||||
// .then(() => {
|
// return postDoc.update({ likeCount: postData.likeCount });
|
||||||
// postData.likeCount--;
|
// })
|
||||||
// return postDoc.update({ likeCount: postData.likeCount });
|
// .then(() => {
|
||||||
// })
|
// res.status(200).json(postData);
|
||||||
// .then(() => {
|
// });
|
||||||
// res.status(200).json(postData);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.error(err);
|
|
||||||
// return res.status(500).json({error: 'Something is wrong'});
|
|
||||||
// })
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// console.error(err);
|
||||||
|
// return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
// })
|
||||||
|
};
|
||||||
|
|
||||||
exports.getLikes = (req, res) => {
|
exports.getLikes = (req, res) => {
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
db.doc(`/users/${req.userData.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then((doc) => {
|
.then(doc => {
|
||||||
let likes = doc.data().likes;
|
let likes = doc.data().likes;
|
||||||
if (likes === undefined || likes === null) {
|
if (likes === undefined || likes === null) {
|
||||||
likes = [];
|
likes = [];
|
||||||
}
|
}
|
||||||
return res.status(200).json({likes});
|
return res.status(200).json({ likes });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.status(500).json({error: err});
|
return res.status(500).json({ error: err });
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.getFilteredPosts = (req, res) => {
|
||||||
|
|
||||||
admin
|
admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection("posts")
|
.collection("posts")
|
||||||
.where("userHandle", "==", "new user")
|
.where("userHandle", "==", "new user")
|
||||||
.where("microBlogTopics", "==");
|
.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) => {
|
exports.getAllTopics = (req, res) => {
|
||||||
admin
|
admin
|
||||||
.firestore()
|
.firestore()
|
||||||
|
|||||||
@@ -100,18 +100,33 @@ app.post("/addSubscription", fbAuth, addSubscription);
|
|||||||
// remove one subscription
|
// remove one subscription
|
||||||
app.post("/removeSub", fbAuth, removeSub);
|
app.post("/removeSub", fbAuth, removeSub);
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* 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("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
app.get("/getallPosts", getallPosts);
|
app.get("/getallPosts", getallPosts);
|
||||||
|
|
||||||
|
//Hides Post
|
||||||
|
app.post("/hidePost", fbAuth, hidePost);
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post("/putPost", fbAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
|
|
||||||
@@ -125,6 +140,8 @@ app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
|||||||
|
|
||||||
app.post("/getOtherUsersPosts", fbAuth, getOtherUsersPosts);
|
app.post("/getOtherUsersPosts", fbAuth, getOtherUsersPosts);
|
||||||
|
|
||||||
|
app.get("/getAlert", fbAuth, getAlert);
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
@@ -132,7 +149,8 @@ const {
|
|||||||
putTopic,
|
putTopic,
|
||||||
getAllTopics,
|
getAllTopics,
|
||||||
deleteTopic,
|
deleteTopic,
|
||||||
getUserTopics
|
getUserTopics,
|
||||||
|
putNewTopic
|
||||||
} = require("./handlers/topic");
|
} = require("./handlers/topic");
|
||||||
|
|
||||||
// add topic to database
|
// add topic to database
|
||||||
@@ -147,4 +165,6 @@ app.post("/deleteTopic", fbAuth, deleteTopic);
|
|||||||
// get topic for this user
|
// get topic for this user
|
||||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
app.post("/getUserTopics", fbAuth, getUserTopics);
|
||||||
|
|
||||||
|
app.post("/putNewTopic", fbAuth, putNewTopic);
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
|
|||||||
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 |
50
twistter-frontend/package-lock.json
generated
@@ -2417,6 +2417,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",
|
||||||
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs="
|
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs="
|
||||||
},
|
},
|
||||||
|
"dayjs": {
|
||||||
|
"version": "1.10.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz",
|
||||||
|
"integrity": "sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@@ -3092,6 +3097,11 @@
|
|||||||
"merge": "^1.2.0"
|
"merge": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"exenv": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/exenv/-/exenv-1.2.2.tgz",
|
||||||
|
"integrity": "sha1-KueOhdmJQVhnCwPUe+wfA72Ru50="
|
||||||
|
},
|
||||||
"exit-hook": {
|
"exit-hook": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
|
||||||
@@ -3957,6 +3967,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||||
},
|
},
|
||||||
|
"fuse.js": {
|
||||||
|
"version": "3.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-3.4.6.tgz",
|
||||||
|
"integrity": "sha512-H6aJY4UpLFwxj1+5nAvufom5b2BT2v45P1MkPvdGIK8fWjQx/7o6tTT1+ALV0yawQvbmvCF0ufl2et8eJ7v7Cg=="
|
||||||
|
},
|
||||||
"gauge": {
|
"gauge": {
|
||||||
"version": "2.7.4",
|
"version": "2.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
|
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
|
||||||
@@ -4225,9 +4240,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hosted-git-info": {
|
"hosted-git-info": {
|
||||||
"version": "2.8.4",
|
"version": "2.8.9",
|
||||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.4.tgz",
|
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
|
||||||
"integrity": "sha512-pzXIvANXEFrc5oFFXRMkbLPQ2rXRoDERwDLyrcUxGhaZhgP54BBSl9Oheh7Vv0T090cszWBxPjkQQ5Sq1PbBRQ=="
|
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw=="
|
||||||
},
|
},
|
||||||
"html-comment-regex": {
|
"html-comment-regex": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
@@ -7167,6 +7182,22 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz",
|
||||||
"integrity": "sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw=="
|
"integrity": "sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw=="
|
||||||
},
|
},
|
||||||
|
"react-lifecycles-compat": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA=="
|
||||||
|
},
|
||||||
|
"react-modal": {
|
||||||
|
"version": "3.11.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-modal/-/react-modal-3.11.1.tgz",
|
||||||
|
"integrity": "sha512-8uN744Yq0X2lbfSLxsEEc2UV3RjSRb4yDVxRQ1aGzPo86QjNOwhQSukDb8U8kR+636TRTvfMren10fgOjAy9eA==",
|
||||||
|
"requires": {
|
||||||
|
"exenv": "^1.2.0",
|
||||||
|
"prop-types": "^15.5.10",
|
||||||
|
"react-lifecycles-compat": "^3.0.0",
|
||||||
|
"warning": "^4.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-redux": {
|
"react-redux": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.1.1.tgz",
|
||||||
@@ -9761,6 +9792,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz",
|
||||||
"integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE="
|
"integrity": "sha1-DqEOgDXo61uOREnwbaHHMGY7qoE="
|
||||||
},
|
},
|
||||||
|
"underscore": {
|
||||||
|
"version": "1.13.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz",
|
||||||
|
"integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g=="
|
||||||
|
},
|
||||||
"union-value": {
|
"union-value": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
||||||
@@ -9991,6 +10027,14 @@
|
|||||||
"makeerror": "1.0.x"
|
"makeerror": "1.0.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"warning": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==",
|
||||||
|
"requires": {
|
||||||
|
"loose-envify": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"watch": {
|
"watch": {
|
||||||
"version": "0.10.0",
|
"version": "0.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/watch/-/watch-0.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/watch/-/watch-0.10.0.tgz",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import TextField from '@material-ui/core/TextField';
|
|||||||
// import Typography from '@material-ui/core/Typography';
|
// import Typography from '@material-ui/core/Typography';
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import withStyles from "@material-ui/styles/withStyles";
|
import withStyles from "@material-ui/styles/withStyles";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
container: {
|
container: {
|
||||||
@@ -21,6 +22,13 @@ const styles = {
|
|||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 15
|
marginBottom: 15
|
||||||
|
},
|
||||||
|
progress: {
|
||||||
|
position: "absolute"
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
positon: "relative",
|
||||||
|
marginBottom: 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +39,8 @@ class Writing_Microblogs extends Component {
|
|||||||
value: "",
|
value: "",
|
||||||
title: "",
|
title: "",
|
||||||
topics: "",
|
topics: "",
|
||||||
characterCount: 250
|
characterCount: 250,
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
@@ -56,11 +65,15 @@ class Writing_Microblogs extends Component {
|
|||||||
microBlogTitle: this.state.title,
|
microBlogTitle: this.state.title,
|
||||||
microBlogTopics: this.state.topics.split(", ")
|
microBlogTopics: this.state.topics.split(", ")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
loading: true
|
||||||
|
})
|
||||||
const headers = {
|
const headers = {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
|
|
||||||
axios
|
let postPromise = axios
|
||||||
.post("/putPost", postData, headers) // TODO: add topics
|
.post("/putPost", postData, headers) // TODO: add topics
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// alert("Post was shared successfully!");
|
// alert("Post was shared successfully!");
|
||||||
@@ -71,20 +84,35 @@ class Writing_Microblogs extends Component {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
console.log(postData.microBlogTopics);
|
console.log(postData.microBlogTopics);
|
||||||
postData.microBlogTopics.forEach(topic => {
|
// let topicPromises = [];
|
||||||
axios
|
// postData.microBlogTopics.forEach(topic => {
|
||||||
.post("/putTopic", {
|
// topicPromises.push(axios
|
||||||
following: topic
|
// .post("/putTopic", {
|
||||||
})
|
// following: topic
|
||||||
.then(res => {
|
// })
|
||||||
console.log(res.data);
|
// .then(res => {
|
||||||
})
|
// console.log(res.data);
|
||||||
.catch(err => {
|
// })
|
||||||
console.error(err);
|
// .catch(err => {
|
||||||
});
|
// console.error(err);
|
||||||
});
|
// })
|
||||||
|
// )
|
||||||
|
// });
|
||||||
event.preventDefault();
|
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) {
|
handleChangeforPost(event) {
|
||||||
@@ -149,12 +177,14 @@ class Writing_Microblogs extends Component {
|
|||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
className={classes.button}
|
||||||
onClick={this.handleSubmit}
|
onClick={this.handleSubmit}
|
||||||
// disabled={loading}
|
disabled={this.state.loading}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="primary"
|
color="primary"
|
||||||
>
|
>
|
||||||
Share Post
|
Share Post
|
||||||
|
{this.state.loading && <CircularProgress size={30} className={classes.progress} />}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,78 +6,134 @@ import axios from "axios";
|
|||||||
|
|
||||||
// Material UI and React Router
|
// Material UI and React Router
|
||||||
|
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from "@material-ui/core/Button";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import Card from "@material-ui/core/Card";
|
import Card from "@material-ui/core/Card";
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
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 Typography from "@material-ui/core/Typography";
|
||||||
import withStyles from '@material-ui/styles/withStyles';
|
import withStyles from "@material-ui/styles/withStyles";
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import '../App.css';
|
import "../App.css";
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from "../images/twistter-logo.png";
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from "../images/no-img.png";
|
||||||
import Writing_Microblogs from '../Writing_Microblogs';
|
import Writing_Microblogs from "../Writing_Microblogs";
|
||||||
import ReactModal from 'react-modal';
|
import ReactModal from "react-modal";
|
||||||
|
|
||||||
// Redux
|
// Redux
|
||||||
import { likePost, unlikePost, getLikes } from '../redux/actions/userActions';
|
import { likePost, unlikePost, getLikes } from "../redux/actions/userActions";
|
||||||
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
card: {
|
card: {
|
||||||
marginBottom: 5
|
marginBottom: 5
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
state = {
|
state = {
|
||||||
likes: []
|
likes: [],
|
||||||
|
loading: false,
|
||||||
|
following: null,
|
||||||
|
topics: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
this.setState({ loading: true });
|
||||||
.get("/getallPosts")
|
let userPromise = axios
|
||||||
|
.get("/user")
|
||||||
.then(res => {
|
.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({
|
this.setState({
|
||||||
posts: res.data
|
following: list,
|
||||||
|
topics: res.data.credentials.followedTopics
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.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();
|
this.props.getLikes();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
this.setState({
|
this.setState({
|
||||||
likes: nextProps.user.likes
|
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) => {
|
handleClickLikeButton = (event) => {
|
||||||
// Need the ternary if statement because the user can click on the text or body of the
|
// 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
|
// Button and they are two different html elements
|
||||||
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
|
let postId = event.target.dataset.key
|
||||||
console.log(postId)
|
? event.target.dataset.key
|
||||||
|
: event.target.parentNode.dataset.key;
|
||||||
|
console.log(postId);
|
||||||
|
|
||||||
let doc = document.getElementById(postId);
|
let doc = document.getElementById(postId);
|
||||||
// console.log(postId);
|
// console.log(postId);
|
||||||
if (this.state.likes.includes(postId)) {
|
if (this.state.likes.includes(postId)) {
|
||||||
this.props.unlikePost(postId, this.state.likes)
|
this.props.unlikePost(postId, this.state.likes);
|
||||||
doc.dataset.likes--;
|
doc.dataset.likes--;
|
||||||
} else {
|
} else {
|
||||||
this.props.likePost(postId, this.state.likes)
|
this.props.likePost(postId, this.state.likes);
|
||||||
doc.dataset.likes++;
|
doc.dataset.likes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.innerHTML = "Likes " + doc.dataset.likes;
|
doc.innerHTML = "Likes " + doc.dataset.likes;
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
formatDate(dateString) {
|
formatDate(dateString) {
|
||||||
let newDate = new Date(Date.parse(dateString));
|
let newDate = new Date(Date.parse(dateString));
|
||||||
@@ -85,96 +141,133 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const {
|
||||||
const { UI:{ loading } } = this.props;
|
UI: { loading }
|
||||||
|
} = this.props;
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
let {classes} = this.props;
|
let { classes } = this.props;
|
||||||
let username = this.props.user.credentials.handle;
|
let username = this.props.user.credentials.handle;
|
||||||
|
console.log(username);
|
||||||
|
var hiddenBool = true;
|
||||||
|
if (username === "Admin") {
|
||||||
|
hiddenBool = false;
|
||||||
|
}
|
||||||
|
|
||||||
let postMarkup = this.state.posts ? (
|
console.log(hiddenBool);
|
||||||
this.state.posts.map(post =>
|
let postMarkup = this.state.posts ? ( this.state.following === undefined || this.state.following === null ? <Typography>You aren't following anybody right now</Typography> :
|
||||||
<Card className={classes.card} key={post.postId}>
|
this.state.posts.map(post => !post.hidden && this.state.following && (this.state.following.includes(post.userHandle) || post.userHandle === "Admin") ? (
|
||||||
<CardContent>
|
<Card className={classes.card} key={post.postId}>
|
||||||
<Typography>
|
<CardContent>
|
||||||
{/* {
|
<Typography>
|
||||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
{/* {
|
||||||
(<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"/>)
|
||||||
{
|
} */}
|
||||||
post.profileImage ? (<img src={post.profileImage} 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>
|
||||||
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||||
<br />
|
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
||||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
<br />
|
||||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
<br />
|
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
<br />
|
||||||
<br />
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
<br />
|
||||||
<br />
|
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join(", ")}</Typography>
|
||||||
<Typography id={post.postId} data-likes={post.likeCount} variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
<br />
|
||||||
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
|
{!hiddenBool &&
|
||||||
<Button
|
<Button
|
||||||
onClick={this.handleClickLikeButton}
|
onClick={this.flagPost}
|
||||||
data-key={post.postId}
|
data-key={post.postId}
|
||||||
disabled={loading}
|
variant = "contained"
|
||||||
variant="outlined"
|
color = "primary"
|
||||||
color="primary"
|
>
|
||||||
>{
|
Hide Post
|
||||||
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
|
</Button>
|
||||||
}</Button>
|
}
|
||||||
<Quote microblog = {post.postId}></Quote>
|
|
||||||
|
<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>
|
{/* <Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography> */}
|
||||||
</Card>
|
|
||||||
)
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
) : (
|
||||||
|
<p></p>
|
||||||
|
)
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<p>Loading post...</p>
|
<p>Loading post...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return authenticated ? (
|
||||||
authenticated ? (
|
this.state.loading ? (
|
||||||
<Grid container>
|
<CircularProgress
|
||||||
<Grid item sm={4} xs={8}>
|
size={60}
|
||||||
<Writing_Microblogs />
|
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>
|
||||||
<Grid item sm={4} xs={8}>
|
)
|
||||||
{postMarkup}
|
) : loading ? (
|
||||||
</Grid>
|
<CircularProgress
|
||||||
</Grid>
|
size={60}
|
||||||
) : loading ?
|
style={{ marginTop: "300px" }}
|
||||||
(<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>)
|
></CircularProgress>
|
||||||
:
|
) : (
|
||||||
(
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<br />
|
||||||
<br/><br/>
|
<br />
|
||||||
<b>Welcome to Twistter!</b>
|
<b>Welcome to Twistter!</b>
|
||||||
<br/><br/>
|
<br />
|
||||||
<b>See the most interesting topics people are following right now.</b>
|
<br />
|
||||||
</div>
|
<b>See the most interesting topics people are following right now.</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
<br/><br/><br/><br/>
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<b>Join today or sign in if you already have an account.</b>
|
<b>Join today or sign in if you already have an account.</b>
|
||||||
<br/><br/>
|
<br />
|
||||||
<form action="./signup">
|
<br />
|
||||||
<button className="authButtons signup">Sign up</button>
|
<form action="./signup">
|
||||||
</form>
|
<button className="authButtons signup">Sign up</button>
|
||||||
<br/>
|
</form>
|
||||||
<form action="./login">
|
<br />
|
||||||
<button className="authButtons login">Sign in</button>
|
<form action="./login">
|
||||||
</form>
|
<button className="authButtons login">Sign in</button>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
));
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,38 +278,36 @@ class Quote extends Component {
|
|||||||
characterCount: 250,
|
characterCount: 250,
|
||||||
showModal: false,
|
showModal: false,
|
||||||
value: ""
|
value: ""
|
||||||
}
|
};
|
||||||
|
|
||||||
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
|
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
|
||||||
this.handleOpenModal = this.handleOpenModal.bind(this);
|
this.handleOpenModal = this.handleOpenModal.bind(this);
|
||||||
this.handleCloseModal = this.handleCloseModal.bind(this);
|
this.handleCloseModal = this.handleCloseModal.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmitWithoutPost(event) {
|
handleSubmitWithoutPost(event) {
|
||||||
const post = {
|
const post = {
|
||||||
|
userImage: "bing-url"
|
||||||
userImage: "bing-url",
|
};
|
||||||
}
|
|
||||||
const headers = {
|
const headers = {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
axios.post(`/quoteWithoutPost/${this.props.microblog}`, post, headers)
|
axios
|
||||||
.then((res) => {
|
.post(`/quoteWithoutPost/${this.props.microblog}`, post, headers)
|
||||||
|
.then(res => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
console.error(err);
|
});
|
||||||
});
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleOpenModal() {
|
handleOpenModal() {
|
||||||
this.setState({ showModal: true });
|
this.setState({ showModal: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCloseModal() {
|
handleCloseModal() {
|
||||||
this.setState({ showModal: false, characterCount: 250, value: "" });
|
this.setState({ showModal: false, characterCount: 250, value: "" });
|
||||||
}
|
}
|
||||||
@@ -234,20 +325,19 @@ class Quote extends Component {
|
|||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
const quotedPost = {
|
const quotedPost = {
|
||||||
quoteBody: this.state.value,
|
quoteBody: this.state.value,
|
||||||
userImage: "bing-url",
|
userImage: "bing-url"
|
||||||
};
|
};
|
||||||
const headers = {
|
const headers = {
|
||||||
headers: { "Content-Type": "application/json" }
|
headers: { "Content-Type": "application/json" }
|
||||||
};
|
};
|
||||||
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
|
axios
|
||||||
.then((res) => {
|
.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
|
||||||
|
.then(res => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
console.error(err);
|
});
|
||||||
});
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({ showModal: false, characterCount: 250, value: "" });
|
this.setState({ showModal: false, characterCount: 250, value: "" });
|
||||||
}
|
}
|
||||||
@@ -255,14 +345,29 @@ class Quote extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button variant="outlined" color="primary" onClick={this.handleOpenModal}>Quote with Post</Button>
|
<Button
|
||||||
<ReactModal
|
variant="outlined"
|
||||||
isOpen={this.state.showModal}
|
color="primary"
|
||||||
style={{content: {height: "50%", width: "25%", marginTop: "auto", marginLeft: "auto", marginRight: "auto", marginBottom : "auto"}}}
|
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" }}>
|
<div style={{ width: "200px", marginLeft: "50px" }}>
|
||||||
<form style={{ width: "350px"}}>
|
<form style={{ width: "350px" }}>
|
||||||
{/* <textarea
|
{/* <textarea
|
||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
required
|
required
|
||||||
maxLength="250"
|
maxLength="250"
|
||||||
@@ -275,101 +380,109 @@ class Quote extends Component {
|
|||||||
cols={40}
|
cols={40}
|
||||||
rows={20}
|
rows={20}
|
||||||
/> */}
|
/> */}
|
||||||
<TextField
|
<TextField
|
||||||
style={{width: 300}}
|
style={{ width: 300 }}
|
||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
label="Write Quoted Post here..."
|
label="Write Quoted Post here..."
|
||||||
required
|
required
|
||||||
multiline
|
multiline
|
||||||
color="primary"
|
color="primary"
|
||||||
rows="14"
|
rows="14"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
maxLength: 250
|
maxLength: 250
|
||||||
}}
|
}}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
this.handleChangeforPost(e);
|
this.handleChangeforPost(e);
|
||||||
this.handleChangeforCharacterCount(e);
|
this.handleChangeforCharacterCount(e);
|
||||||
}}
|
}}
|
||||||
autoComplete='off'
|
autoComplete="off"
|
||||||
></TextField>
|
></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>
|
|
||||||
|
|
||||||
</form>
|
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
||||||
</div>
|
<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>
|
</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>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Like extends Component {
|
class Like extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
num : this.props.count,
|
num: this.props.count
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.setState({
|
this.setState({
|
||||||
like: localStorage.getItem(this.props.microBlog + this.props.name) === "false"
|
like:
|
||||||
|
localStorage.getItem(this.props.microBlog + this.props.name) === "false"
|
||||||
})
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handleClick(){
|
handleClick(){
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
like: !this.state.like
|
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)
|
if (this.state.like == false) {
|
||||||
{
|
this.setState(() => {
|
||||||
this.setState(() => {
|
return { num: this.state.num + 1 };
|
||||||
return {num: this.state.num + 1}
|
});
|
||||||
});
|
axios
|
||||||
axios.get(`/like/${this.props.microBlog}`)
|
.get(`/like/${this.props.microBlog}`)
|
||||||
.then((res) => {
|
.then(res => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
});
|
||||||
}
|
} else {
|
||||||
else
|
this.setState(() => {
|
||||||
{
|
return { num: this.state.num - 1 };
|
||||||
this.setState(() => {
|
});
|
||||||
return {num: this.state.num - 1}
|
axios
|
||||||
});
|
.get(`/unlike/${this.props.microBlog}`)
|
||||||
axios.get(`/unlike/${this.props.microBlog}`)
|
.then(res => {
|
||||||
.then((res) => {
|
console.log(res.data);
|
||||||
console.log(res.data);
|
})
|
||||||
})
|
.catch(err => {
|
||||||
.catch((err) => {
|
console.log(err);
|
||||||
console.log(err);
|
});
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* componentDidMount() {
|
/* 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,
|
user: state.user,
|
||||||
UI: state.UI
|
UI: state.UI
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
const mapActionsToProps = {
|
const mapActionsToProps = {
|
||||||
likePost,
|
likePost,
|
||||||
unlikePost,
|
unlikePost,
|
||||||
getLikes
|
getLikes
|
||||||
}
|
};
|
||||||
|
|
||||||
Home.propTypes = {
|
Home.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
@@ -425,16 +535,17 @@ Home.propTypes = {
|
|||||||
getLikes: PropTypes.func.isRequired,
|
getLikes: PropTypes.func.isRequired,
|
||||||
classes: PropTypes.object.isRequired,
|
classes: PropTypes.object.isRequired,
|
||||||
UI: PropTypes.object.isRequired
|
UI: PropTypes.object.isRequired
|
||||||
}
|
};
|
||||||
|
|
||||||
Like.propTypes = {
|
Like.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired
|
||||||
}
|
};
|
||||||
|
|
||||||
Quote.propTypes = {
|
Quote.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
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",
|
wordBreak: "break-all",
|
||||||
color: 'black'
|
color: 'black'
|
||||||
},
|
},
|
||||||
|
dmRecentMessageDisabled: {
|
||||||
|
wordBreak: "break-all",
|
||||||
|
color: 'red'
|
||||||
|
},
|
||||||
dmListItemContainer: {
|
dmListItemContainer: {
|
||||||
height: 100
|
height: 100
|
||||||
},
|
},
|
||||||
@@ -105,7 +109,7 @@ const styles = {
|
|||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
backgroundColor: '#1da1f2',
|
backgroundColor: '#1da1f2',
|
||||||
width: 300
|
width: 300
|
||||||
},
|
},
|
||||||
messagesGrid: {
|
messagesGrid: {
|
||||||
// // margin: "auto"
|
// // margin: "auto"
|
||||||
// height: "auto",
|
// height: "auto",
|
||||||
@@ -377,7 +381,7 @@ export class directMessages extends Component {
|
|||||||
const open = Boolean(this.state.anchorEl);
|
const open = Boolean(this.state.anchorEl);
|
||||||
const id = open ? 'simple-popover' : undefined;
|
const id = open ? 'simple-popover' : undefined;
|
||||||
|
|
||||||
let dmListMarkup = this.state.dmData ? (
|
let dmListMarkup = this.state.dmData ? (
|
||||||
this.state.dmData.map((channel) => (
|
this.state.dmData.map((channel) => (
|
||||||
<Card
|
<Card
|
||||||
onClick={this.handleClickChannel}
|
onClick={this.handleClickChannel}
|
||||||
@@ -426,13 +430,19 @@ export class directMessages extends Component {
|
|||||||
<Typography
|
<Typography
|
||||||
className={
|
className={
|
||||||
this.state.selectedChannel && this.state.selectedChannel.dmId === channel.dmId ? (
|
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 ?
|
!channel.recentMessage ?
|
||||||
'No messages'
|
'No messages'
|
||||||
:
|
:
|
||||||
@@ -524,35 +534,35 @@ export class directMessages extends Component {
|
|||||||
onChange={this.handleChangeAddDMUsername}
|
onChange={this.handleChangeAddDMUsername}
|
||||||
value={this.state.createDMUsername}
|
value={this.state.createDMUsername}
|
||||||
label="Username"
|
label="Username"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
helperText={errors.createDirectMessage}
|
helperText={errors.createDirectMessage}
|
||||||
error={errors.createDirectMessage ? true : false}
|
error={errors.createDirectMessage ? true : false}
|
||||||
style={{
|
style={{
|
||||||
width: 265,
|
width: 265,
|
||||||
marginRight: 10,
|
marginRight: 10,
|
||||||
marginLeft: 10,
|
marginLeft: 10,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<Button
|
<Button
|
||||||
className={classes.createButton}
|
className={classes.createButton}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={this.handleClickCreate}
|
onClick={this.handleClickCreate}
|
||||||
disabled={
|
disabled={
|
||||||
creatingDirectMessage ||
|
creatingDirectMessage ||
|
||||||
this.state.createDMUsername === ""
|
this.state.createDMUsername === ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
{creatingDirectMessage &&
|
{creatingDirectMessage &&
|
||||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
// Won't accept classes style for some reason
|
||||||
// Won't accept classes style for some reason
|
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||||
}
|
}
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
@@ -572,13 +582,13 @@ export class directMessages extends Component {
|
|||||||
<Grid item className={classes.dmItemsUpper} id="dmItemsUpper">
|
<Grid item className={classes.dmItemsUpper} id="dmItemsUpper">
|
||||||
{dmListMarkup}
|
{dmListMarkup}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item className={classes.dmItemsLower}>
|
<Grid item className={classes.dmItemsLower}>
|
||||||
<Card key="5555" data-key="5555" className={classes.dmCardUnselected}>
|
<Card key="5555" data-key="5555" className={classes.dmCardUnselected}>
|
||||||
<Box className={classes.dmListItemContainer}>
|
<Box className={classes.dmListItemContainer}>
|
||||||
{addDMMarkup}
|
{addDMMarkup}
|
||||||
</Box>
|
</Box>
|
||||||
</Card>
|
</Card>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item className={classes.messagesGrid} sm>
|
<Grid item className={classes.messagesGrid} sm>
|
||||||
@@ -596,30 +606,39 @@ export class directMessages extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
multiline
|
multiline
|
||||||
rows={2}
|
rows={2}
|
||||||
margin="dense"
|
margin="dense"
|
||||||
value={this.state.drafts[this.state.selectedChannel.dmId] ? this.state.drafts[this.state.selectedChannel.dmId] : ""}
|
disabled={!this.state.selectedChannel.hasDirectMessagesEnabled}
|
||||||
onChange={this.handleChangeMessage}
|
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
|
<Fab
|
||||||
className={classes.messageButton}
|
className={classes.messageButton}
|
||||||
onClick={this.handleClickSend}
|
onClick={this.handleClickSend}
|
||||||
disabled={
|
disabled={
|
||||||
sendingDirectMessage ||
|
sendingDirectMessage ||
|
||||||
!this.state.drafts[this.state.selectedChannel.dmId] ||
|
!this.state.drafts[this.state.selectedChannel.dmId] ||
|
||||||
this.state.drafts[this.state.selectedChannel.dmId] === ""
|
this.state.drafts[this.state.selectedChannel.dmId] === ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SendIcon style={{ color: '#FFFFFF' }} />
|
<SendIcon style={{ color: '#FFFFFF' }} />
|
||||||
{
|
{
|
||||||
sendingDirectMessage &&
|
sendingDirectMessage &&
|
||||||
<CircularProgress size={30} style={{position: "absolute"}}/>
|
<CircularProgress size={30} style={{position: "absolute"}}/>
|
||||||
// Won't accept classes style for some reason
|
// Won't accept classes style for some reason
|
||||||
}
|
}
|
||||||
</Fab>
|
</Fab>
|
||||||
</Box>
|
</Box>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
{!this.state.hasChannelSelected &&
|
{!this.state.hasChannelSelected &&
|
||||||
this.state.dmData && <Typography>Select a DM on the left</Typography>}
|
this.state.dmData && <Typography>Select a DM on the left</Typography>}
|
||||||
</Box>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import AddCircle from "@material-ui/icons/AddCircle";
|
|||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
||||||
import DoneIcon from "@material-ui/icons/Done";
|
import DoneIcon from "@material-ui/icons/Done";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import "../App.css";
|
import "../App.css";
|
||||||
@@ -77,7 +78,9 @@ class user extends Component {
|
|||||||
user: null,
|
user: null,
|
||||||
following: null,
|
following: null,
|
||||||
posts: null,
|
posts: null,
|
||||||
myTopics: null
|
myTopics: null,
|
||||||
|
followingList: null,
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +93,8 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
console.log("removed sub");
|
console.log("removed sub");
|
||||||
this.setState({
|
this.setState({
|
||||||
following: false
|
following: false,
|
||||||
|
myTopics: []
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
@@ -113,8 +117,27 @@ class user extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
handleAdd = newTopic => {
|
||||||
axios
|
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", {
|
.post("/getUserDetails", {
|
||||||
handle: this.state.profile
|
handle: this.state.profile
|
||||||
})
|
})
|
||||||
@@ -126,19 +149,26 @@ class user extends Component {
|
|||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
let userPromise = axios
|
||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.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({
|
this.setState({
|
||||||
following: res.data.credentials.following.includes(
|
following: fol,
|
||||||
this.state.profile
|
myTopics: list
|
||||||
),
|
|
||||||
myTopics: res.data.credentials.followedTopics
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
let posts = axios
|
||||||
.post("/getOtherUsersPosts", {
|
.post("/getOtherUsersPosts", {
|
||||||
handle: this.state.profile
|
handle: this.state.profile
|
||||||
})
|
})
|
||||||
@@ -149,6 +179,44 @@ class user extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.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() {
|
render() {
|
||||||
@@ -177,8 +245,8 @@ class user extends Component {
|
|||||||
<p>loading username...</p>
|
<p>loading username...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(this.state.topics);
|
// console.log(this.state.topics);
|
||||||
console.log(this.state.myTopics);
|
// console.log(this.state.myTopics);
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(
|
||||||
topic =>
|
topic =>
|
||||||
@@ -186,16 +254,20 @@ class user extends Component {
|
|||||||
this.state.myTopics.includes(topic) ? (
|
this.state.myTopics.includes(topic) ? (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={topic}
|
||||||
key={{ topic }.topic.id}
|
key={{ topic }.id}
|
||||||
onDelete
|
onDelete
|
||||||
deleteIcon={<DoneIcon />}
|
deleteIcon={<DoneIcon />}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : this.state.following ? (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={topic}
|
||||||
key={{ topic }.topic.id}
|
key={{ topic }.id}
|
||||||
color="secondary"
|
color="secondary"
|
||||||
|
clickable
|
||||||
|
onClick={key => this.handleAdd(topic)}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<MyChip label={topic} key={{ topic }.id} color="secondary" />
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<p></p>
|
<p></p>
|
||||||
@@ -211,10 +283,10 @@ class user extends Component {
|
|||||||
) : (
|
) : (
|
||||||
<img src={noImage} height="150" width="150" />
|
<img src={noImage} height="150" width="150" />
|
||||||
);
|
);
|
||||||
|
//(this.state.posts);
|
||||||
let postMarkup = this.state.posts ? (
|
let postMarkup = this.state.posts ? (
|
||||||
this.state.posts.map(post => (
|
this.state.posts.map(post => (
|
||||||
<Card className={classes.card}>
|
<Card className={classes.card} key={post.postId} data-key={post.postId}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography>
|
<Typography>
|
||||||
{this.state.imageUrl ? (
|
{this.state.imageUrl ? (
|
||||||
@@ -223,11 +295,11 @@ class user extends Component {
|
|||||||
<img src={noImage} height="50" width="50" />
|
<img src={noImage} height="50" width="50" />
|
||||||
)}
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h7">
|
<Typography variant="h4">
|
||||||
<b>{post.userHandle}</b>
|
<b>{post.userHandle}</b>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
{post.createdAt}
|
{this.formatDate(post.createdAt)}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
@@ -240,7 +312,7 @@ class user extends Component {
|
|||||||
<Typography variant="body2">{post.body}</Typography>
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
<b>Topics:</b> {post.microBlogTopics}
|
<b>Topics:</b> {post.microBlogTopics.join(", ")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
@@ -253,8 +325,13 @@ class user extends Component {
|
|||||||
<p>Posts</p>
|
<p>Posts</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return this.state.loading ? (
|
||||||
<Grid container spacing={24}>
|
<CircularProgress
|
||||||
|
size={60}
|
||||||
|
style={{ marginTop: "300px" }}
|
||||||
|
></CircularProgress>
|
||||||
|
) : (
|
||||||
|
<Grid container spacing={10}>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import CardMedia from "@material-ui/core/CardMedia";
|
|||||||
import CardContent from "@material-ui/core/CardContent";
|
import CardContent from "@material-ui/core/CardContent";
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
|
||||||
import Chip from "@material-ui/core/Chip";
|
import Chip from "@material-ui/core/Chip";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
@@ -76,7 +77,8 @@ class user extends Component {
|
|||||||
profile: null,
|
profile: null,
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
topics: null,
|
topics: null,
|
||||||
newTopic: ""
|
newTopic: "",
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +129,8 @@ class user extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
this.setState({loading: true})
|
||||||
|
let userPromise = axios
|
||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -141,7 +144,7 @@ class user extends Component {
|
|||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
let postsPromise = axios
|
||||||
.get("/getallPostsforUser")
|
.get("/getallPostsforUser")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log(res.data);
|
// console.log(res.data);
|
||||||
@@ -150,6 +153,14 @@ class user extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
|
Promise.all([userPromise, postsPromise])
|
||||||
|
.then(() => {
|
||||||
|
this.setState({loading: false});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
formatDate(dateString) {
|
formatDate(dateString) {
|
||||||
@@ -219,7 +230,7 @@ class user extends Component {
|
|||||||
<b>{post.userHandle}</b>
|
<b>{post.userHandle}</b>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
{post.createdAt}
|
{this.formatDate(post.createdAt) }
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
@@ -232,7 +243,7 @@ class user extends Component {
|
|||||||
<Typography variant="body2">{post.body}</Typography>
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
<b>Topics:</b> {post.microBlogTopics}
|
<b>Topics:</b> {post.microBlogTopics.join(", ")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
@@ -258,7 +269,17 @@ class user extends Component {
|
|||||||
</Link>
|
</Link>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
|
let verifyButtonMarkup = this.state.profile === "Admin" ?
|
||||||
|
<Link to="/verify">
|
||||||
|
<Button className={classes.button} variant="outlined" color="primary">
|
||||||
|
Verify Users
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
:
|
||||||
|
null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
this.state.loading ? <CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress> :
|
||||||
<div>
|
<div>
|
||||||
{/* <Paper className={classes.paper}> */}
|
{/* <Paper className={classes.paper}> */}
|
||||||
<Grid container direction="column">
|
<Grid container direction="column">
|
||||||
@@ -266,6 +287,7 @@ class user extends Component {
|
|||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
{editButtonMarkup}
|
{editButtonMarkup}
|
||||||
|
{verifyButtonMarkup}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
{/* <Grid container direction="column"> */}
|
{/* <Grid container direction="column"> */}
|
||||||
|
|||||||
@@ -142,5 +142,6 @@ export const sendDirectMessage = (user, message) => (dispatch) => {
|
|||||||
sendDirectMessage: err.response.data
|
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
|
// Sends login data to firebase and sets the user data in Redux
|
||||||
export const loginUser = (loginData, history) => (dispatch) => {
|
export const loginUser = (loginData, history) => (dispatch) => {
|
||||||
|
dispatch({type: CLEAR_ERRORS});
|
||||||
dispatch({ type: LOADING_UI });
|
dispatch({ type: LOADING_UI });
|
||||||
axios
|
axios
|
||||||
.post("/login", loginData)
|
.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
|
// Sends signup data to firebase and sets the user data in Redux
|
||||||
export const signupUser = (newUserData, history) => (dispatch) => {
|
export const signupUser = (newUserData, history) => (dispatch) => {
|
||||||
|
dispatch({type: CLEAR_ERRORS});
|
||||||
dispatch({ type: LOADING_UI });
|
dispatch({ type: LOADING_UI });
|
||||||
axios
|
axios
|
||||||
.post("/signup", newUserData)
|
.post("/signup", newUserData)
|
||||||
|
|||||||