mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Compare commits
43 Commits
chronologi
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47319308e3 | ||
|
|
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 | ||
|
|
c7859e0f0a | ||
|
|
aad9dc0273 | ||
|
|
30df98343e | ||
| 719294f0ed | |||
|
|
de72bd9223 | ||
|
|
bae2947003 | ||
|
|
96423cee8a | ||
|
|
6924af58a7 |
@@ -1,2 +1,2 @@
|
|||||||
# CS307-Team24
|
# CS307-Team24
|
||||||
CS307 Team 24 Twistter website.
|
CS307 Team 24 Twistter website
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -62,59 +74,81 @@ exports.getallPostsforUser = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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) => {
|
exports.getallPosts = (req, res) => {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
let users = {};
|
let users = {};
|
||||||
|
|
||||||
// Get all the posts
|
// Get all the posts
|
||||||
var postsPromise = new Promise((resolve, reject) => {
|
var postsPromise = new Promise((resolve, reject) => {
|
||||||
db.collection("posts").get()
|
db.collection("posts")
|
||||||
.then((allPosts) => {
|
.get()
|
||||||
allPosts.forEach((post) => {
|
.then(allPosts => {
|
||||||
|
allPosts.forEach(post => {
|
||||||
posts.push(post.data());
|
posts.push(post.data());
|
||||||
});
|
});
|
||||||
|
posts.sort((a, b) => -a.createdAt.localeCompare(b.createdAt));
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get all users
|
// Get all users
|
||||||
var usersPromise = new Promise((resolve, reject) => {
|
var usersPromise = new Promise((resolve, reject) => {
|
||||||
db.collection("users").get()
|
db.collection("users")
|
||||||
.then((allUsers) => {
|
.get()
|
||||||
allUsers.forEach((user) => {
|
.then(allUsers => {
|
||||||
|
allUsers.forEach(user => {
|
||||||
users[user.data().handle] = user.data();
|
users[user.data().handle] = user.data();
|
||||||
})
|
});
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for the two promises
|
// Wait for the two promises
|
||||||
Promise.all([postsPromise, usersPromise])
|
Promise.all([postsPromise, usersPromise])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
let newPosts = []
|
let newPosts = [];
|
||||||
// Add the image url of the person who made the post to all of the post objects
|
// Add the image url of the person who made the post to all of the post objects
|
||||||
posts.forEach((post) => {
|
posts.forEach(post => {
|
||||||
post.profileImage = users[post.userHandle].imageUrl ? users[post.userHandle].imageUrl : null;
|
post.profileImage = users[post.userHandle].imageUrl
|
||||||
|
? users[post.userHandle].imageUrl
|
||||||
|
: null;
|
||||||
newPosts.push(post);
|
newPosts.push(post);
|
||||||
});
|
});
|
||||||
return res.status(200).json(newPosts);
|
return res.status(200).json(newPosts);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(error => {
|
||||||
return res.status(500).json({error});
|
return res.status(500).json({ error });
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getOtherUsersPosts = (req, res) => {
|
exports.getAlert = (req, res) => {
|
||||||
var post_query = admin
|
var post_query = admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection("posts")
|
.collection("posts")
|
||||||
.where("userHandle", "==", req.body.handle);
|
.where("microBlogTitle", "==", "Alert");
|
||||||
|
|
||||||
post_query
|
post_query
|
||||||
.get()
|
.get()
|
||||||
@@ -123,6 +157,40 @@ 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);
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
return res
|
||||||
|
.status(200)
|
||||||
|
.json("Successfully retrieved all user's posts from database.");
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json("Failed to retrieve user's posts from database.", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.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()
|
||||||
|
.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() {
|
||||||
@@ -138,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) {
|
||||||
@@ -202,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) {
|
||||||
@@ -260,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 });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -274,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()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||||
|
|||||||
81
twistter-frontend/package-lock.json
generated
81
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",
|
||||||
@@ -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",
|
||||||
@@ -9119,21 +9150,42 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sockjs": {
|
"sockjs": {
|
||||||
"version": "0.3.19",
|
"version": "0.3.21",
|
||||||
"resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.19.tgz",
|
"resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.21.tgz",
|
||||||
"integrity": "sha512-V48klKZl8T6MzatbLlzzRNhMepEys9Y4oGFpypBFFn1gLI/QQ9HtLLyWJNbPlwGLelOVOEijUbTTJeLLI59jLw==",
|
"integrity": "sha512-DhbPFGpxjc6Z3I+uX07Id5ZO2XwYsWOrYjaSeieES78cq+JaJvVe5q/m1uvjIQhXinhIeCFRH6JgXe+mvVMyXw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"faye-websocket": "^0.10.0",
|
"faye-websocket": "^0.11.3",
|
||||||
"uuid": "^3.0.1"
|
"uuid": "^3.4.0",
|
||||||
|
"websocket-driver": "^0.7.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"faye-websocket": {
|
"faye-websocket": {
|
||||||
"version": "0.10.0",
|
"version": "0.11.3",
|
||||||
"resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.3.tgz",
|
||||||
"integrity": "sha1-TkkvjQTftviQA1B/btvy1QHnxvQ=",
|
"integrity": "sha512-D2y4bovYpzziGgbHYtGCMjlJM36vAl/y+xUyn1C+FVx8szd1E+86KwVw6XvYSzOP8iMpm1X0I4xJD+QtUb36OA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"websocket-driver": ">=0.5.1"
|
"websocket-driver": ">=0.5.1"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"http-parser-js": {
|
||||||
|
"version": "0.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-t7hjvef/5HEK7RWTdUzVUhl8zkEu+LlaE0IYzdMuvbSDipxBRpOn4Uhw8ZyECEa808iVT8XCjzo6xmYt4CiLZg=="
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "3.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
|
||||||
|
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
|
||||||
|
},
|
||||||
|
"websocket-driver": {
|
||||||
|
"version": "0.7.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz",
|
||||||
|
"integrity": "sha512-b17KeDIQVjvb0ssuSDF2cYXSg2iztliJ4B9WdsuB6J952qCPKmnVq4DyW5motImXHDC1cBT/1UezrJVsKw5zjg==",
|
||||||
|
"requires": {
|
||||||
|
"http-parser-js": ">=0.5.1",
|
||||||
|
"safe-buffer": ">=5.1.0",
|
||||||
|
"websocket-extensions": ">=0.1.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -9761,6 +9813,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 +10048,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",
|
||||||
|
|||||||
@@ -84,23 +84,23 @@ class Writing_Microblogs extends Component {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
console.log(postData.microBlogTopics);
|
console.log(postData.microBlogTopics);
|
||||||
let topicPromises = [];
|
// let topicPromises = [];
|
||||||
postData.microBlogTopics.forEach(topic => {
|
// postData.microBlogTopics.forEach(topic => {
|
||||||
topicPromises.push(axios
|
// topicPromises.push(axios
|
||||||
.post("/putTopic", {
|
// .post("/putTopic", {
|
||||||
following: topic
|
// following: topic
|
||||||
})
|
// })
|
||||||
.then(res => {
|
// .then(res => {
|
||||||
console.log(res.data);
|
// console.log(res.data);
|
||||||
})
|
// })
|
||||||
.catch(err => {
|
// .catch(err => {
|
||||||
console.error(err);
|
// console.error(err);
|
||||||
})
|
// })
|
||||||
)
|
// )
|
||||||
});
|
// });
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
topicPromises.push(postPromise);
|
// topicPromises.push(postPromise);
|
||||||
Promise.all(topicPromises)
|
Promise.all([postPromise])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
value: "",
|
value: "",
|
||||||
|
|||||||
@@ -41,36 +41,55 @@ class Home extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.setState({loading: true});
|
this.setState({ loading: true });
|
||||||
let userPromise = axios
|
let userPromise = axios
|
||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
console.log(res.data.credentials.following);
|
||||||
|
let list = [];
|
||||||
|
res.data.credentials.following.forEach(element => {
|
||||||
|
list.push(element.handle);
|
||||||
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
following: res.data.credentials.following,
|
following: list,
|
||||||
topics: res.data.credentials.followedTopics
|
topics: res.data.credentials.followedTopics
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
|
let allPosts;
|
||||||
let postPromise = axios
|
let postPromise = axios
|
||||||
.get("/getallPosts")
|
.get("/getallPosts")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log(res.data);
|
// 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({
|
this.setState({
|
||||||
posts: res.data
|
posts: allPosts
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
Promise.all([userPromise, postPromise])
|
Promise.all([userPromise, postPromise])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false
|
loading: false
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.props.getLikes();
|
this.props.getLikes();
|
||||||
}
|
}
|
||||||
@@ -81,8 +100,22 @@ class Home extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickLikeButton = event => {
|
flagPost = (event) => {
|
||||||
// Need the ternary if statement because the user can click on the text or body of the
|
// 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
|
// Button and they are two different html elements
|
||||||
let postId = event.target.dataset.key
|
let postId = event.target.dataset.key
|
||||||
? event.target.dataset.key
|
? event.target.dataset.key
|
||||||
@@ -114,51 +147,49 @@ class Home extends Component {
|
|||||||
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(this.state.following);
|
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> :
|
||||||
this.state.following ? (
|
this.state.posts.map(post => !post.hidden && this.state.following && (this.state.following.includes(post.userHandle) || post.userHandle === "Admin") ? (
|
||||||
this.state.following.includes(post.userHandle) ? (
|
|
||||||
<Card className={classes.card} key={post.postId}>
|
<Card className={classes.card} key={post.postId}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography>
|
<Typography>
|
||||||
{/* {
|
{/* {
|
||||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
||||||
(<img src={noImage} height="50" width="50"/>)
|
(<img src={noImage} height="50" width="50"/>)
|
||||||
} */}
|
} */}
|
||||||
{post.profileImage ? (
|
{
|
||||||
<img src={post.profileImage} height="50" width="50" />
|
post.profileImage ? (<img src={post.profileImage} height="50" width="50" />) :
|
||||||
) : (
|
(<img src={noImage} 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>
|
</Typography>
|
||||||
|
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body1">
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
<b>{post.microBlogTitle}</b>
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<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.join(", ")}</Typography>
|
||||||
<b>Topics:</b> {post.microBlogTopics}
|
|
||||||
</Typography>
|
|
||||||
<br />
|
<br />
|
||||||
<Typography
|
{!hiddenBool &&
|
||||||
id={post.postId}
|
<Button
|
||||||
data-likes={post.likeCount}
|
onClick={this.flagPost}
|
||||||
variant="body2"
|
data-key={post.postId}
|
||||||
color={"textSecondary"}
|
variant = "contained"
|
||||||
|
color = "primary"
|
||||||
>
|
>
|
||||||
Likes {post.likeCount}
|
Hide Post
|
||||||
</Typography>
|
</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> */}
|
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
|
||||||
<Button
|
<Button
|
||||||
onClick={this.handleClickLikeButton}
|
onClick={this.handleClickLikeButton}
|
||||||
@@ -166,70 +197,76 @@ class Home extends Component {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="primary"
|
color="primary"
|
||||||
>
|
>{
|
||||||
{this.state.likes && this.state.likes.includes(post.postId)
|
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
|
||||||
? "Unlike"
|
}</Button>
|
||||||
: "Like"}
|
<Quote microblog = {post.postId}></Quote>
|
||||||
</Button>
|
|
||||||
<Quote microblog={post.postId}></Quote>
|
|
||||||
|
|
||||||
{/* <button>Quote</button> */}
|
{/* <button>Quote</button> */}
|
||||||
|
|
||||||
|
{/* <Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography> */}
|
||||||
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
) : (
|
|
||||||
<p></p>
|
|
||||||
)
|
|
||||||
) : (
|
) : (
|
||||||
<p>Loading</p>
|
<p></p>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<p>Loading post...</p>
|
<p>Loading post...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return authenticated ? (
|
||||||
authenticated ? (
|
this.state.loading ? (
|
||||||
this.state.loading ? (<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>) :
|
<CircularProgress
|
||||||
<Grid container>
|
size={60}
|
||||||
<Grid item sm={4} xs={8}>
|
style={{ marginTop: "300px" }}
|
||||||
<Writing_Microblogs />
|
></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 />
|
<br />
|
||||||
<form action="./signup">
|
<form action="./signup">
|
||||||
<button className="authButtons signup">Sign up</button>
|
<button className="authButtons signup">Sign up</button>
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
<form action="./login">
|
<form action="./login">
|
||||||
<button className="authButtons login">Sign in</button>
|
<button className="authButtons login">Sign in</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,7 +449,7 @@ class Like extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
handleClick(){
|
||||||
this.setState({
|
this.setState({
|
||||||
like: !this.state.like
|
like: !this.state.like
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class user extends Component {
|
|||||||
following: null,
|
following: null,
|
||||||
posts: null,
|
posts: null,
|
||||||
myTopics: null,
|
myTopics: null,
|
||||||
|
followingList: null,
|
||||||
loading: false
|
loading: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -92,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) {
|
||||||
@@ -115,8 +117,26 @@ class user extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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() {
|
componentDidMount() {
|
||||||
this.setState({loading: true});
|
this.setState({ loading: true });
|
||||||
let otherUserPromise = axios
|
let otherUserPromise = axios
|
||||||
.post("/getUserDetails", {
|
.post("/getUserDetails", {
|
||||||
handle: this.state.profile
|
handle: this.state.profile
|
||||||
@@ -132,11 +152,18 @@ class user extends Component {
|
|||||||
let userPromise = 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));
|
||||||
@@ -153,13 +180,43 @@ class user extends Component {
|
|||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
Promise.all([otherUserPromise, userPromise, posts])
|
// Only add Admin posts if this is not the Admin account
|
||||||
.then(() => {
|
let alertPromise;
|
||||||
this.setState({loading: false});
|
if (this.state.profile !== "Admin") {
|
||||||
})
|
alertPromise = axios
|
||||||
.catch((error) => {
|
.get("/getAlert")
|
||||||
console.log(error);
|
.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() {
|
||||||
@@ -188,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 =>
|
||||||
@@ -197,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>
|
||||||
@@ -222,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 ? (
|
||||||
@@ -234,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 />
|
||||||
@@ -251,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"}>
|
||||||
@@ -264,9 +325,13 @@ class user extends Component {
|
|||||||
<p>Posts</p>
|
<p>Posts</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return this.state.loading ? (
|
||||||
this.state.loading ? <CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress> :
|
<CircularProgress
|
||||||
<Grid container spacing={24}>
|
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}
|
||||||
|
|||||||
@@ -269,6 +269,15 @@ 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> :
|
this.state.loading ? <CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress> :
|
||||||
<div>
|
<div>
|
||||||
@@ -278,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user