mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Merge branch 'master' into likes
This commit is contained in:
commit
6989091fb1
@ -1,76 +1,141 @@
|
|||||||
/* eslint-disable prefer-arrow-callback */
|
/* eslint-disable prefer-arrow-callback */
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
const admin = require('firebase-admin');
|
const admin = require("firebase-admin");
|
||||||
const { db } = require('../util/admin');
|
const { db } = require("../util/admin");
|
||||||
|
|
||||||
|
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
const newPost = {
|
const newPost = {
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
userHandle: req.user.handle,
|
userHandle: req.user.handle,
|
||||||
userImage: req.body.userImage,
|
userImage: req.body.userImage,
|
||||||
userID: req.user.uid,
|
userID: req.user.uid,
|
||||||
microBlogTitle: req.body.microBlogTitle,
|
microBlogTitle: req.body.microBlogTitle,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
likeCount: 0,
|
likeCount: 0,
|
||||||
commentCount: 0,
|
commentCount: 0,
|
||||||
microBlogTopics: req.body.microBlogTopics,
|
microBlogTopics: req.body.microBlogTopics,
|
||||||
quoteBody: null
|
quoteBody: null
|
||||||
};
|
};
|
||||||
|
|
||||||
admin.firestore().collection('posts').add(newPost)
|
admin
|
||||||
.then((doc) => {
|
.firestore()
|
||||||
doc.update({postId: doc.id})
|
.collection("posts")
|
||||||
const resPost = newPost;
|
.add(newPost)
|
||||||
resPost.postId = doc.id;
|
.then(doc => {
|
||||||
return res.status(200).json(resPost);
|
doc.update({ postId: doc.id });
|
||||||
|
const resPost = newPost;
|
||||||
|
resPost.postId = doc.id;
|
||||||
|
return res.status(200).json(resPost);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something went wrong'});
|
return res.status(500).json({ error: "something went wrong" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
var post_query = admin
|
||||||
|
.firestore()
|
||||||
|
.collection("posts")
|
||||||
|
.where("userHandle", "==", req.user.handle);
|
||||||
|
|
||||||
post_query.get()
|
post_query
|
||||||
|
.get()
|
||||||
.then(function(myPosts) {
|
.then(function(myPosts) {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
myPosts.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
return res
|
||||||
|
.status(200)
|
||||||
|
.json("Successfully retrieved all user's posts from database.");
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json("Failed to retrieve user's posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPosts = (req, res) => {
|
exports.getallPosts = (req, res) => {
|
||||||
var post_query = admin.firestore().collection("posts");
|
let posts = [];
|
||||||
post_query.get()
|
let users = {};
|
||||||
.then(function(allPosts) {
|
|
||||||
let posts = [];
|
// Get all the posts
|
||||||
allPosts.forEach(function(doc) {
|
var postsPromise = new Promise((resolve, reject) => {
|
||||||
posts.push(doc.data());
|
db.collection("posts").get()
|
||||||
|
.then((allPosts) => {
|
||||||
|
allPosts.forEach((post) => {
|
||||||
|
posts.push(post.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get all users
|
||||||
|
var usersPromise = new Promise((resolve, reject) => {
|
||||||
|
db.collection("users").get()
|
||||||
|
.then((allUsers) => {
|
||||||
|
allUsers.forEach((user) => {
|
||||||
|
users[user.data().handle] = user.data();
|
||||||
|
})
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for the two promises
|
||||||
|
Promise.all([postsPromise, usersPromise])
|
||||||
|
.then(() => {
|
||||||
|
let newPosts = []
|
||||||
|
// Add the image url of the person who made the post to all of the post objects
|
||||||
|
posts.forEach((post) => {
|
||||||
|
post.profileImage = users[post.userHandle].imageUrl ? users[post.userHandle].imageUrl : null;
|
||||||
|
newPosts.push(post);
|
||||||
|
});
|
||||||
|
return res.status(200).json(newPosts);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
return res.status(500).json({error});
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getOtherUsersPosts = (req, res) => {
|
||||||
|
var post_query = admin
|
||||||
|
.firestore()
|
||||||
|
.collection("posts")
|
||||||
|
.where("userHandle", "==", req.body.handle);
|
||||||
|
|
||||||
|
post_query
|
||||||
|
.get()
|
||||||
|
.then(function(myPosts) {
|
||||||
|
let posts = [];
|
||||||
|
myPosts.forEach(function(doc) {
|
||||||
|
posts.push(doc.data());
|
||||||
|
});
|
||||||
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return res.status(200).json("Successfully retrieved every post from database.");
|
return res
|
||||||
|
.status(200)
|
||||||
|
.json("Successfully retrieved all user's posts from database.");
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
return res.status(500).json("Failed to retrieve posts from database.", err);
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json("Failed to retrieve user's posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.quoteWithPost = (req, res) => {
|
exports.quoteWithPost = (req, res) => {
|
||||||
|
|
||||||
let quoteData;
|
let quoteData;
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
const quoteDoc = admin.firestore().collection('quote').
|
||||||
where('userHandle', '==', req.user.handle).
|
where('userHandle', '==', req.user.handle).
|
||||||
@ -89,46 +154,50 @@ exports.quoteWithPost = (req, res) => {
|
|||||||
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) {
|
||||||
return admin.firestore().collection('quote').add({
|
return admin
|
||||||
quoteId : req.params.postId,
|
.firestore()
|
||||||
userHandle : req.user.handle,
|
.collection("quote")
|
||||||
quoteBody : req.body.quoteBody
|
.add({
|
||||||
})
|
quoteId: req.params.postId,
|
||||||
.then(() => {
|
userHandle: req.user.handle,
|
||||||
const post = {
|
quoteBody: req.body.quoteBody
|
||||||
body: quoteData.body,
|
})
|
||||||
userHandle : req.user.handle,
|
.then(() => {
|
||||||
quoteBody: req.body.quoteBody,
|
const post = {
|
||||||
createdAt : new Date().toISOString(),
|
body: quoteData.body,
|
||||||
userImage: req.body.userImage,
|
userHandle: req.user.handle,
|
||||||
likeCount: 0,
|
quoteBody: req.body.quoteBody,
|
||||||
commentCount: 0,
|
createdAt: new Date().toISOString(),
|
||||||
userID: req.user.uid,
|
userImage: req.body.userImage,
|
||||||
microBlogTitle: quoteData.microBlogTitle,
|
likeCount: 0,
|
||||||
microBlogTopics: quoteData.microBlogTopics,
|
commentCount: 0,
|
||||||
quoteId: req.params.postId
|
userID: req.user.uid,
|
||||||
}
|
microBlogTitle: quoteData.microBlogTitle,
|
||||||
return admin.firestore().collection('posts').add(post)
|
microBlogTopics: quoteData.microBlogTopics,
|
||||||
.then((doc) => {
|
quoteId: req.params.postId
|
||||||
doc.update({postId: doc.id})
|
};
|
||||||
|
return admin
|
||||||
|
.firestore()
|
||||||
|
.collection("posts")
|
||||||
|
.add(post)
|
||||||
|
.then(doc => {
|
||||||
|
doc.update({ postId: doc.id });
|
||||||
const resPost = post;
|
const resPost = post;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
return res.status(400).json({ error: "Post has already been quoted." });
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return res.status(500).json({error: err});
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
.catch(err => {
|
||||||
|
return res.status(500).json({ error: err });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.quoteWithoutPost = (req, res) => {
|
exports.quoteWithoutPost = (req, res) => {
|
||||||
let quoteData;
|
let quoteData;
|
||||||
@ -149,70 +218,77 @@ exports.quoteWithoutPost = (req, res) => {
|
|||||||
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) {
|
||||||
return admin.firestore().collection('quote').add({
|
return admin
|
||||||
quoteId : req.params.postId,
|
.firestore()
|
||||||
userHandle : req.user.handle,
|
.collection("quote")
|
||||||
quoteBody: null
|
.add({
|
||||||
})
|
quoteId: req.params.postId,
|
||||||
.then(() => {
|
userHandle: req.user.handle,
|
||||||
const post = {
|
quoteBody: null
|
||||||
userHandle : req.user.handle,
|
})
|
||||||
body: quoteData.body,
|
.then(() => {
|
||||||
quoteBody: null,
|
const post = {
|
||||||
createdAt : new Date().toISOString(),
|
userHandle: req.user.handle,
|
||||||
likeCount: 0,
|
body: quoteData.body,
|
||||||
commentCount: 0,
|
quoteBody: null,
|
||||||
userID: req.user.uid,
|
createdAt: new Date().toISOString(),
|
||||||
userImage: req.body.userImage,
|
likeCount: 0,
|
||||||
microBlogTitle: quoteData.microBlogTitle,
|
commentCount: 0,
|
||||||
microBlogTopics: quoteData.microBlogTopics,
|
userID: req.user.uid,
|
||||||
quoteId: req.params.postId
|
userImage: req.body.userImage,
|
||||||
}
|
microBlogTitle: quoteData.microBlogTitle,
|
||||||
return admin.firestore().collection('posts').add(post)
|
microBlogTopics: quoteData.microBlogTopics,
|
||||||
.then((doc) => {
|
quoteId: req.params.postId
|
||||||
doc.update({postId: doc.id})
|
};
|
||||||
|
return admin
|
||||||
|
.firestore()
|
||||||
|
.collection("posts")
|
||||||
|
.add(post)
|
||||||
|
.then(doc => {
|
||||||
|
doc.update({ postId: doc.id });
|
||||||
const resPost = post;
|
const resPost = post;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
})
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return res.status(400).json({ error: "Post has already been quoted." });
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.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 });
|
||||||
})
|
});
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
exports.checkforLikePost = (req, res) => {
|
exports.checkforLikePost = (req, res) => {
|
||||||
const likedPostDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
const likedPostDoc = admin
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
.firestore()
|
||||||
let result;
|
.collection("likes")
|
||||||
|
.where("userHandle", "==", req.user.handle)
|
||||||
|
.where("postId", "==", req.params.postId)
|
||||||
|
.limit(1);
|
||||||
|
let result;
|
||||||
|
|
||||||
likedPostDoc.get()
|
likedPostDoc.get().then(data => {
|
||||||
.then((data) => {
|
if (data.empty) {
|
||||||
if (data.empty) {
|
result = false;
|
||||||
result = false;
|
return res.status(200).json(result);
|
||||||
return res.status(200).json(result);
|
} else {
|
||||||
}
|
result = true;
|
||||||
else
|
return res.status(200).json(result);
|
||||||
{
|
}
|
||||||
result = true;
|
})
|
||||||
return res.status(200).json(result);
|
.catch((err) => {
|
||||||
}
|
console.log(err);
|
||||||
})
|
return res.status(500).json({error: err});
|
||||||
}
|
})
|
||||||
|
};
|
||||||
|
|
||||||
exports.likePost = (req, res) => {
|
exports.likePost = (req, res) => {
|
||||||
|
|
||||||
const postId = req.params.postId;
|
const postId = req.params.postId;
|
||||||
let likedPostDoc;
|
let likedPostDoc;
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
db.doc(`/users/${req.userData.handle}`)
|
||||||
@ -369,6 +445,7 @@ exports.unlikePost = (req, res) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.getLikes = (req, res) => {
|
exports.getLikes = (req, res) => {
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
db.doc(`/users/${req.userData.handle}`)
|
||||||
.get()
|
.get()
|
||||||
@ -386,5 +463,11 @@ exports.getLikes = (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.getFilteredPosts = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
|
||||||
|
admin
|
||||||
|
.firestore()
|
||||||
|
.collection("posts")
|
||||||
|
.where("userHandle", "==", "new user")
|
||||||
|
.where("microBlogTopics", "==");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
/* eslint-disable promise/catch-or-return */
|
/* eslint-disable promise/catch-or-return */
|
||||||
|
/* eslint-disable promise/always-return */
|
||||||
|
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
const config = require("../util/config");
|
const config = require("../util/config");
|
||||||
const { validateUpdateProfileInfo } = require("../util/validator");
|
const { validateUpdateProfileInfo } = require("../util/validator");
|
||||||
@ -209,7 +211,7 @@ exports.deleteUser = (req, res) => {
|
|||||||
let errors = {};
|
let errors = {};
|
||||||
|
|
||||||
function thenFunction(data) {
|
function thenFunction(data) {
|
||||||
console.log(`${data} data for ${req.userData.handle} has been deleted.`);
|
console.log(`${data} for ${req.userData.handle} has been deleted.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchFunction(data, err) {
|
function catchFunction(data, err) {
|
||||||
@ -217,14 +219,131 @@ exports.deleteUser = (req, res) => {
|
|||||||
errors[data] = err;
|
errors[data] = err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteDirectMessages() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const deleteUsername = req.userData.handle;
|
||||||
|
db.doc(`/users/${deleteUsername}`)
|
||||||
|
.get()
|
||||||
|
.then((deleteUserDocSnap) => {
|
||||||
|
const dms = deleteUserDocSnap.data().dms;
|
||||||
|
const dmRecipients = deleteUserDocSnap.data().dmRecipients;
|
||||||
|
|
||||||
|
if (!dms) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over the list of users who this person has DM'd
|
||||||
|
let otherUsersPromises = [];
|
||||||
|
|
||||||
|
// Resolve if they don't have a dmRecipients list
|
||||||
|
if (dmRecipients === undefined || dmRecipients === null || dmRecipients.length === 0) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dmRecipients.forEach((dmRecipient) => {
|
||||||
|
otherUsersPromises.push(
|
||||||
|
// Get each users data
|
||||||
|
db.doc(`/users/${dmRecipient}`).get()
|
||||||
|
.then((otherUserDocSnap) => {
|
||||||
|
// Get the index of deleteUsername so that we can remove the dangling
|
||||||
|
// reference to the DM document
|
||||||
|
let otherUserDMRecipients = otherUserDocSnap.data().dmRecipients;
|
||||||
|
let otherUserDMs = otherUserDocSnap.data().dms;
|
||||||
|
let index = -1;
|
||||||
|
otherUserDMRecipients.forEach((dmRecip, i) => {
|
||||||
|
if (dmRecip === deleteUsername) {
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
// Remove deleteUsername from their dmRecipients list
|
||||||
|
otherUserDMRecipients.splice(index, 1);
|
||||||
|
|
||||||
|
// Remove the DM channel with deleteUsername
|
||||||
|
otherUserDMs.splice(index, 1);
|
||||||
|
|
||||||
|
// Update the users data
|
||||||
|
return otherUserDocSnap.ref.update({
|
||||||
|
dmRecipients: otherUserDMRecipients,
|
||||||
|
dms: otherUserDMs
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Wait for the removal of DM data stored on other users to be deleted
|
||||||
|
Promise.all(otherUsersPromises)
|
||||||
|
.then(() => {
|
||||||
|
// Iterate through DM references and delete them from the dm collection
|
||||||
|
let dmRefsPromises = [];
|
||||||
|
dms.forEach((dmRef) => {
|
||||||
|
// Create a delete queue
|
||||||
|
let batch = db.batch();
|
||||||
|
dmRefsPromises.push(
|
||||||
|
// Add the messages to the delete queue
|
||||||
|
db.collection(`/dm/${dmRef.id}/messages`).listDocuments()
|
||||||
|
.then((docs) => {
|
||||||
|
console.log("second")
|
||||||
|
console.log(docs);
|
||||||
|
docs.map((doc) => {
|
||||||
|
batch.delete(doc);
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add the doc that the DM is stored in to the delete queue
|
||||||
|
batch.delete(dmRef);
|
||||||
|
|
||||||
|
// Commit the writes
|
||||||
|
return batch.commit();
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return Promise.all(dmRefsPromises);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log("error " + err);
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return res.status(500).json({error: err});
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Deletes user from authentication
|
// Deletes user from authentication
|
||||||
let auth = admin.auth().deleteUser(userId);
|
let auth = admin.auth().deleteUser(userId);
|
||||||
|
|
||||||
// Deletes database data
|
// Deletes database data
|
||||||
let data = db
|
let data = new Promise((resolve, reject) => {
|
||||||
.collection("users")
|
deleteDirectMessages()
|
||||||
.doc(`${req.user.handle}`)
|
.then(() => {
|
||||||
.delete();
|
return db
|
||||||
|
.collection("users")
|
||||||
|
.doc(`${req.user.handle}`)
|
||||||
|
.delete()
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Deletes any custom profile image
|
// Deletes any custom profile image
|
||||||
let image;
|
let image;
|
||||||
@ -298,7 +417,7 @@ exports.updateProfileInfo = (req, res) => {
|
|||||||
// Update the database entry for this user
|
// Update the database entry for this user
|
||||||
db.collection("users")
|
db.collection("users")
|
||||||
.doc(req.user.handle)
|
.doc(req.user.handle)
|
||||||
.set(profileData, { merge: true })
|
.set(profileData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`${req.user.handle}'s profile info has been updated.`);
|
console.log(`${req.user.handle}'s profile info has been updated.`);
|
||||||
return res.status(201).json({
|
return res.status(201).json({
|
||||||
@ -331,6 +450,25 @@ exports.getUserDetails = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getAllHandles = (req, res) => {
|
||||||
|
var user_query = admin.firestore().collection("users");
|
||||||
|
user_query.get()
|
||||||
|
.then((allUsers) => {
|
||||||
|
let users = [];
|
||||||
|
allUsers.forEach((user) => {
|
||||||
|
users.push(user.data().handle);
|
||||||
|
});
|
||||||
|
return res.status(200).json(users);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
return res.status(500).json({
|
||||||
|
message:"Failed to retrieve posts from database.",
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns all data stored for a user
|
||||||
exports.getAuthenticatedUser = (req, res) => {
|
exports.getAuthenticatedUser = (req, res) => {
|
||||||
let credentials = {};
|
let credentials = {};
|
||||||
db.doc(`/users/${req.user.handle}`)
|
db.doc(`/users/${req.user.handle}`)
|
||||||
@ -466,6 +604,126 @@ exports.getSubs = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Uploads a profile image
|
||||||
|
exports.uploadProfileImage = (req, res) => {
|
||||||
|
const BusBoy = require("busboy");
|
||||||
|
const path = require("path");
|
||||||
|
const os = require("os");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const busboy = new BusBoy({ headers: req.headers });
|
||||||
|
|
||||||
|
let imageFileName;
|
||||||
|
let imageToBeUploaded = {};
|
||||||
|
let oldImageFileName = req.userData.imageUrl ? req.userData.imageUrl.split("/o/")[1].split("?alt")[0] : null;
|
||||||
|
// console.log(`old file: ${oldImageFileName}`);
|
||||||
|
|
||||||
|
busboy.on("file", (fieldname, file, filename, encoding, mimetype) => {
|
||||||
|
if (mimetype !== 'image/jpeg' && mimetype !== 'image/png') {
|
||||||
|
return res.status(400).json({ error: "Wrong filetype submitted" });
|
||||||
|
}
|
||||||
|
// console.log(fieldname);
|
||||||
|
// console.log(filename);
|
||||||
|
// console.log(mimetype);
|
||||||
|
const imageExtension = filename.split(".")[filename.split(".").length - 1]; // Get the image file extension
|
||||||
|
imageFileName = `${Math.round(Math.random() * 100000000000)}.${imageExtension}`; // Get a random filename
|
||||||
|
const filepath = path.join(os.tmpdir(), imageFileName);
|
||||||
|
imageToBeUploaded = { filepath, mimetype };
|
||||||
|
file.pipe(fs.createWriteStream(filepath));
|
||||||
|
});
|
||||||
|
busboy.on("finish", () => {
|
||||||
|
// Save the file to the storage bucket
|
||||||
|
admin.storage().bucket(config.storageBucket).upload(imageToBeUploaded.filepath, {
|
||||||
|
resumable: false,
|
||||||
|
metadata: {
|
||||||
|
metadata: {
|
||||||
|
contentType: imageToBeUploaded.mimetype
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Add the new URL to the user's profile
|
||||||
|
const imageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`;
|
||||||
|
return db.doc(`/users/${req.user.handle}`).update({ imageUrl });
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// Delete their old image if they have one
|
||||||
|
if (oldImageFileName !== null && oldImageFileName !== "no-img.png") {
|
||||||
|
admin.storage().bucket(config.storageBucket).file(oldImageFileName).delete()
|
||||||
|
.then(() => {
|
||||||
|
return res.status(201).json({ message: "Image uploaded successfully1"});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return res.status(201).json({ message: "Image uploaded successfully2"});
|
||||||
|
})
|
||||||
|
// return res.status(201).json({ message: "Image uploaded successfully"});
|
||||||
|
} else {
|
||||||
|
return res.status(201).json({ message: "Image uploaded successfully3"});
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: err.code})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
busboy.end(req.rawBody);
|
||||||
|
|
||||||
|
// const BusBoy = require('busboy');
|
||||||
|
// const path = require('path');
|
||||||
|
// const os = require('os');
|
||||||
|
// const fs = require('fs');
|
||||||
|
|
||||||
|
// const busboy = new BusBoy({ headers: req.headers });
|
||||||
|
|
||||||
|
// let imageToBeUploaded = {};
|
||||||
|
// let imageFileName;
|
||||||
|
|
||||||
|
// busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
|
||||||
|
// // console.log(fieldname, file, filename, encoding, mimetype);
|
||||||
|
// if (mimetype !== 'image/jpeg' && mimetype !== 'image/png') {
|
||||||
|
// return res.status(400).json({ error: 'Wrong file type submitted' });
|
||||||
|
// }
|
||||||
|
// // my.image.png => ['my', 'image', 'png']
|
||||||
|
// const imageExtension = filename.split('.')[filename.split('.').length - 1];
|
||||||
|
// // 32756238461724837.png
|
||||||
|
// imageFileName = `${Math.round(
|
||||||
|
// Math.random() * 1000000000000
|
||||||
|
// ).toString()}.${imageExtension}`;
|
||||||
|
// const filepath = path.join(os.tmpdir(), imageFileName);
|
||||||
|
// imageToBeUploaded = { filepath, mimetype };
|
||||||
|
// file.pipe(fs.createWriteStream(filepath));
|
||||||
|
// });
|
||||||
|
// busboy.on('finish', () => {
|
||||||
|
// admin
|
||||||
|
// .storage()
|
||||||
|
// .bucket(config.storageBucket)
|
||||||
|
// .upload(imageToBeUploaded.filepath, {
|
||||||
|
// resumable: false,
|
||||||
|
// metadata: {
|
||||||
|
// metadata: {
|
||||||
|
// contentType: imageToBeUploaded.mimetype
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .then(() => {
|
||||||
|
// const imageUrl = `https://firebasestorage.googleapis.com/v0/b/${
|
||||||
|
// config.storageBucket
|
||||||
|
// }/o/${imageFileName}?alt=media`;
|
||||||
|
// return db.doc(`/users/${req.user.handle}`).update({ imageUrl });
|
||||||
|
// })
|
||||||
|
// .then(() => {
|
||||||
|
// return res.json({ message: 'image uploaded successfully' });
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// console.error(err);
|
||||||
|
// return res.status(500).json({ error: 'something went wrong' });
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// busboy.end(req.rawBody);
|
||||||
|
}
|
||||||
|
|
||||||
exports.removeSub = (req, res) => {
|
exports.removeSub = (req, res) => {
|
||||||
let new_following = [];
|
let new_following = [];
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
let userRef = db.doc(`/users/${req.userData.handle}`);
|
||||||
@ -489,6 +747,7 @@ exports.removeSub = (req, res) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({ message: "ok" });
|
return res.status(200).json({ message: "ok" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,12 +11,14 @@ app.use(cors());
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const {
|
||||||
getAuthenticatedUser,
|
getAuthenticatedUser,
|
||||||
|
getAllHandles,
|
||||||
getUserDetails,
|
getUserDetails,
|
||||||
getProfileInfo,
|
getProfileInfo,
|
||||||
login,
|
login,
|
||||||
signup,
|
signup,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
updateProfileInfo,
|
updateProfileInfo,
|
||||||
|
uploadProfileImage,
|
||||||
verifyUser,
|
verifyUser,
|
||||||
unverifyUser,
|
unverifyUser,
|
||||||
getUserHandles,
|
getUserHandles,
|
||||||
@ -39,14 +41,23 @@ app.delete("/delete", fbAuth, deleteUser);
|
|||||||
|
|
||||||
app.post("/getUserDetails", fbAuth, getUserDetails);
|
app.post("/getUserDetails", fbAuth, getUserDetails);
|
||||||
|
|
||||||
|
// Returns a list of all usernames
|
||||||
|
// Used for searching
|
||||||
|
app.get("/getAllHandles", fbAuth, getAllHandles);
|
||||||
|
|
||||||
// Returns all profile data of the currently logged in user
|
// Returns all profile data of the currently logged in user
|
||||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||||
|
|
||||||
// Updates the currently logged in user's profile information
|
// Updates the currently logged in user's profile information
|
||||||
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
||||||
|
|
||||||
|
// Returns all user data for the logged in user.
|
||||||
|
// Used when setting the state in Redux.
|
||||||
app.get("/user", fbAuth, getAuthenticatedUser);
|
app.get("/user", fbAuth, getAuthenticatedUser);
|
||||||
|
|
||||||
|
// Uploads a profile image
|
||||||
|
app.post("/user/image", fbAuth, uploadProfileImage);
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
// Verifies the user sent to the request
|
||||||
// Must be run by the Admin user
|
// Must be run by the Admin user
|
||||||
app.post("/verifyUser", fbAuth, verifyUser);
|
app.post("/verifyUser", fbAuth, verifyUser);
|
||||||
@ -70,8 +81,10 @@ app.post("/removeSub", fbAuth, removeSub);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
|
||||||
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, getLikes, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
|
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, getLikes, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
|
||||||
|
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
app.get("/getallPosts", getallPosts);
|
app.get("/getallPosts", getallPosts);
|
||||||
@ -87,7 +100,7 @@ app.get("/checkforLikePost/:postId", fbAuth, checkforLikePost);
|
|||||||
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
||||||
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
||||||
|
|
||||||
|
app.post("/getOtherUsersPosts", fbAuth, getOtherUsersPosts);
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
|
"busboy": "^0.3.1",
|
||||||
"firebase": "^6.6.2",
|
"firebase": "^6.6.2",
|
||||||
"firebase-admin": "^8.6.0",
|
"firebase-admin": "^8.6.0",
|
||||||
"firebase-functions": "^3.1.0",
|
"firebase-functions": "^3.1.0",
|
||||||
|
|||||||
@ -4,12 +4,12 @@ const { admin, db } = require('./admin');
|
|||||||
// The function will only execute if the user is logged in, or rather, they have
|
// The function will only execute if the user is logged in, or rather, they have
|
||||||
// a valid token
|
// a valid token
|
||||||
module.exports = (req, res, next) => {
|
module.exports = (req, res, next) => {
|
||||||
console.log(req);
|
// console.log(req);
|
||||||
console.log(req.body);
|
// console.log(req.body);
|
||||||
console.log(req.headers);
|
// console.log(req.headers);
|
||||||
console.log(req.headers.authorization);
|
// console.log(req.headers.authorization);
|
||||||
console.log(JSON.stringify(req.body));
|
// console.log(JSON.stringify(req.body));
|
||||||
console.log(JSON.stringify(req.header));
|
// console.log(JSON.stringify(req.header));
|
||||||
|
|
||||||
let idToken;
|
let idToken;
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
"clsx": "^1.0.4",
|
"clsx": "^1.0.4",
|
||||||
"create-react-app": "^3.1.2",
|
"create-react-app": "^3.1.2",
|
||||||
|
"fuse.js": "^3.4.6",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"jwt-decode": "^2.2.0",
|
"jwt-decode": "^2.2.0",
|
||||||
"node-pre-gyp": "^0.13.0",
|
"node-pre-gyp": "^0.13.0",
|
||||||
@ -42,5 +43,5 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class App extends Component {
|
|||||||
|
|
||||||
<Route exact path="/home" component={home} />
|
<Route exact path="/home" component={home} />
|
||||||
<Route exact path="/user" component={user} />
|
<Route exact path="/user" component={user} />
|
||||||
<Route exact path="/edit" component={editProfile} />
|
<Route exact path="/user/edit" component={editProfile} />
|
||||||
<Route exact path="/verify" component={verify} />
|
<Route exact path="/verify" component={verify} />
|
||||||
<Route exact path="/search" component={Search} />
|
<Route exact path="/search" component={Search} />
|
||||||
<Route exact path="/user/:userhandle" component={otherUser} />
|
<Route exact path="/user/:userhandle" component={otherUser} />
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
// import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import Route from 'react-router-dom/Route';
|
// import Route from 'react-router-dom/Route';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import Box from '@material-ui/core/Box'
|
import Box from '@material-ui/core/Box'
|
||||||
import {borders} from '@material-ui/system';
|
// import {borders} from '@material-ui/system';
|
||||||
import { sizing } from '@material-ui/system';
|
// import { sizing } from '@material-ui/system';
|
||||||
// var moment = require('moment');
|
// var moment = require('moment');
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class Userline extends Component {
|
|||||||
<div style={{fontsize: "13px", textAlign: "left", marginLeft: "14px"}}>
|
<div style={{fontsize: "13px", textAlign: "left", marginLeft: "14px"}}>
|
||||||
<p>Userline</p>
|
<p>Userline</p>
|
||||||
</div>
|
</div>
|
||||||
<Box border={1} width="25%" flex="1" height="auto" m={2} fontSize="13px" textAlign= "left" padding="5px" flexWrap= "wrap" flexDirection= "row" >
|
<Box border={1} width="25%" flex="1" height="auto" m={2} fontSize="13px" textAlign="left" padding="5px" flexWrap="wrap" flexDirection="row" >
|
||||||
<div style={{flexWrap: "wrap", flex: "1", flexDirection: "row", wordBreak: "break-word"}}>
|
<div style={{flexWrap: "wrap", flex: "1", flexDirection: "row", wordBreak: "break-word"}}>
|
||||||
<p>
|
<p>
|
||||||
{sortedPosts.map((microBlog) => <p>Microblog Title: {microBlog.microBlogTitle}
|
{sortedPosts.map((microBlog) => <p>Microblog Title: {microBlog.microBlogTitle}
|
||||||
@ -50,7 +50,7 @@ class Userline extends Component {
|
|||||||
<br></br>Number of comments: {microBlog.commentCount}
|
<br></br>Number of comments: {microBlog.commentCount}
|
||||||
<br></br>Number of likes: {microBlog.likeCount}
|
<br></br>Number of likes: {microBlog.likeCount}
|
||||||
<br></br>Body of post: {microBlog.body}
|
<br></br>Body of post: {microBlog.body}
|
||||||
<br></br>Tagged topics: {microBlog.microBlogTopics.join("," + " ")}
|
<br></br>Tagged topics: {microBlog.microBlogTopics.join(", ")}
|
||||||
</p>)}
|
</p>)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,8 +1,29 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
// import { BrowserRouter as Router } from "react-router-dom";
|
||||||
import Route from "react-router-dom/Route";
|
// import Route from "react-router-dom/Route";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
|
// Material-UI
|
||||||
|
import TextField from '@material-ui/core/TextField';
|
||||||
|
// import Typography from '@material-ui/core/Typography';
|
||||||
|
import Button from '@material-ui/core/Button';
|
||||||
|
import withStyles from "@material-ui/styles/withStyles";
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
container: {
|
||||||
|
position: "fixed"
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
width: "300px",
|
||||||
|
height: "50px",
|
||||||
|
marginTop: "180px",
|
||||||
|
marginLeft: "50px"
|
||||||
|
},
|
||||||
|
textField: {
|
||||||
|
marginBottom: 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Writing_Microblogs extends Component {
|
class Writing_Microblogs extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -27,7 +48,7 @@ class Writing_Microblogs extends Component {
|
|||||||
this.setState({ topics: event.target.value });
|
this.setState({ topics: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit = (event) => {
|
||||||
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||||
const postData = {
|
const postData = {
|
||||||
body: this.state.value,
|
body: this.state.value,
|
||||||
@ -40,20 +61,34 @@ class Writing_Microblogs extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post("/putPost", postData, headers)
|
.post("/putPost", postData, headers) // TODO: add topics
|
||||||
.then(res => {
|
.then(res => {
|
||||||
alert("Post was shared successfully!");
|
// alert("Post was shared successfully!");
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
alert("An error occured.");
|
alert("An error occured.");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
console.log(postData.microBlogTopics);
|
||||||
|
postData.microBlogTopics.forEach(topic => {
|
||||||
|
axios
|
||||||
|
.post("/putTopic", {
|
||||||
|
following: topic
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
handleChangeforPost(event) {
|
||||||
|
|
||||||
this.setState({ value: event.target.value });
|
this.setState({ value: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,65 +99,67 @@ class Writing_Microblogs extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { classes } = this.props;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={classes.container}>
|
||||||
<div
|
<form noValidate className={classes.form}>
|
||||||
style={{
|
<TextField
|
||||||
width: "200px",
|
id="title"
|
||||||
height: "50px",
|
name="title"
|
||||||
marginTop: "180px",
|
label="Title"
|
||||||
marginLeft: "50px"
|
className={classes.textField}
|
||||||
}}
|
value={this.state.title}
|
||||||
>
|
variant="outlined"
|
||||||
<form>
|
onChange={this.handleChange}
|
||||||
<textarea
|
fullWidth
|
||||||
placeholder="Enter Microblog Title"
|
autoComplete='off'
|
||||||
value={this.state.title}
|
/>
|
||||||
required
|
|
||||||
onChange={this.handleChange}
|
|
||||||
cols={30}
|
|
||||||
rows={1}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
|
|
||||||
<form>
|
|
||||||
<textarea
|
|
||||||
placeholder="Enter topics seperated by a comma"
|
|
||||||
value={this.state.topics}
|
|
||||||
required
|
|
||||||
onChange={this.handleChangeforTopics}
|
|
||||||
cols={40}
|
|
||||||
rows={1}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ width: "200px", marginLeft: "50px" }}>
|
<TextField
|
||||||
<form onSubmit={this.handleSubmit}>
|
id="topics"
|
||||||
<textarea
|
name="topics"
|
||||||
value={this.state.value}
|
label="Topics"
|
||||||
required
|
className={classes.textField}
|
||||||
maxLength="250"
|
value={this.state.topics}
|
||||||
placeholder="Write Microblog here..."
|
variant="outlined"
|
||||||
onChange={e => {
|
onChange={this.handleChangeforTopics}
|
||||||
this.handleChangeforPost(e);
|
color="primary"
|
||||||
this.handleChangeforCharacterCount(e);
|
fullWidth
|
||||||
}}
|
autoComplete='off'
|
||||||
cols={40}
|
/>
|
||||||
rows={20}
|
<TextField
|
||||||
/>
|
id="content"
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
name="content"
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
label="Content"
|
||||||
</div>
|
color="primary"
|
||||||
<div style={{ marginRight: "-100px" }}>
|
className={classes.textField}
|
||||||
<button onClick>Share Post</button>
|
value={this.state.value}
|
||||||
</div>
|
helperText={`${this.state.characterCount} characters left`}
|
||||||
</form>
|
multiline
|
||||||
</div>
|
rows="9"
|
||||||
|
variant="outlined"
|
||||||
|
inputProps={{
|
||||||
|
maxLength: 250
|
||||||
|
}}
|
||||||
|
onChange={(e) => {
|
||||||
|
this.handleChangeforPost(e);
|
||||||
|
this.handleChangeforCharacterCount(e);
|
||||||
|
}}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={this.handleSubmit}
|
||||||
|
// disabled={loading}
|
||||||
|
variant="outlined"
|
||||||
|
color="primary"
|
||||||
|
>
|
||||||
|
Share Post
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Writing_Microblogs;
|
export default withStyles(styles)(Writing_Microblogs);
|
||||||
|
|||||||
@ -1,16 +1,20 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from "react";
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from "prop-types";
|
||||||
import { connect } from 'react-redux';
|
import { connect } from "react-redux";
|
||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
|
|
||||||
// Material UI and React Router
|
// Material UI and React Router
|
||||||
|
|
||||||
|
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from '@material-ui/core/Button';
|
||||||
import Card from '@material-ui/core/Card';
|
import Grid from "@material-ui/core/Grid";
|
||||||
import CardContent from '@material-ui/core/CardContent';
|
import Card from "@material-ui/core/Card";
|
||||||
import Grid from '@material-ui/core/Grid';
|
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';
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
@ -23,6 +27,12 @@ import ReactModal from 'react-modal';
|
|||||||
import { likePost, unlikePost, getLikes } from '../redux/actions/userActions';
|
import { likePost, unlikePost, getLikes } from '../redux/actions/userActions';
|
||||||
|
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
card: {
|
||||||
|
marginBottom: 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
state = {
|
state = {
|
||||||
likes: []
|
likes: []
|
||||||
@ -33,10 +43,10 @@ class Home extends Component {
|
|||||||
axios
|
axios
|
||||||
.get("/getallPosts")
|
.get("/getallPosts")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res.data);
|
// console.log(res.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
posts: res.data
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
@ -69,23 +79,34 @@ class Home extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatDate(dateString) {
|
||||||
|
let newDate = new Date(Date.parse(dateString));
|
||||||
|
return newDate.toDateString();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
|
const { UI:{ loading } } = this.props;
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
|
let {classes} = this.props;
|
||||||
let username = this.props.user.credentials.handle;
|
let username = this.props.user.credentials.handle;
|
||||||
const {UI: { loading }} = this.props;
|
|
||||||
let postMarkup = this.state.posts ? (
|
let postMarkup = this.state.posts ? (
|
||||||
this.state.posts.map(post =>
|
this.state.posts.map(post =>
|
||||||
<Card>
|
<Card className={classes.card} key={post.postId}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography>
|
<Typography>
|
||||||
{
|
{/* {
|
||||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
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" />) :
|
||||||
|
(<img src={noImage} height="50" width="50"/>)
|
||||||
}
|
}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||||
@ -112,11 +133,13 @@ class Home extends Component {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
) : (<p>My Posts</p>);
|
) : (
|
||||||
|
<p>Loading post...</p>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
authenticated ?
|
authenticated ? (
|
||||||
<Grid container spacing={16}>
|
<Grid container>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
<Writing_Microblogs />
|
<Writing_Microblogs />
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -124,35 +147,37 @@ class Home extends Component {
|
|||||||
{postMarkup}
|
{postMarkup}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
:
|
) : loading ?
|
||||||
<div>
|
(<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>)
|
||||||
<div>
|
:
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
(
|
||||||
<br/><br/>
|
<div>
|
||||||
<b>Welcome to Twistter!</b>
|
<div>
|
||||||
<br/><br/>
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<b>See the most interesting topics people are following right now.</b>
|
<br/><br/>
|
||||||
</div>
|
<b>Welcome to Twistter!</b>
|
||||||
|
<br/><br/>
|
||||||
|
<b>See the most interesting topics people are following right now.</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
<br/><br/><br/><br/>
|
<br/><br/><br/><br/>
|
||||||
|
|
||||||
<div>
|
<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>
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Quote extends Component {
|
class Quote extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -386,6 +411,7 @@ const mapStateToProps = (state) => ({
|
|||||||
UI: state.UI
|
UI: state.UI
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const mapActionsToProps = {
|
const mapActionsToProps = {
|
||||||
likePost,
|
likePost,
|
||||||
unlikePost,
|
unlikePost,
|
||||||
@ -396,7 +422,9 @@ Home.propTypes = {
|
|||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
likePost: PropTypes.func.isRequired,
|
likePost: PropTypes.func.isRequired,
|
||||||
unlikePost: PropTypes.func.isRequired,
|
unlikePost: PropTypes.func.isRequired,
|
||||||
getLikes: PropTypes.func.isRequired
|
getLikes: PropTypes.func.isRequired,
|
||||||
|
classes: PropTypes.object.isRequired,
|
||||||
|
UI: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
Like.propTypes = {
|
Like.propTypes = {
|
||||||
@ -407,4 +435,6 @@ Quote.propTypes = {
|
|||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapActionsToProps)(Home, Like, Quote);
|
export default connect(mapStateToProps, mapActionsToProps)(Home, Like, Quote);
|
||||||
|
|
||||||
|
|||||||
@ -110,7 +110,7 @@ export class Login extends Component {
|
|||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br></br>
|
<br></br>
|
||||||
<Typography variant="p" className={classes.pageTitle} fontFamily = "Georgia, serif">
|
<Typography variant="h6" className={classes.pageTitle} fontFamily = "Georgia, serif">
|
||||||
<b>Log in to Twistter</b>
|
<b>Log in to Twistter</b>
|
||||||
<br></br>
|
<br></br>
|
||||||
</Typography>
|
</Typography>
|
||||||
@ -119,7 +119,7 @@ export class Login extends Component {
|
|||||||
<TextField
|
<TextField
|
||||||
id="email"
|
id="email"
|
||||||
name="email"
|
name="email"
|
||||||
label="Email*"
|
label="Email or Username*"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.email}
|
value={this.state.email}
|
||||||
helperText={errors.email}
|
helperText={errors.email}
|
||||||
@ -127,6 +127,7 @@ export class Login extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="password"
|
id="password"
|
||||||
@ -140,6 +141,7 @@ export class Login extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
@ -1,39 +1,77 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
// import props
|
// import props
|
||||||
import { TextField, Button } from "@material-ui/core";
|
// import { TextField, Button } from "@material-ui/core";
|
||||||
|
import TextField from "@material-ui/core/TextField"
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import Axios from "axios";
|
import axios from "axios";
|
||||||
|
import Fuse from "fuse.js";
|
||||||
|
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
import { BrowserRouter as Router } from "react-router-dom";
|
||||||
|
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
|
||||||
|
const fuseOptions = {
|
||||||
|
shouldSort: true,
|
||||||
|
threshold: 0.6,
|
||||||
|
location: 0,
|
||||||
|
distance: 100,
|
||||||
|
maxPatternLength: 32,
|
||||||
|
minMatchCharLength: 1,
|
||||||
|
keys: []
|
||||||
|
};
|
||||||
|
|
||||||
|
let fuse;
|
||||||
|
|
||||||
|
|
||||||
export class Search extends Component {
|
export class Search extends Component {
|
||||||
state = {
|
state = {
|
||||||
searchPhase: null,
|
handles: [],
|
||||||
searchResult: null
|
// searchPhrase: null,
|
||||||
|
searchResult: null,
|
||||||
|
loading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSearch = () => {
|
componentDidMount() {
|
||||||
console.log(this.state.searchPhase);
|
this.setState({loading: true});
|
||||||
Axios.post("/getUserHandles", {
|
axios.get("/getAllHandles")
|
||||||
userHandle: this.state.searchPhase
|
.then((res) => {
|
||||||
})
|
this.setState({
|
||||||
.then(res => {
|
handles: res.data,
|
||||||
console.log(res);
|
loading: false
|
||||||
|
}, () => {
|
||||||
this.setState({
|
// console.log(res.data);
|
||||||
searchResult: res.data
|
fuse = new Fuse(this.state.handles, fuseOptions); // "list" is the item array
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
})
|
||||||
console.log(err);
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
handleInput(event) {
|
// handleSearch = () => {
|
||||||
|
// console.log(this.state.searchPhase);
|
||||||
|
// axios.post("/getUserHandles", {
|
||||||
|
// userHandle: this.state.searchPhase
|
||||||
|
// })
|
||||||
|
// .then(res => {
|
||||||
|
// console.log(res);
|
||||||
|
|
||||||
|
// this.setState({
|
||||||
|
// searchResult: res.data
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
// .catch(err => {
|
||||||
|
// console.log(err);
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
handleChange = (event) => {
|
||||||
|
let result = fuse.search(event.target.value);
|
||||||
|
let parsed = [];
|
||||||
|
result.forEach((res) => {
|
||||||
|
// console.log(res)
|
||||||
|
parsed.push(this.state.handles[res])
|
||||||
|
})
|
||||||
this.setState({
|
this.setState({
|
||||||
searchPhase: event.target.value
|
searchResult: parsed.length !== 0 ? parsed : "No Results"
|
||||||
});
|
})
|
||||||
console.log(this.state.searchPhase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRedirect() {
|
handleRedirect() {
|
||||||
@ -41,39 +79,50 @@ export class Search extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let resultMarkup = this.state.searchResult ? (
|
let resultMarkup = this.state.searchResult && this.state.searchResult !== "No Results" ? (
|
||||||
<Router>
|
this.state.searchResult.map(res =>
|
||||||
<div>
|
<Router key={res}>
|
||||||
<a href={`/user/${this.state.searchResult}`}>
|
<div>
|
||||||
{this.state.searchResult}
|
<a href={`/user/${res}`}>
|
||||||
</a>
|
{res}
|
||||||
</div>
|
</a>
|
||||||
</Router>
|
</div>
|
||||||
) : (
|
</Router>
|
||||||
// console.log(this.state.searchResult)
|
)
|
||||||
<p> No result </p>
|
)
|
||||||
);
|
:
|
||||||
|
this.state.searchResult === "No Results" ?
|
||||||
|
(
|
||||||
|
<p> No results </p>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
(
|
||||||
|
null
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid>
|
|
||||||
<Grid>
|
|
||||||
<TextField
|
|
||||||
id="standard-required"
|
|
||||||
label="Username"
|
|
||||||
// defaultValue="username"
|
|
||||||
|
|
||||||
margin="normal"
|
this.state.loading
|
||||||
value={this.state.searchPhase}
|
?
|
||||||
onChange={event => this.handleInput(event)}
|
<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>
|
||||||
/>
|
:
|
||||||
</Grid>
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Button color="primary" onClick={this.handleSearch}>
|
<Grid>
|
||||||
Search
|
<TextField
|
||||||
</Button>
|
id="standard-required"
|
||||||
|
label="Username"
|
||||||
|
margin="normal"
|
||||||
|
// value={this.state.searchPhrase}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid>
|
||||||
|
{/* <Button color="primary" onClick={this.handleSearch}>
|
||||||
|
Search
|
||||||
|
</Button> */}
|
||||||
|
</Grid>
|
||||||
|
<Grid>{resultMarkup}</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid>{resultMarkup}</Grid>
|
|
||||||
</Grid>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,6 +122,7 @@ export class Signup extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="email"
|
id="email"
|
||||||
@ -134,6 +135,7 @@ export class Signup extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="password"
|
id="password"
|
||||||
@ -147,6 +149,7 @@ export class Signup extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="confirmPassword"
|
id="confirmPassword"
|
||||||
@ -160,6 +163,7 @@ export class Signup extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<br></br>
|
<br></br>
|
||||||
<br></br>
|
<br></br>
|
||||||
|
|||||||
@ -1,17 +1,26 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
// TODO: Add a read-only '@' in the left side of the handle input
|
|
||||||
// TODO: Add a cancel button, that takes the user back to their profile page
|
import noImage from '../images/no-img.png';
|
||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
|
import Box from "@material-ui/core/Box"
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
|
import Popover from "@material-ui/core/Popover";
|
||||||
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/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
|
import EditIcon from "@material-ui/icons/Edit";
|
||||||
|
import Tooltip from "@material-ui/core/Tooltip";
|
||||||
|
|
||||||
|
// Redux stuff
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { uploadImage } from "../redux/actions/userActions";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
@ -28,34 +37,76 @@ const styles = {
|
|||||||
positon: "relative",
|
positon: "relative",
|
||||||
marginBottom: 30
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
|
box: {
|
||||||
|
position: "relative"
|
||||||
|
},
|
||||||
|
back: {
|
||||||
|
float: "left",
|
||||||
|
marginLeft: 15
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
float: "right",
|
||||||
|
marginRight: 15
|
||||||
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
|
},
|
||||||
|
uploadProgress: {
|
||||||
|
position: "absolute",
|
||||||
|
marginLeft: -155,
|
||||||
|
marginTop: 95
|
||||||
|
},
|
||||||
|
popoverBackground: {
|
||||||
|
marginTop: "-100px",
|
||||||
|
width: "calc(100vw)",
|
||||||
|
height: 'calc(100vh + 100px)',
|
||||||
|
backgroundColor: "gray",
|
||||||
|
position: "absolute",
|
||||||
|
opacity: "70%"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export class edit extends Component {
|
export class editProfile extends Component {
|
||||||
|
// mapReduxToState = (credentials) => {
|
||||||
|
// this.setState({
|
||||||
|
// imageUrl: credentials.imageUrl ? credentials.imageUrl : noImage,
|
||||||
|
// firstName: credentials.firstName ? credentials.firstName : '',
|
||||||
|
// lastName: credentials.lastName ? credentials.lastName : '',
|
||||||
|
// email: credentials.email ? credentials.email : 'error, email doesn\'t exist',
|
||||||
|
// handle: credentials.handle ? credentials.handle : 'error, handle doesn\'t exist',
|
||||||
|
// bio: credentials.bio ? credentials.bio : ''
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
// Runs as soon as the page loads.
|
// Runs as soon as the page loads.
|
||||||
// Sets the default values of all the textboxes to the data
|
// Sets the default values of all the textboxes to the data
|
||||||
// that is stored in the database for the user.
|
// that is stored in the database for the user.
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
// const { credentials } = this.props;
|
||||||
|
// console.log(this.props.user);
|
||||||
|
// this.mapReduxToState(credentials);
|
||||||
|
this.setState({pageLoading: true})
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/getProfileInfo")
|
.get("/getProfileInfo")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
// Need to have the ternary if statements, because react throws an error if
|
||||||
|
// any of the res.data keys are undefined
|
||||||
this.setState({
|
this.setState({
|
||||||
firstName: res.data.firstName,
|
imageUrl: res.data.imageUrl,
|
||||||
lastName: res.data.lastName,
|
firstName: res.data.firstName ? res.data.firstName : "",
|
||||||
|
lastName: res.data.lastName ? res.data.lastName : "",
|
||||||
email: res.data.email,
|
email: res.data.email,
|
||||||
handle: res.data.handle,
|
handle: res.data.handle,
|
||||||
bio: res.data.bio
|
bio: res.data.bio ? res.data.bio : "",
|
||||||
|
pageLoading: false
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.response.status === 403) {
|
if (err.response.status === 403) {
|
||||||
alert("You are not logged in");
|
// This user is not logged in
|
||||||
// TODO: Redirect them, to the profile they are trying to edit
|
this.props.history.push('/');
|
||||||
// If they are on /itsjimmy/edit, they will be redirected to /itsjimmy
|
|
||||||
this.props.history.push('../');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -64,12 +115,15 @@ export class edit extends Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
|
imageUrl: "",
|
||||||
firstName: "",
|
firstName: "",
|
||||||
lastName: "",
|
lastName: "",
|
||||||
email: "",
|
email: "",
|
||||||
handle: "",
|
handle: "",
|
||||||
bio: "",
|
bio: "",
|
||||||
|
anchorEl: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
pageLoading: false,
|
||||||
errors: {}
|
errors: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -104,11 +158,11 @@ export class edit extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
// this.props.history.push('/');
|
this.props.history.push('/user');
|
||||||
// TODO: Need to redirect user to their profile page
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
// TODO: Should redirect to login page if they get a 403
|
||||||
this.setState({
|
this.setState({
|
||||||
errors: err.response.data,
|
errors: err.response.data,
|
||||||
loading: false
|
loading: false
|
||||||
@ -129,136 +183,288 @@ export class edit extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleImageChange = (event) => {
|
||||||
|
if (event.target.files[0]) {
|
||||||
|
const image = event.target.files[0];
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('image', image, image.name);
|
||||||
|
this.props.uploadImage(formData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEditPicture = () => {
|
||||||
|
const fileInput = document.getElementById('imageUpload');
|
||||||
|
fileInput.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// logging = () => {
|
||||||
|
// console.log(this.state);
|
||||||
|
// console.log(this.props);
|
||||||
|
// this.mapReduxToState(this.props.credentials);
|
||||||
|
// }
|
||||||
|
|
||||||
|
handleOpenConfirmDelete = (event) => {
|
||||||
|
this.setState({
|
||||||
|
// anchorEl: event.currentTarget
|
||||||
|
anchorEl: document.getElementById("container-grid")
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleCloseConfirmDelete = () => {
|
||||||
|
this.setState({
|
||||||
|
anchorEl: null,
|
||||||
|
createDMUsername: ''
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const { classes } = this.props;
|
||||||
|
const uploading = this.props.UI.loading;
|
||||||
const { errors, loading } = this.state;
|
const { errors, loading } = this.state;
|
||||||
|
|
||||||
|
// <<<<<<< edit-profile-image-upload
|
||||||
|
|
||||||
|
let imageMarkup = this.props.user.credentials.imageUrl ? (
|
||||||
|
<Box
|
||||||
|
// className={classes.box}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={this.props.user.credentials.imageUrl}
|
||||||
|
height="250"
|
||||||
|
width="250"
|
||||||
|
className={classes.box}/>
|
||||||
|
{uploading && (
|
||||||
|
<CircularProgress size={60} className={classes.uploadProgress} />
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Box
|
||||||
|
// className={classes.box}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={noImage}
|
||||||
|
height="250"
|
||||||
|
width="250"
|
||||||
|
className={classes.box}/>
|
||||||
|
{uploading && (
|
||||||
|
<CircularProgress size={60} className={classes.uploadProgress} />
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
|
||||||
|
// Used for the delete button
|
||||||
|
const open = Boolean(this.state.anchorEl);
|
||||||
|
const id = open ? 'simple-popover' : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container className={classes.form}>
|
this.state.pageLoading ?
|
||||||
<Grid item sm />
|
<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>
|
||||||
<Grid item sm>
|
:
|
||||||
<Typography variant="h2" className={classes.pageTitle}>
|
<Grid container className={classes.form} id="container-grid">
|
||||||
Edit Profile
|
<Grid item sm >
|
||||||
</Typography>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
|
||||||
<Grid container className={classes.form} spacing={4}>
|
|
||||||
<Grid item sm>
|
|
||||||
<TextField
|
|
||||||
id="firstName"
|
|
||||||
name="firstName"
|
|
||||||
label="First Name"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.firstName}
|
|
||||||
helperText={errors.firstName}
|
|
||||||
error={errors.firstName ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm>
|
|
||||||
<TextField
|
|
||||||
id="lastName"
|
|
||||||
name="lastName"
|
|
||||||
label="Last Name"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.lastName}
|
|
||||||
helperText={errors.lastname}
|
|
||||||
error={errors.lastName ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
<TextField
|
|
||||||
id="email"
|
|
||||||
name="email"
|
|
||||||
label="Email*"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.email}
|
|
||||||
disabled
|
|
||||||
helperText="(disabled)"
|
|
||||||
// INFO: These will be uncommented if changing emails is allowed
|
|
||||||
// helperText={errors.email}
|
|
||||||
// error={errors.email ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
id="handle"
|
|
||||||
name="handle"
|
|
||||||
label="Handle*"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.handle}
|
|
||||||
disabled
|
|
||||||
helperText="(disabled)"
|
|
||||||
// INFO: These will be uncommented if changing usernames is allowed
|
|
||||||
// helperText={errors.handle}
|
|
||||||
// error={errors.handle ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
id="bio"
|
|
||||||
name="bio"
|
|
||||||
label="Bio"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.bio}
|
|
||||||
helperText={errors.bio}
|
|
||||||
error={errors.bio ? true : false}
|
|
||||||
multiline
|
|
||||||
rows="8"
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
variant="outlined"
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
color="primary"
|
||||||
className={classes.button}
|
// className={classes.button}
|
||||||
disabled={loading}
|
disabled={loading || uploading}
|
||||||
//component={ Link }
|
className={classes.back}
|
||||||
//to='/user'
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
{loading && (
|
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
//variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.button}
|
|
||||||
component={ Link }
|
component={ Link }
|
||||||
to='/user'
|
to='/user'
|
||||||
>
|
>
|
||||||
Back to Profile
|
Back to Profile
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
</Grid>
|
||||||
|
<Grid item sm>
|
||||||
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
|
Edit Profile
|
||||||
|
</Typography>
|
||||||
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
|
{imageMarkup}
|
||||||
|
<input type="file" id="imageUpload" onChange={this.handleImageChange} hidden = "hidden"/>
|
||||||
|
<Tooltip title="Edit profile picture" placement="top">
|
||||||
|
<IconButton onClick={this.handleEditPicture} className="button">
|
||||||
|
<EditIcon color="primary"/>
|
||||||
|
</IconButton></Tooltip>
|
||||||
|
<Grid container className={classes.form} spacing={4}>
|
||||||
|
<Grid item sm>
|
||||||
|
<TextField
|
||||||
|
id="firstName"
|
||||||
|
name="firstName"
|
||||||
|
label="First Name"
|
||||||
|
className={classes.textField}
|
||||||
|
value={this.state.firstName}
|
||||||
|
helperText={errors.firstName}
|
||||||
|
error={errors.firstName ? true : false}
|
||||||
|
variant="outlined"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm>
|
||||||
|
<TextField
|
||||||
|
id="lastName"
|
||||||
|
name="lastName"
|
||||||
|
label="Last Name"
|
||||||
|
className={classes.textField}
|
||||||
|
value={this.state.lastName}
|
||||||
|
helperText={errors.lastname}
|
||||||
|
error={errors.lastName ? true : false}
|
||||||
|
variant="outlined"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
<TextField
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
label="Email*"
|
||||||
|
className={classes.textField}
|
||||||
|
value={this.state.email}
|
||||||
|
disabled
|
||||||
|
helperText="(disabled)"
|
||||||
|
// INFO: These will be uncommented if changing emails is allowed
|
||||||
|
// helperText={errors.email}
|
||||||
|
// error={errors.email ? true : false}
|
||||||
|
variant="outlined"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
id="handle"
|
||||||
|
name="handle"
|
||||||
|
label="Handle*"
|
||||||
|
className={classes.textField}
|
||||||
|
value={"@" + this.state.handle}
|
||||||
|
disabled
|
||||||
|
helperText="(disabled)"
|
||||||
|
// INFO: These will be uncommented if changing usernames is allowed
|
||||||
|
// helperText={errors.handle}
|
||||||
|
// error={errors.handle ? true : false}
|
||||||
|
variant="outlined"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
id="bio"
|
||||||
|
name="bio"
|
||||||
|
label="Bio"
|
||||||
|
className={classes.textField}
|
||||||
|
value={this.state.bio}
|
||||||
|
helperText={errors.bio}
|
||||||
|
error={errors.bio ? true : false}
|
||||||
|
multiline
|
||||||
|
rows="8"
|
||||||
|
variant="outlined"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
className={classes.button}
|
||||||
|
disabled={loading}
|
||||||
|
//component={ Link }
|
||||||
|
//to='/user'
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
{loading && (
|
||||||
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="outlined"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
className={classes.button}
|
className={classes.delete}
|
||||||
component={ Link }
|
onClick={this.handleOpenConfirmDelete}
|
||||||
to='/delete'
|
|
||||||
>
|
>
|
||||||
Delete Account
|
Delete Account
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</Grid>
|
||||||
|
<Box hidden={!Boolean(this.state.anchorEl)} className={classes.popoverBackground}></Box>
|
||||||
|
<Popover
|
||||||
|
id={id}
|
||||||
|
open={open}
|
||||||
|
anchorEl={this.state.anchorEl}
|
||||||
|
onClose={this.handleCloseConfirmDelete}
|
||||||
|
anchorOrigin={{
|
||||||
|
vertical: 'center',
|
||||||
|
horizontal: 'center'
|
||||||
|
}}
|
||||||
|
transformOrigin={{
|
||||||
|
vertical: 'top',
|
||||||
|
horizontal: 'center'
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
marginTop: "-200px"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
style={{
|
||||||
|
height: 200,
|
||||||
|
width: 400
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Grid container direction="column" spacing={3}>
|
||||||
|
<Grid item>
|
||||||
|
<Typography style={{marginTop: 30, marginLeft: 50, marginRight: 50, textAlign: "center", fontSize: 24}}>Are you sure you want to delete your account?</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Button
|
||||||
|
color="secondary"
|
||||||
|
variant="contained"
|
||||||
|
component={ Link }
|
||||||
|
to='/delete'
|
||||||
|
style={{
|
||||||
|
marginBottom: "-40px",
|
||||||
|
marginLeft: 10,
|
||||||
|
width: 90
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Yes
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="outlined"
|
||||||
|
onClick={this.handleCloseConfirmDelete}
|
||||||
|
style={{
|
||||||
|
marginBottom: "-40px",
|
||||||
|
marginLeft: 195
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
</Popover>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
|
||||||
</Grid>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edit.propTypes = {
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user,
|
||||||
|
UI: state.UI,
|
||||||
|
// credentials: state.user.credentials
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapActionsToProps = { uploadImage }
|
||||||
|
|
||||||
|
editProfile.propTypes = {
|
||||||
|
uploadImage: PropTypes.func.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withStyles(styles)(edit);
|
// export default withStyles(styles)(edit);
|
||||||
|
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(editProfile));
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import axios from "axios";
|
|||||||
|
|
||||||
// Material UI and React Router
|
// Material UI and React Router
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
import { makeStyles, styled } from "@material-ui/core/styles";
|
||||||
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import Card from "@material-ui/core/Card";
|
import Card from "@material-ui/core/Card";
|
||||||
import CardMedia from "@material-ui/core/CardMedia";
|
import CardMedia from "@material-ui/core/CardMedia";
|
||||||
@ -19,6 +21,7 @@ import Typography from "@material-ui/core/Typography";
|
|||||||
import AddCircle from "@material-ui/icons/AddCircle";
|
import AddCircle from "@material-ui/icons/AddCircle";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
||||||
|
import DoneIcon from "@material-ui/icons/Done";
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import "../App.css";
|
import "../App.css";
|
||||||
@ -30,14 +33,53 @@ const MyChip = styled(Chip)({
|
|||||||
color: "primary"
|
color: "primary"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
button: {
|
||||||
|
positon: "relative",
|
||||||
|
float: "left",
|
||||||
|
marginLeft: 30,
|
||||||
|
marginTop: 20
|
||||||
|
},
|
||||||
|
paper: {
|
||||||
|
// marginLeft: "10%",
|
||||||
|
// marginRight: "10%"
|
||||||
|
},
|
||||||
|
card: {
|
||||||
|
marginBottom: 5
|
||||||
|
},
|
||||||
|
profileImage: {
|
||||||
|
marginTop: 20
|
||||||
|
},
|
||||||
|
topicsContainer: {
|
||||||
|
border: "lightgray solid 1px",
|
||||||
|
marginTop: 20,
|
||||||
|
paddingTop: 10,
|
||||||
|
paddingBottom: 10,
|
||||||
|
height: 300
|
||||||
|
},
|
||||||
|
addCircle: {
|
||||||
|
width: 65,
|
||||||
|
height: 65,
|
||||||
|
marginTop: 10
|
||||||
|
},
|
||||||
|
username: {
|
||||||
|
marginBottom: 100
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class user extends Component {
|
class user extends Component {
|
||||||
state = {
|
constructor() {
|
||||||
profile: window.location.pathname.split("/").pop(),
|
super();
|
||||||
imageUrl: null,
|
this.state = {
|
||||||
topics: null,
|
profile: window.location.pathname.split("/").pop(),
|
||||||
user: null,
|
imageUrl: null,
|
||||||
following: null
|
topics: null,
|
||||||
};
|
user: null,
|
||||||
|
following: null,
|
||||||
|
posts: null,
|
||||||
|
myTopics: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
handleSub = () => {
|
handleSub = () => {
|
||||||
if (this.state.following === true) {
|
if (this.state.following === true) {
|
||||||
@ -88,38 +130,29 @@ class user extends Component {
|
|||||||
.get("/user")
|
.get("/user")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
following: res.data.credentials.following.includes(this.state.profile)
|
following: res.data.credentials.following.includes(
|
||||||
|
this.state.profile
|
||||||
|
),
|
||||||
|
myTopics: res.data.credentials.followedTopics
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post("/getOtherUsersPosts", {
|
||||||
|
handle: this.state.profile
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
// console.log(res.data);
|
||||||
|
this.setState({
|
||||||
|
posts: res.data
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let profileMarkup = this.state.profile ? (
|
const { classes } = this.props;
|
||||||
<div>
|
|
||||||
<Typography variant="h5">
|
|
||||||
@{this.state.profile}{" "}
|
|
||||||
{this.state.verified ? (
|
|
||||||
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
|
||||||
) : null}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p>loading username...</p>
|
|
||||||
);
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
|
||||||
this.state.topics.map(
|
|
||||||
topic => <MyChip label={topic} key={{ topic }.topic.id} /> // console.log({ topic }.topic.id)
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<p> loading topics...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
|
||||||
<img src={this.state.imageUrl} height="150" width="150" />
|
|
||||||
) : (
|
|
||||||
<img src={noImage} height="150" width="150" />
|
|
||||||
);
|
|
||||||
|
|
||||||
let followMarkup = this.state.following ? (
|
let followMarkup = this.state.following ? (
|
||||||
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
||||||
@ -130,18 +163,109 @@ class user extends Component {
|
|||||||
follow
|
follow
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
let profileMarkup = this.state.profile ? (
|
||||||
|
<div>
|
||||||
|
<Typography variant="h5">
|
||||||
|
@{this.state.profile}{" "}
|
||||||
|
{this.state.verified ? (
|
||||||
|
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
||||||
|
) : null}
|
||||||
|
</Typography>
|
||||||
|
{followMarkup}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p>loading username...</p>
|
||||||
|
);
|
||||||
|
|
||||||
console.log(this.state.following);
|
console.log(this.state.topics);
|
||||||
|
console.log(this.state.myTopics);
|
||||||
|
let topicsMarkup = this.state.topics ? (
|
||||||
|
this.state.topics.map(
|
||||||
|
topic =>
|
||||||
|
this.state.myTopics ? (
|
||||||
|
this.state.myTopics.includes(topic) ? (
|
||||||
|
<MyChip
|
||||||
|
label={topic}
|
||||||
|
key={{ topic }.topic.id}
|
||||||
|
onDelete
|
||||||
|
deleteIcon={<DoneIcon />}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<MyChip
|
||||||
|
label={topic}
|
||||||
|
key={{ topic }.topic.id}
|
||||||
|
color="secondary"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<p></p>
|
||||||
|
)
|
||||||
|
// topic => <MyChip label={topic} key={{ topic }.topic.id} /> // console.log({ topic }.topic.id)
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<p> no topic yet</p>
|
||||||
|
);
|
||||||
|
|
||||||
|
let imageMarkup = this.state.imageUrl ? (
|
||||||
|
<img src={this.state.imageUrl} height="150" width="150" />
|
||||||
|
) : (
|
||||||
|
<img src={noImage} height="150" width="150" />
|
||||||
|
);
|
||||||
|
|
||||||
|
let postMarkup = this.state.posts ? (
|
||||||
|
this.state.posts.map(post => (
|
||||||
|
<Card className={classes.card}>
|
||||||
|
<CardContent>
|
||||||
|
<Typography>
|
||||||
|
{this.state.imageUrl ? (
|
||||||
|
<img src={this.state.imageUrl} height="50" width="50" />
|
||||||
|
) : (
|
||||||
|
<img src={noImage} height="50" width="50" />
|
||||||
|
)}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h7">
|
||||||
|
<b>{post.userHandle}</b>
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
|
{post.createdAt}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<Typography variant="body1">
|
||||||
|
<b>{post.microBlogTitle}</b>
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
|
<br />
|
||||||
|
<Typography variant="body2">
|
||||||
|
<b>Topics:</b> {post.microBlogTopics}
|
||||||
|
</Typography>
|
||||||
|
<br />
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
|
Likes {post.likeCount}
|
||||||
|
</Typography>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<p>Posts</p>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={24}>
|
<Grid container spacing={24}>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
{followMarkup}
|
{/* {followMarkup} */}
|
||||||
{topicsMarkup}
|
{topicsMarkup}
|
||||||
<br />
|
<br />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
{postMarkup}
|
||||||
|
<br />
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -152,7 +276,8 @@ const mapStateToProps = state => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
user.propTypes = {
|
user.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired,
|
||||||
|
classes: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps)(user);
|
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const styles = {
|
|||||||
// marginRight: "10%"
|
// marginRight: "10%"
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
marginBottom: 10
|
marginBottom: 5
|
||||||
},
|
},
|
||||||
profileImage: {
|
profileImage: {
|
||||||
marginTop: 20
|
marginTop: 20
|
||||||
@ -76,7 +76,7 @@ class user extends Component {
|
|||||||
profile: null,
|
profile: null,
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
topics: null,
|
topics: null,
|
||||||
newTopic: null
|
newTopic: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +147,16 @@ class user extends Component {
|
|||||||
// console.log(res.data);
|
// console.log(res.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
posts: res.data
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatDate(dateString) {
|
||||||
|
let newDate = new Date(Date.parse(dateString));
|
||||||
|
return newDate.toDateString();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const { classes } = this.props;
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
@ -174,7 +179,7 @@ class user extends Component {
|
|||||||
topic => (
|
topic => (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={topic}
|
||||||
key={topic.id}
|
key={topic}
|
||||||
onDelete={key => this.handleDelete(topic)}
|
onDelete={key => this.handleDelete(topic)}
|
||||||
/>
|
/>
|
||||||
) // console.log({ topic }.topic.id)
|
) // console.log({ topic }.topic.id)
|
||||||
@ -201,7 +206,7 @@ class user extends Component {
|
|||||||
|
|
||||||
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}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography>
|
<Typography>
|
||||||
{this.state.imageUrl ? (
|
{this.state.imageUrl ? (
|
||||||
@ -210,25 +215,29 @@ 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="h6">
|
||||||
<b>{post.userHandle}</b>
|
<b>{post.userHandle}</b>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
{post.createdAt}
|
{post.createdAt}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body1">
|
<Typography variant="body1">
|
||||||
<b>{post.microBlogTitle}</b>
|
<b>{post.microBlogTitle}</b>
|
||||||
</Typography>
|
</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"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
<Typography variant="body2">
|
||||||
|
<b>Topics:</b> {post.microBlogTopics}
|
||||||
|
</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
<Typography variant="body2" color={"textSecondary"}>
|
||||||
|
Likes {post.likeCount}
|
||||||
|
</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
))
|
))
|
||||||
@ -242,7 +251,7 @@ class user extends Component {
|
|||||||
// showing the logged in users profile, instead of retreiving the
|
// showing the logged in users profile, instead of retreiving the
|
||||||
// profile based on the URL entered
|
// profile based on the URL entered
|
||||||
let editButtonMarkup = true ? (
|
let editButtonMarkup = true ? (
|
||||||
<Link to="/edit">
|
<Link to="/user/edit">
|
||||||
<Button className={classes.button} variant="outlined" color="primary">
|
<Button className={classes.button} variant="outlined" color="primary">
|
||||||
Edit Profile
|
Edit Profile
|
||||||
</Button>
|
</Button>
|
||||||
@ -276,7 +285,7 @@ class user extends Component {
|
|||||||
<TextField
|
<TextField
|
||||||
id="newTopic"
|
id="newTopic"
|
||||||
label="new topic"
|
label="new topic"
|
||||||
defaultValue=""
|
// defaultValue=""
|
||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={this.state.newTopic}
|
value={this.state.newTopic}
|
||||||
@ -286,7 +295,7 @@ class user extends Component {
|
|||||||
className={classes.addCircle}
|
className={classes.addCircle}
|
||||||
color="primary"
|
color="primary"
|
||||||
// iconStyle={classes.addCircle}
|
// iconStyle={classes.addCircle}
|
||||||
clickable
|
clickable="true"
|
||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
cursor="pointer"
|
cursor="pointer"
|
||||||
/>
|
/>
|
||||||
@ -311,7 +320,8 @@ const mapStateToProps = state => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
user.propTypes = {
|
user.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired,
|
||||||
|
classes: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||||
|
|||||||
@ -89,7 +89,7 @@ export class verify extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const { classes } = this.props;
|
||||||
const { errors, loading } = this.state;
|
const { loading } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container className={classes.form}>
|
<Grid container className={classes.form}>
|
||||||
|
|||||||
@ -1,18 +1,40 @@
|
|||||||
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED, LIKE_POST, UNLIKE_POST, SET_LIKES} from '../types';
|
|
||||||
|
import {
|
||||||
|
SET_USER,
|
||||||
|
SET_ERRORS,
|
||||||
|
CLEAR_ERRORS,
|
||||||
|
LOADING_UI,
|
||||||
|
// SET_AUTHENTICATED,
|
||||||
|
SET_UNAUTHENTICATED,
|
||||||
|
LIKE_POST,
|
||||||
|
UNLIKE_POST,
|
||||||
|
SET_LIKES,
|
||||||
|
LOADING_USER
|
||||||
|
} from '../types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
// Saves Authorization in browser local storage and adds it as a header to axios
|
||||||
|
const setAuthorizationHeader = (token) => {
|
||||||
|
const FBIdToken = `Bearer ${token}`;
|
||||||
|
localStorage.setItem('FBIdToken', FBIdToken);
|
||||||
|
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets Database info for the logged in user and sets it in Redux
|
||||||
export const getUserData = () => (dispatch) => {
|
export const getUserData = () => (dispatch) => {
|
||||||
|
dispatch({ type: LOADING_USER });
|
||||||
axios.get('/user')
|
axios.get('/user')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SET_USER,
|
type: SET_USER,
|
||||||
payload: res.data,
|
payload: res.data,
|
||||||
})
|
});
|
||||||
|
dispatch({type: CLEAR_ERRORS});
|
||||||
})
|
})
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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: LOADING_UI });
|
dispatch({ type: LOADING_UI });
|
||||||
axios
|
axios
|
||||||
@ -21,7 +43,7 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
|||||||
// Save the login token
|
// Save the login token
|
||||||
setAuthorizationHeader(res.data.token);
|
setAuthorizationHeader(res.data.token);
|
||||||
dispatch(getUserData());
|
dispatch(getUserData());
|
||||||
dispatch({ type: CLEAR_ERRORS })
|
// dispatch({ type: CLEAR_ERRORS })
|
||||||
// Redirects to home page
|
// Redirects to home page
|
||||||
history.push('/home');
|
history.push('/home');
|
||||||
})
|
})
|
||||||
@ -33,6 +55,7 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Sends signup data to firebase and sets the user data in Redux
|
||||||
export const signupUser = (newUserData, history) => (dispatch) => {
|
export const signupUser = (newUserData, history) => (dispatch) => {
|
||||||
dispatch({ type: LOADING_UI });
|
dispatch({ type: LOADING_UI });
|
||||||
axios
|
axios
|
||||||
@ -43,7 +66,7 @@ export const signupUser = (newUserData, history) => (dispatch) => {
|
|||||||
// Save the signup token
|
// Save the signup token
|
||||||
setAuthorizationHeader(res.data.token);
|
setAuthorizationHeader(res.data.token);
|
||||||
dispatch(getUserData());
|
dispatch(getUserData());
|
||||||
dispatch({ type: CLEAR_ERRORS })
|
// dispatch({ type: CLEAR_ERRORS })
|
||||||
// Redirects to home page
|
// Redirects to home page
|
||||||
history.push('/home');
|
history.push('/home');
|
||||||
})
|
})
|
||||||
@ -55,12 +78,14 @@ export const signupUser = (newUserData, history) => (dispatch) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Deletes the Authorization header and clears all user data from Redux
|
||||||
export const logoutUser = () => (dispatch) => {
|
export const logoutUser = () => (dispatch) => {
|
||||||
localStorage.removeItem('FBIdToken');
|
localStorage.removeItem('FBIdToken');
|
||||||
delete axios.defaults.headers.common['Authorization'];
|
delete axios.defaults.headers.common['Authorization'];
|
||||||
dispatch({ type: SET_UNAUTHENTICATED });
|
dispatch({ type: SET_UNAUTHENTICATED });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const deleteUser = () => (dispatch) => {
|
export const deleteUser = () => (dispatch) => {
|
||||||
axios
|
axios
|
||||||
.delete("/delete")
|
.delete("/delete")
|
||||||
@ -135,3 +160,16 @@ const setAuthorizationHeader = (token) => {
|
|||||||
localStorage.setItem('FBIdToken', FBIdToken);
|
localStorage.setItem('FBIdToken', FBIdToken);
|
||||||
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
||||||
}
|
}
|
||||||
|
// Sends an image data form to firebase to be uploaded to the user profile
|
||||||
|
export const uploadImage = (formData) => (dispatch) => {
|
||||||
|
dispatch({ type: LOADING_UI });
|
||||||
|
axios.post('/user/image', formData)
|
||||||
|
.then(() => {
|
||||||
|
dispatch(getUserData());
|
||||||
|
// dispatch({ type: CLEAR_ERRORS });
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export default function(state = initialState, action) {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
loading: true
|
loading: true
|
||||||
}
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,17 @@
|
|||||||
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED, LIKE_POST, UNLIKE_POST, SET_LIKES} from '../types';
|
|
||||||
|
import {
|
||||||
|
SET_USER,
|
||||||
|
// SET_ERRORS,
|
||||||
|
// CLEAR_ERRORS,
|
||||||
|
// LOADING_UI,
|
||||||
|
SET_AUTHENTICATED,
|
||||||
|
SET_UNAUTHENTICATED,
|
||||||
|
LOADING_USER,
|
||||||
|
LIKE_POST,
|
||||||
|
UNLIKE_POST,
|
||||||
|
SET_LIKES
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
@ -21,6 +34,7 @@ export default function(state = initialState, action) {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
|
loading: false,
|
||||||
...action.payload,
|
...action.payload,
|
||||||
};
|
};
|
||||||
case LIKE_POST:
|
case LIKE_POST:
|
||||||
@ -37,6 +51,11 @@ export default function(state = initialState, action) {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
...action.payload
|
...action.payload
|
||||||
|
|
||||||
|
case LOADING_USER:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user