mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 21:25:04 +00:00
Compare commits
2 Commits
engage_mic
...
ImprovingU
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1846165c85 | ||
|
|
3f24d90fef |
@@ -1,8 +1,6 @@
|
|||||||
/* 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');
|
|
||||||
|
|
||||||
|
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
const newPost = {
|
const newPost = {
|
||||||
@@ -19,7 +17,6 @@ exports.putPost = (req, res) => {
|
|||||||
|
|
||||||
admin.firestore().collection('posts').add(newPost)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
doc.update({postId: doc.id})
|
|
||||||
const resPost = newPost;
|
const resPost = newPost;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
@@ -41,11 +38,11 @@ exports.getallPostsforUser = (req, res) => {
|
|||||||
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.");
|
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||||
|
return;
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
res.status(500).send("Failed to retrieve user's posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,186 +57,14 @@ exports.getallPosts = (req, res) => {
|
|||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return res.status(200).json("Successfully retrieved every post from database.");
|
res.status(200).send("Successfully retrieved every post from database.");
|
||||||
|
return;
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
return res.status(500).json("Failed to retrieve posts from database.", err);
|
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.quoteWithPost = (req, res) => {
|
|
||||||
|
|
||||||
let quoteData;
|
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
|
||||||
where('userHandle', '==', req.user.handle).
|
|
||||||
where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
quoteData = doc.data();
|
|
||||||
return quoteDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
if(data.empty) {
|
|
||||||
return admin.firestore().collection('quote').add({
|
|
||||||
postId : req.params.postId,
|
|
||||||
userHandle : req.user.handle,
|
|
||||||
quotePost : req.body.quotePost
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return admin.firestore().collection('posts').add({
|
|
||||||
quoteData,
|
|
||||||
quoteUser : req.user.handle,
|
|
||||||
quotePost : req.body.quotePost,
|
|
||||||
quotedAt : new Date().toISOString()
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return res.status(500).json({error: err});
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.quoteWithoutPost = (req, res) => {
|
|
||||||
let quoteData;
|
|
||||||
const quoteDoc = admin.firestore().collection('quote').
|
|
||||||
where('userHandle', '==', req.user.handle).
|
|
||||||
where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
quoteData = doc.data();
|
|
||||||
return quoteDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
if(data.empty) {
|
|
||||||
return admin.firestore().collection('quote').add({
|
|
||||||
postId : req.params.postId,
|
|
||||||
userHandle : req.user.handle,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return admin.firestore().collection('posts').add({
|
|
||||||
quoteData,
|
|
||||||
quoteUser : req.user.handle,
|
|
||||||
quotedAt : new Date().toISOString()
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res.status(400).json({ error: 'Post has already been quoted.' });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return res.status(500).json({error: 'Something is wrong'});
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
exports.likePost = (req, res) => {
|
|
||||||
let postData;
|
|
||||||
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
postData = doc.data();
|
|
||||||
return likeDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
if (data.empty) {
|
|
||||||
return admin.firestore().collection('likes').add({
|
|
||||||
postId : req.params.postId,
|
|
||||||
userHandle: req.user.handle
|
|
||||||
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
postData.likeCount++;
|
|
||||||
return postDoc.update({likeCount : postData.likeCount})
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return res.status(200).json(postData);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return res.status(500).json({error: 'Something is wrong'});
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.unlikePost = (req, res) => {
|
|
||||||
|
|
||||||
let postData;
|
|
||||||
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
|
||||||
.where('postId', '==', req.params.postId).limit(1);
|
|
||||||
|
|
||||||
const postDoc = db.doc(`/posts/${req.params.postId}`);
|
|
||||||
|
|
||||||
postDoc.get()
|
|
||||||
.then((doc) => {
|
|
||||||
if(doc.exists) {
|
|
||||||
postData = doc.data();
|
|
||||||
return likeDoc.get();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return res.status(404).json({error: 'Post not found'});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
return db
|
|
||||||
.doc(`/likes/${data.docs[0].id}`)
|
|
||||||
.delete()
|
|
||||||
.then(() => {
|
|
||||||
postData.likeCount--;
|
|
||||||
return postDoc.update({ likeCount: postData.likeCount });
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
res.status(200).json(postData);
|
|
||||||
});
|
|
||||||
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({error: 'Something is wrong'});
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
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,28 +1,20 @@
|
|||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
exports.putTopic = (req, res) => {
|
exports.putTopic = (req, res) => {
|
||||||
let new_following = [];
|
const newTopic = {
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
topic: req.body.topic
|
||||||
userRef
|
};
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
new_following = doc.data().followedTopics;
|
|
||||||
new_following.push(req.body.following);
|
|
||||||
|
|
||||||
// add stuff
|
admin
|
||||||
userRef
|
.firestore()
|
||||||
.set({ followedTopics: new_following }, { merge: true })
|
.collection("topics")
|
||||||
|
.add(newTopic)
|
||||||
.then(doc => {
|
.then(doc => {
|
||||||
return res
|
const resTopic = newTopic;
|
||||||
.status(201)
|
return res.status(200).json(resTopic);
|
||||||
.json({ message: `Following ${req.body.following}` });
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
console.error(err);
|
||||||
});
|
return res.status(500).json({ error: "something is wrong" });
|
||||||
return res.status(200).json({ message: "OK" });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,46 +40,21 @@ exports.getAllTopics = (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteTopic = (req, res) => {
|
exports.deleteTopic = (req, res) => {
|
||||||
let new_following = [];
|
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
topic
|
||||||
userRef
|
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then(doc => {
|
||||||
new_following = doc.data().followedTopics;
|
if (!doc.exists) {
|
||||||
// remove username from array
|
return res.status(404).json({ error: "Topic not found" });
|
||||||
new_following.forEach(function(follower, index) {
|
} else {
|
||||||
if (follower === `${req.body.unfollow}`) {
|
return topic.delete();
|
||||||
new_following.splice(index, 1);
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.then(() => {
|
||||||
// update database
|
return res.json({ message: "Topic successfully deleted!" });
|
||||||
userRef
|
|
||||||
.set({ followedTopics: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(202)
|
|
||||||
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
console.error(err);
|
||||||
});
|
return res.status(500).json({ error: "Failed to delete topic." });
|
||||||
return res.status(200).json({ message: "ok" });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getUserTopics = (req, res) => {
|
|
||||||
let data = [];
|
|
||||||
db.doc(`/users/${req.body.handle}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
data = doc.data().followedTopics;
|
|
||||||
return res.status(200).json({ data });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ exports.signup = (req, res) => {
|
|||||||
createdAt: newUser.createdAt,
|
createdAt: newUser.createdAt,
|
||||||
userId,
|
userId,
|
||||||
followedTopics: [],
|
followedTopics: [],
|
||||||
imageUrl: defaultImageUrl,
|
imageUrl: defaultImageUrl
|
||||||
verified: false
|
|
||||||
};
|
};
|
||||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||||
})
|
})
|
||||||
@@ -201,9 +200,9 @@ exports.deleteUser = (req, res) => {
|
|||||||
// Get the profile image filename
|
// Get the profile image filename
|
||||||
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
||||||
let imageFileName;
|
let imageFileName;
|
||||||
req.userData.imageUrl
|
req.userData.imageUrl ?
|
||||||
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
|
imageFileName = req.userData.imageUrl.split('/o/')[1].split('?alt=')[0] :
|
||||||
: (imageFileName = "no-img.png");
|
imageFileName = 'no-img.png'
|
||||||
|
|
||||||
const userId = req.userData.userId;
|
const userId = req.userData.userId;
|
||||||
let errors = {};
|
let errors = {};
|
||||||
@@ -221,58 +220,56 @@ exports.deleteUser = (req, res) => {
|
|||||||
let auth = admin.auth().deleteUser(userId);
|
let auth = admin.auth().deleteUser(userId);
|
||||||
|
|
||||||
// Deletes database data
|
// Deletes database data
|
||||||
let data = db
|
let data = db.collection("users").doc(`${req.user.handle}`).delete();
|
||||||
.collection("users")
|
|
||||||
.doc(`${req.user.handle}`)
|
|
||||||
.delete();
|
|
||||||
|
|
||||||
// Deletes any custom profile image
|
// Deletes any custom profile image
|
||||||
let image;
|
let image;
|
||||||
if (imageFileName !== "no-img.png") {
|
if (imageFileName !== 'no-img.png') {
|
||||||
image = admin
|
image = admin.storage().bucket().file(imageFileName).delete()
|
||||||
.storage()
|
|
||||||
.bucket()
|
|
||||||
.file(imageFileName)
|
|
||||||
.delete();
|
|
||||||
} else {
|
} else {
|
||||||
image = Promise.resolve();
|
image = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes all users posts
|
// Deletes all users posts
|
||||||
let posts = db
|
let posts = db.collection("posts")
|
||||||
.collection("posts")
|
|
||||||
.where("userHandle", "==", req.user.handle)
|
.where("userHandle", "==", req.user.handle)
|
||||||
.get()
|
.get()
|
||||||
.then(query => {
|
.then((query) => {
|
||||||
query.forEach(snap => {
|
query.forEach((snap) => {
|
||||||
snap.ref.delete();
|
snap.ref.delete();
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
});
|
})
|
||||||
|
|
||||||
let promises = [
|
let promises = [
|
||||||
auth.then(thenFunction("auth")).catch(err => catchFunction("auth", err)),
|
auth
|
||||||
data.then(thenFunction("data")).catch(err => catchFunction("data", err)),
|
.then(thenFunction('auth'))
|
||||||
image.then(thenFunction("image")).catch(err => catchFunction("image", err)),
|
.catch((err) => catchFunction('auth', err)),
|
||||||
posts.then(thenFunction("posts")).catch(err => catchFunction("image", err))
|
data
|
||||||
|
.then(thenFunction('data'))
|
||||||
|
.catch((err) => catchFunction('data', err)),
|
||||||
|
image
|
||||||
|
.then(thenFunction('image'))
|
||||||
|
.catch((err) => catchFunction('image', err)),
|
||||||
|
posts
|
||||||
|
.then(thenFunction('posts'))
|
||||||
|
.catch((err) => catchFunction('image', err))
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
// Wait for all promises to resolve
|
// Wait for all promises to resolve
|
||||||
let waitPromise = Promise.all(promises);
|
let waitPromise = Promise.all(promises);
|
||||||
|
|
||||||
waitPromise
|
waitPromise.then(() => {
|
||||||
.then(() => {
|
|
||||||
if (Object.keys(errors) > 0) {
|
if (Object.keys(errors) > 0) {
|
||||||
return res.status(500).json(errors);
|
return res.status(500).json(errors);
|
||||||
} else {
|
} else {
|
||||||
return res.status(200).json({
|
return res.status(200).json({message: `All data for ${req.userData.handle} has been deleted.`});
|
||||||
message: `All data for ${req.userData.handle} has been deleted.`
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
return res.status(500).json({error: err});
|
return res.status(500).json({error: err});
|
||||||
});
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns all data in the database for the user who is currently signed in
|
// Returns all data in the database for the user who is currently signed in
|
||||||
@@ -349,146 +346,20 @@ exports.getAuthenticatedUser = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
|
||||||
// Must be run by the Admin user
|
|
||||||
exports.verifyUser = (req, res) => {
|
|
||||||
if (req.userData.handle !== "Admin") {
|
|
||||||
return res.status(403).json({ error: "This must be done as Admin" });
|
|
||||||
}
|
|
||||||
|
|
||||||
db.doc(`/users/${req.body.user}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
if (doc.exists) {
|
|
||||||
let verifiedUser = doc.data();
|
|
||||||
verifiedUser.verified = true;
|
|
||||||
return db
|
|
||||||
.doc(`/users/${req.body.user}`)
|
|
||||||
.set(verifiedUser, { merge: true });
|
|
||||||
} else {
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ error: `User ${req.body.user} was not found` });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `${req.body.user} is now verified` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Unverifies the user sent to the request
|
|
||||||
// Must be run by admin
|
|
||||||
exports.unverifyUser = (req, res) => {
|
|
||||||
if (req.userData.handle !== "Admin") {
|
|
||||||
return res.status(403).json({ error: "This must be done as Admin" });
|
|
||||||
}
|
|
||||||
|
|
||||||
db.doc(`/users/${req.body.user}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
if (doc.exists) {
|
|
||||||
let unverifiedUser = doc.data();
|
|
||||||
unverifiedUser.verified = false;
|
|
||||||
return db
|
|
||||||
.doc(`/users/${req.body.user}`)
|
|
||||||
.set(unverifiedUser, { merge: true });
|
|
||||||
} else {
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ error: `User ${req.body.user} was not found` });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `${req.body.user} is no longer verified` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
exports.getUserHandles = (req, res) => {
|
exports.getUserHandles = (req, res) => {
|
||||||
db.doc(`/users/${req.body.userHandle}`)
|
admin
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then(data => {
|
||||||
if (doc.exists) {
|
let users = [];
|
||||||
let userHandle = doc.data().handle;
|
data.forEach(function(doc) {
|
||||||
return res.status(200).json(userHandle);
|
users.push(doc.data().handle);
|
||||||
} else {
|
});
|
||||||
return res.status(404).json({ error: "user not found" });
|
return res.status(200).json(users);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: "Failed to get all user handles." });
|
return res.status(500).json({ error: "Failed to get all user handles." });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.addSubscription = (req, res) => {
|
|
||||||
let new_following = [];
|
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
|
||||||
userRef.get().then(doc => {
|
|
||||||
new_following = doc.data().following;
|
|
||||||
new_following.push(req.body.following);
|
|
||||||
|
|
||||||
// add stuff
|
|
||||||
userRef
|
|
||||||
.set({ following: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ message: `Following ${req.body.following}` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getSubs = (req, res) => {
|
|
||||||
let data = [];
|
|
||||||
db.doc(`/users/${req.userData.handle}`)
|
|
||||||
.get()
|
|
||||||
.then(doc => {
|
|
||||||
data = doc.data().following;
|
|
||||||
return res.status(200).json({ data });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.removeSub = (req, res) => {
|
|
||||||
let new_following = [];
|
|
||||||
let userRef = db.doc(`/users/${req.userData.handle}`);
|
|
||||||
userRef.get().then(doc => {
|
|
||||||
new_following = doc.data().following;
|
|
||||||
// remove username from array
|
|
||||||
new_following.forEach(function(follower, index) {
|
|
||||||
if (follower === `${req.body.unfollow}`) {
|
|
||||||
new_following.splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// update database
|
|
||||||
userRef
|
|
||||||
.set({ following: new_following }, { merge: true })
|
|
||||||
.then(doc => {
|
|
||||||
return res
|
|
||||||
.status(202)
|
|
||||||
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return res.status(500).json({ err });
|
|
||||||
});
|
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -17,12 +17,7 @@ const {
|
|||||||
signup,
|
signup,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
updateProfileInfo,
|
updateProfileInfo,
|
||||||
verifyUser,
|
getUserHandles
|
||||||
unverifyUser,
|
|
||||||
getUserHandles,
|
|
||||||
addSubscription,
|
|
||||||
getSubs,
|
|
||||||
removeSub
|
|
||||||
} = require("./handlers/users");
|
} = require("./handlers/users");
|
||||||
|
|
||||||
// Adds a user to the database and registers them in firebase with
|
// Adds a user to the database and registers them in firebase with
|
||||||
@@ -37,7 +32,7 @@ app.post("/login", login);
|
|||||||
//Deletes user account
|
//Deletes user account
|
||||||
app.delete("/delete", fbAuth, deleteUser);
|
app.delete("/delete", fbAuth, deleteUser);
|
||||||
|
|
||||||
app.post("/getUserDetails", fbAuth, getUserDetails);
|
app.get("/getUser", fbAuth, getUserDetails);
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -47,30 +42,13 @@ app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
|||||||
|
|
||||||
app.get("/user", fbAuth, getAuthenticatedUser);
|
app.get("/user", fbAuth, getAuthenticatedUser);
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
|
||||||
// Must be run by the Admin user
|
|
||||||
app.post("/verifyUser", fbAuth, verifyUser);
|
|
||||||
|
|
||||||
// Unverifies the user sent to the request
|
|
||||||
// Must be run by admin
|
|
||||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
|
||||||
|
|
||||||
// get user handles with search phase
|
// get user handles with search phase
|
||||||
app.post("/getUserHandles", fbAuth, getUserHandles);
|
app.get("/getUserHandles", fbAuth, getUserHandles);
|
||||||
|
|
||||||
// get user's subscription
|
|
||||||
app.get("/getSubs", fbAuth, getSubs);
|
|
||||||
|
|
||||||
// add user to another user's "following" data field
|
|
||||||
app.post("/addSubscription", fbAuth, addSubscription);
|
|
||||||
|
|
||||||
// remove one subscription
|
|
||||||
app.post("/removeSub", fbAuth, removeSub);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
|
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
@@ -79,23 +57,10 @@ app.get("/getallPosts", getallPosts);
|
|||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post("/putPost", fbAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
|
|
||||||
app.get("/like/:postId", fbAuth, likePost);
|
|
||||||
app.get("/unlike/:postId", fbAuth, unlikePost);
|
|
||||||
|
|
||||||
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
|
||||||
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic");
|
||||||
putTopic,
|
|
||||||
getAllTopics,
|
|
||||||
deleteTopic,
|
|
||||||
getUserTopics
|
|
||||||
} = require("./handlers/topic");
|
|
||||||
|
|
||||||
// add topic to database
|
// add topic to database
|
||||||
app.post("/putTopic", fbAuth, putTopic);
|
app.post("/putTopic", fbAuth, putTopic);
|
||||||
@@ -104,9 +69,6 @@ app.post("/putTopic", fbAuth, putTopic);
|
|||||||
app.get("/getAllTopics", fbAuth, getAllTopics);
|
app.get("/getAllTopics", fbAuth, getAllTopics);
|
||||||
|
|
||||||
// delete a specific topic
|
// delete a specific topic
|
||||||
app.post("/deleteTopic", fbAuth, deleteTopic);
|
app.delete("/deleteTopic/:topicId", fbAuth, deleteTopic);
|
||||||
|
|
||||||
// get topic for this user
|
|
||||||
app.post("/getUserTopics", fbAuth, getUserTopics);
|
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
|
|||||||
@@ -41,5 +41,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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import { logoutUser, getUserData } from "./redux/actions/userActions";
|
|||||||
// Components
|
// Components
|
||||||
import AuthRoute from "./util/AuthRoute";
|
import AuthRoute from "./util/AuthRoute";
|
||||||
|
|
||||||
|
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
import home from "./pages/Home";
|
import home from "./pages/Home";
|
||||||
import signup from "./pages/Signup";
|
import signup from "./pages/Signup";
|
||||||
@@ -29,9 +31,7 @@ import Delete from "./pages/Delete";
|
|||||||
import writeMicroblog from "./Writing_Microblogs.js";
|
import writeMicroblog from "./Writing_Microblogs.js";
|
||||||
import editProfile from "./pages/editProfile";
|
import editProfile from "./pages/editProfile";
|
||||||
import userLine from "./Userline.js";
|
import userLine from "./Userline.js";
|
||||||
import verify from "./pages/verify";
|
|
||||||
import Search from "./pages/Search.js";
|
import Search from "./pages/Search.js";
|
||||||
import otherUser from "./pages/otherUser";
|
|
||||||
|
|
||||||
const theme = createMuiTheme(themeObject);
|
const theme = createMuiTheme(themeObject);
|
||||||
|
|
||||||
@@ -64,6 +64,7 @@ class App extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
||||||
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
||||||
<AuthRoute exact path="/signup" component={signup} />
|
<AuthRoute exact path="/signup" component={signup} />
|
||||||
<AuthRoute exact path="/login" component={login} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
@@ -75,11 +76,10 @@ 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="/edit" component={editProfile} />
|
||||||
<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} />
|
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home} />
|
<AuthRoute exact path="/" component={home} />
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from "react";
|
import React, { Component } from 'react';
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from 'react-router-dom';
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
// Material UI stuff
|
// Material UI stuff
|
||||||
import AppBar from "@material-ui/core/AppBar";
|
import AppBar from '@material-ui/core/AppBar';
|
||||||
import ToolBar from "@material-ui/core/Toolbar";
|
import ToolBar from '@material-ui/core/Toolbar';
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from '@material-ui/core/Button';
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { logoutUser } from "../../redux/actions/userActions";
|
import { logoutUser } from '../../redux/actions/userActions';
|
||||||
import { connect } from "react-redux";
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
@@ -38,47 +38,34 @@ export class Navbar extends Component {
|
|||||||
return (
|
return (
|
||||||
<AppBar>
|
<AppBar>
|
||||||
<ToolBar>
|
<ToolBar>
|
||||||
<Button component={Link} to="/">
|
<Button component={ Link } to='/'>
|
||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
{authenticated && (
|
{authenticated && <Button component={ Link } to='/user'>
|
||||||
<Button component={Link} to="/user">
|
|
||||||
Profile
|
Profile
|
||||||
</Button>
|
</Button>}
|
||||||
)}
|
{!authenticated && <Button component={ Link } to='/login'>
|
||||||
{!authenticated && (
|
|
||||||
<Button component={Link} to="/login">
|
|
||||||
Login
|
Login
|
||||||
</Button>
|
</Button>}
|
||||||
)}
|
{!authenticated && <Button component={ Link } to='/signup'>
|
||||||
{!authenticated && (
|
|
||||||
<Button component={Link} to="/signup">
|
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>
|
</Button>}
|
||||||
)}
|
{authenticated && <Button component={ Link } to='/logout'>
|
||||||
{authenticated && (
|
|
||||||
<Button component={Link} to="/search">
|
|
||||||
Search
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{authenticated && (
|
|
||||||
<Button component={Link} to="/logout">
|
|
||||||
Logout
|
Logout
|
||||||
</Button>
|
</Button>}
|
||||||
)}
|
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
});
|
})
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
};
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|||||||
@@ -15,14 +15,9 @@ import '../App.css';
|
|||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from '../images/no-img.png';
|
||||||
import Writing_Microblogs from '../Writing_Microblogs';
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
import ReactModal from 'react-modal';
|
|
||||||
|
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
state = {
|
state = {};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
@@ -32,14 +27,10 @@ class Home extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
posts: res.data
|
||||||
})
|
})
|
||||||
this.setState({posts: (this.state.posts).sort((a,b) =>
|
|
||||||
-a.createdAt.localeCompare(b.createdAt))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
|
|
||||||
@@ -54,17 +45,14 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
|
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
||||||
" " + post.createdAt.substring(11,19)}</Typography>
|
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</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} Comments {post.commentCount}</Typography>
|
||||||
<Like microBlog = {post.postId}></Like>
|
|
||||||
<Quote microblog = {post.postId}></Quote>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
@@ -108,7 +96,6 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
})
|
})
|
||||||
@@ -117,167 +104,4 @@ Home.propTypes = {
|
|||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
class Quote extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
characterCount: 250,
|
|
||||||
showModal: false,
|
|
||||||
value: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
|
|
||||||
this.handleOpenModal = this.handleOpenModal.bind(this);
|
|
||||||
this.handleCloseModal = this.handleCloseModal.bind(this);
|
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmitWithoutPost(event) {
|
|
||||||
const headers = {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
};
|
|
||||||
axios.post(`/quoteWithoutPost/${this.props.microblog}`, headers)
|
|
||||||
.then((res) => {
|
|
||||||
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
handleOpenModal() {
|
|
||||||
this.setState({ showModal: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCloseModal() {
|
|
||||||
this.setState({ showModal: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
|
||||||
this.setState({ value: event.target.value });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
|
||||||
const charCount = event.target.value.length;
|
|
||||||
const charRemaining = 250 - charCount;
|
|
||||||
this.setState({ characterCount: charRemaining });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit(event) {
|
|
||||||
const quotedPost = {
|
|
||||||
quotePost: this.state.value,
|
|
||||||
};
|
|
||||||
const headers = {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
};
|
|
||||||
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
|
|
||||||
.then((res) => {
|
|
||||||
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({ showModal: false, characterCount: 250, value: "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<button onClick={this.handleOpenModal}>Quote with Post</button>
|
|
||||||
<ReactModal
|
|
||||||
isOpen={this.state.showModal}
|
|
||||||
style={{content: {height: "50%", width: "25%", marginTop: "auto", marginLeft: "auto", marginRight: "auto", marginBottom : "auto"}}}
|
|
||||||
>
|
|
||||||
<div style={{ width: "200px", marginLeft: "50px" }}>
|
|
||||||
<form>
|
|
||||||
<textarea
|
|
||||||
value={this.state.value}
|
|
||||||
required
|
|
||||||
maxLength="250"
|
|
||||||
placeholder="Write Quoted Post here..."
|
|
||||||
onChange={e => {
|
|
||||||
this.handleChangeforPost(e);
|
|
||||||
this.handleChangeforCharacterCount(e);
|
|
||||||
|
|
||||||
}}
|
|
||||||
cols={40}
|
|
||||||
rows={20}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
|
||||||
</div>
|
|
||||||
<button onClick={this.handleSubmit}>Share Quoted Post</button>
|
|
||||||
|
|
||||||
<button onClick={this.handleCloseModal}>Cancel</button>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</ReactModal>
|
|
||||||
<button onClick={this.handleSubmitWithoutPost}>Quote without Post</button>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Like extends Component {
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
this.state = {
|
|
||||||
like: false
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleClick = this.handleClick.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClick(){
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
like: !this.state.like
|
|
||||||
});
|
|
||||||
|
|
||||||
if(this.state.like == false)
|
|
||||||
{
|
|
||||||
|
|
||||||
axios.get(`/like/${this.props.microBlog}`)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
axios.get(`/unlike/${this.props.microBlog}`)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
const label = this.state.like ? 'Unlike' : 'Like'
|
|
||||||
return(
|
|
||||||
<div>
|
|
||||||
<button onClick={this.handleClick}>{label}</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Home);
|
export default connect(mapStateToProps)(Home);
|
||||||
@@ -24,7 +24,8 @@ const styles = {
|
|||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 20
|
marginBottom: 20,
|
||||||
|
border: ""
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
// marginTop: 20,
|
// marginTop: 20,
|
||||||
@@ -39,6 +40,12 @@ const styles = {
|
|||||||
},
|
},
|
||||||
p: {
|
p: {
|
||||||
fontFamily: "cursive",
|
fontFamily: "cursive",
|
||||||
|
backgroundColor: "lightgrey",
|
||||||
|
},
|
||||||
|
div: {
|
||||||
|
borderRadius: "5px",
|
||||||
|
backgroundColor: "#f2f2f2",
|
||||||
|
padding: "20px",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
// import props
|
// import props
|
||||||
import { TextField, Button } from "@material-ui/core";
|
import { TextField, Paper } from "@material-ui/core";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import Axios from "axios";
|
import Axios from "axios";
|
||||||
|
import user from "./user.js";
|
||||||
|
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
import {
|
||||||
|
BrowserRouter as Router,
|
||||||
|
Switch,
|
||||||
|
Route,
|
||||||
|
Link,
|
||||||
|
useRouteMatch
|
||||||
|
} from "react-router-dom";
|
||||||
|
|
||||||
export class Search extends Component {
|
export class Search extends Component {
|
||||||
state = {
|
state = {
|
||||||
@@ -12,28 +19,20 @@ export class Search extends Component {
|
|||||||
searchResult: null
|
searchResult: null
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSearch = () => {
|
handleSearch(event) {
|
||||||
console.log(this.state.searchPhase);
|
Axios.get("/getUserHandles").then(res => {
|
||||||
Axios.post("/getUserHandles", {
|
|
||||||
userHandle: this.state.searchPhase
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log(res);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
searchResult: res.data
|
searchResult: res.data
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
});
|
||||||
};
|
console.log(this.state.searchPhase);
|
||||||
|
}
|
||||||
|
|
||||||
handleInput(event) {
|
handleInput(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
searchPhase: event.target.value
|
searchPhase: event.target.value
|
||||||
});
|
});
|
||||||
console.log(this.state.searchPhase);
|
this.handleSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRedirect() {
|
handleRedirect() {
|
||||||
@@ -42,16 +41,16 @@ export class Search extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let resultMarkup = this.state.searchResult ? (
|
let resultMarkup = this.state.searchResult ? (
|
||||||
|
this.state.searchResult.map(result => (
|
||||||
<Router>
|
<Router>
|
||||||
<div>
|
<div>
|
||||||
<a href={`/user/${this.state.searchResult}`}>
|
<Link to={`/user`}>{result}</Link>
|
||||||
{this.state.searchResult}
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
))
|
||||||
) : (
|
) : (
|
||||||
// console.log(this.state.searchResult)
|
// console.log(this.state.searchResult)
|
||||||
<p> No result </p>
|
<p> searching... </p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -66,11 +65,6 @@ export class Search extends Component {
|
|||||||
onChange={event => this.handleInput(event)}
|
onChange={event => this.handleInput(event)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid>
|
|
||||||
<Button color="primary" onClick={this.handleSearch}>
|
|
||||||
Search
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
<Grid>{resultMarkup}</Grid>
|
<Grid>{resultMarkup}</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
import React, { Component } from "react";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { connect } from "react-redux";
|
|
||||||
import axios from "axios";
|
|
||||||
//import '../App.css';
|
|
||||||
|
|
||||||
// Material UI and React Router
|
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import Card from "@material-ui/core/Card";
|
|
||||||
import CardMedia from "@material-ui/core/CardMedia";
|
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
|
|
||||||
import Chip from "@material-ui/core/Chip";
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import AddCircle from "@material-ui/icons/AddCircle";
|
|
||||||
import TextField from "@material-ui/core/TextField";
|
|
||||||
import VerifiedIcon from "@material-ui/icons/CheckSharp";
|
|
||||||
|
|
||||||
// component
|
|
||||||
import "../App.css";
|
|
||||||
import noImage from "../images/no-img.png";
|
|
||||||
import Writing_Microblogs from "../Writing_Microblogs";
|
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
|
||||||
margin: 2,
|
|
||||||
color: "primary"
|
|
||||||
});
|
|
||||||
|
|
||||||
class user extends Component {
|
|
||||||
state = {
|
|
||||||
profile: window.location.pathname.split("/").pop(),
|
|
||||||
imageUrl: null,
|
|
||||||
topics: null,
|
|
||||||
user: null,
|
|
||||||
following: null
|
|
||||||
};
|
|
||||||
|
|
||||||
handleSub = () => {
|
|
||||||
if (this.state.following === true) {
|
|
||||||
axios
|
|
||||||
.post("/removeSub", {
|
|
||||||
unfollow: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log("removed sub");
|
|
||||||
this.setState({
|
|
||||||
following: false
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
axios
|
|
||||||
.post("/addSubscription", {
|
|
||||||
following: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
console.log("adding sub");
|
|
||||||
this.setState({
|
|
||||||
following: true
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
axios
|
|
||||||
.post("/getUserDetails", {
|
|
||||||
handle: this.state.profile
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
this.setState({
|
|
||||||
imageUrl: res.data.userData.imageUrl,
|
|
||||||
topics: res.data.userData.followedTopics
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
|
|
||||||
axios
|
|
||||||
.get("/user")
|
|
||||||
.then(res => {
|
|
||||||
this.setState({
|
|
||||||
following: res.data.credentials.following.includes(this.state.profile)
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let profileMarkup = this.state.profile ? (
|
|
||||||
<div>
|
|
||||||
<Typography variant="h5">
|
|
||||||
@{this.state.profile}{" "}
|
|
||||||
{this.state.verified ? (
|
|
||||||
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
|
||||||
) : null}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p>loading username...</p>
|
|
||||||
);
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
|
||||||
this.state.topics.map(
|
|
||||||
topic => <MyChip label={topic} key={{ topic }.topic.id} /> // console.log({ topic }.topic.id)
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<p> loading topics...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
|
||||||
<img src={this.state.imageUrl} height="150" width="150" />
|
|
||||||
) : (
|
|
||||||
<img src={noImage} height="150" width="150" />
|
|
||||||
);
|
|
||||||
|
|
||||||
let followMarkup = this.state.following ? (
|
|
||||||
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
|
||||||
unfollow
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Button variant="contained" color="primary" onClick={this.handleSub}>
|
|
||||||
follow
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(this.state.following);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid container spacing={24}>
|
|
||||||
<Grid item sm={4} xs={8}>
|
|
||||||
{imageMarkup}
|
|
||||||
{profileMarkup}
|
|
||||||
{followMarkup}
|
|
||||||
{topicsMarkup}
|
|
||||||
<br />
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
|
||||||
user: state.user
|
|
||||||
});
|
|
||||||
|
|
||||||
user.propTypes = {
|
|
||||||
user: PropTypes.object.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(mapStateToProps)(user);
|
|
||||||
@@ -1,74 +1,33 @@
|
|||||||
/* 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';
|
||||||
//import '../App.css';
|
//import '../App.css';
|
||||||
// Material-UI
|
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
// Material UI and React Router
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
import { makeStyles, styled } from "@material-ui/core/styles";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from 'react-router-dom';
|
||||||
import Card from "@material-ui/core/Card";
|
import Card from "@material-ui/core/Card";
|
||||||
import CardMedia from "@material-ui/core/CardMedia";
|
import CardMedia from '@material-ui/core/CardMedia';
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
import CardContent from '@material-ui/core/CardContent';
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from '@material-ui/core/Button';
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
|
|
||||||
import Chip from "@material-ui/core/Chip";
|
import Chip from "@material-ui/core/Chip";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
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 Paper from "@material-ui/core/Paper";
|
|
||||||
import GridList from "@material-ui/core/GridList";
|
|
||||||
import GridListTile from "@material-ui/core/GridListTile";
|
|
||||||
import GridListTileBar from "@material-ui/core/GridListTileBar";
|
|
||||||
import Container from "@material-ui/core/Container";
|
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import "../App.css";
|
import '../App.css';
|
||||||
import noImage from "../images/no-img.png";
|
import noImage from '../images/no-img.png';
|
||||||
import Writing_Microblogs from "../Writing_Microblogs";
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
|
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: "primary"
|
color: "primary"
|
||||||
});
|
});
|
||||||
|
|
||||||
const styles = {
|
|
||||||
button: {
|
|
||||||
positon: "relative",
|
|
||||||
float: "left",
|
|
||||||
marginLeft: 30,
|
|
||||||
marginTop: 20
|
|
||||||
},
|
|
||||||
paper: {
|
|
||||||
// marginLeft: "10%",
|
|
||||||
// marginRight: "10%"
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
marginBottom: 10
|
|
||||||
},
|
|
||||||
profileImage: {
|
|
||||||
marginTop: 20
|
|
||||||
},
|
|
||||||
topicsContainer: {
|
|
||||||
border: "lightgray solid 1px",
|
|
||||||
marginTop: 20,
|
|
||||||
paddingTop: 10,
|
|
||||||
paddingBottom: 10,
|
|
||||||
height: 300
|
|
||||||
},
|
|
||||||
addCircle: {
|
|
||||||
width: 65,
|
|
||||||
height: 65,
|
|
||||||
marginTop: 10
|
|
||||||
},
|
|
||||||
username: {
|
|
||||||
marginBottom: 100
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class user extends Component {
|
class user extends Component {
|
||||||
state = {
|
state = {
|
||||||
profile: null,
|
profile: null,
|
||||||
@@ -78,11 +37,8 @@ class user extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = topic => {
|
handleDelete = topic => {
|
||||||
console.log(topic);
|
|
||||||
axios
|
axios
|
||||||
.post(`/deleteTopic`, {
|
.delete(`/deleteTopic/${topic.id}`)
|
||||||
unfollow: topic
|
|
||||||
})
|
|
||||||
.then(function() {
|
.then(function() {
|
||||||
location.reload();
|
location.reload();
|
||||||
})
|
})
|
||||||
@@ -94,7 +50,7 @@ class user extends Component {
|
|||||||
handleAddCircle = () => {
|
handleAddCircle = () => {
|
||||||
axios
|
axios
|
||||||
.post("/putTopic", {
|
.post("/putTopic", {
|
||||||
following: this.state.newTopic
|
topic: this.state.newTopic
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
location.reload();
|
location.reload();
|
||||||
@@ -116,11 +72,16 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
profile: res.data.credentials.handle,
|
profile: res.data.credentials.handle,
|
||||||
imageUrl: res.data.credentials.imageUrl,
|
imageUrl: res.data.credentials.imageUrl
|
||||||
verified: res.data.credentials.verified
|
});
|
||||||
? res.data.credentials.verified
|
})
|
||||||
: false,
|
.catch(err => console.log(err));
|
||||||
topics: res.data.credentials.followedTopics
|
|
||||||
|
axios
|
||||||
|
.get("/getAllTopics")
|
||||||
|
.then(res => {
|
||||||
|
this.setState({
|
||||||
|
topics: res.data
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
@@ -128,40 +89,27 @@ class user extends Component {
|
|||||||
axios
|
axios
|
||||||
.get("/getallPostsforUser")
|
.get("/getallPostsforUser")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log(res.data);
|
console.log(res.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
posts: res.data
|
posts: res.data
|
||||||
})
|
})
|
||||||
this.setState({posts: (this.state.posts).sort((a,b) =>
|
|
||||||
-a.createdAt.localeCompare(b.createdAt))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
|
let classes = this.props;
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<div>
|
<p>
|
||||||
<Typography variant="h5" className={classes.username}>
|
<Typography variant='h5'>{this.state.profile}</Typography>
|
||||||
@{this.state.profile}{" "}
|
</p>) : (<p>loading username...</p>);
|
||||||
{this.state.verified ? (
|
|
||||||
<VerifiedIcon style={{ fill: "#1397D5" }} />
|
|
||||||
) : null}
|
|
||||||
</Typography>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p className={classes.username}>loading username...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(
|
||||||
topic => (
|
topic => (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={{ topic }.topic.topic}
|
||||||
key={topic.id}
|
key={{ topic }.topic.id}
|
||||||
onDelete={key => this.handleDelete(topic)}
|
onDelete={key => this.handleDelete(topic)}
|
||||||
/>
|
/>
|
||||||
) // console.log({ topic }.topic.id)
|
) // console.log({ topic }.topic.id)
|
||||||
@@ -170,96 +118,39 @@ class user extends Component {
|
|||||||
<p> loading topics...</p>
|
<p> loading topics...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
|
||||||
<img
|
(<img src={noImage} height="150" width="150"/>);
|
||||||
className={classes.profileImage}
|
|
||||||
src={this.state.imageUrl}
|
|
||||||
height="250"
|
|
||||||
width="250"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<img
|
|
||||||
className={classes.profileImage}
|
|
||||||
src={noImage}
|
|
||||||
height="250"
|
|
||||||
width="250"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
let postMarkup = this.state.posts ? (
|
let postMarkup = this.state.posts ? (
|
||||||
this.state.posts.map(post => (
|
this.state.posts.map(post =>
|
||||||
<Card className={classes.card}>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography>
|
<Typography>
|
||||||
{this.state.imageUrl ? (
|
{
|
||||||
<img src={this.state.imageUrl} height="50" width="50" />
|
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
||||||
) : (
|
(<img src={noImage} height="50" width="50"/>)
|
||||||
<img src={noImage} height="50" width="50" />
|
}
|
||||||
)}
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="h7">
|
|
||||||
<b>{post.userHandle}</b>
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
|
||||||
{post.createdAt}
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
||||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
|
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
||||||
" " + post.createdAt.substring(11,19)}</Typography>
|
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body1">
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
<b>{post.microBlogTitle}</b>
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</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} Comments {post.commentCount}</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
))
|
)
|
||||||
) : (
|
) : (<p>My Posts</p>);
|
||||||
<p>My Posts</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
// FIX: This needs to check if user's profile page being displayed
|
|
||||||
// is the same as the user who is logged in
|
|
||||||
// Can't check for that right now, because this page is always
|
|
||||||
// showing the logged in users profile, instead of retreiving the
|
|
||||||
// profile based on the URL entered
|
|
||||||
let editButtonMarkup = true ? (
|
|
||||||
<Link to="/edit">
|
|
||||||
<Button className={classes.button} variant="outlined" color="primary">
|
|
||||||
Edit Profile
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Grid container spacing={24}>
|
||||||
{/* <Paper className={classes.paper}> */}
|
<Grid item sm={4} xs={8}>
|
||||||
<Grid container direction="column">
|
|
||||||
<Grid item>
|
|
||||||
<Grid container>
|
|
||||||
<Grid item sm>
|
|
||||||
{editButtonMarkup}
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm>
|
|
||||||
{/* <Grid container direction="column"> */}
|
|
||||||
{/* <Grid item sm> */}
|
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
{/* </Grid> */}
|
|
||||||
{/* <Grid item sm> */}
|
|
||||||
{/* {postMarkup} */}
|
|
||||||
{/* </Grid> */}
|
|
||||||
{/* </Grid> */}
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm>
|
|
||||||
<Container className={classes.topicsContainer} maxWidth="xs">
|
|
||||||
{topicsMarkup}
|
{topicsMarkup}
|
||||||
</Container>
|
|
||||||
<TextField
|
<TextField
|
||||||
id="newTopic"
|
id="newTopic"
|
||||||
label="new topic"
|
label="new topic"
|
||||||
@@ -267,38 +158,34 @@ class user extends Component {
|
|||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={this.state.newTopic}
|
value={this.state.newTopic}
|
||||||
onChange={event => this.handleChange(event)}
|
onChange={(event) => this.handleChange(event)}
|
||||||
/>
|
/>
|
||||||
<AddCircle
|
<AddCircle
|
||||||
className={classes.addCircle}
|
|
||||||
color="primary"
|
color="primary"
|
||||||
// iconStyle={classes.addCircle}
|
|
||||||
clickable
|
clickable
|
||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
cursor="pointer"
|
|
||||||
/>
|
/>
|
||||||
|
<br />
|
||||||
|
{authenticated && <Button component={ Link } to='/edit'>Edit Profile Info</Button>}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
{postMarkup}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
<Writing_Microblogs />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item>
|
|
||||||
<Grid container>
|
|
||||||
<Grid item sm />
|
|
||||||
<Grid item>{postMarkup}</Grid>
|
|
||||||
<Grid item sm />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
});
|
})
|
||||||
|
|
||||||
user.propTypes = {
|
user.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired
|
||||||
};
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
export default connect(mapStateToProps)(user);
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
import React, { Component } from "react";
|
|
||||||
import axios from "axios";
|
|
||||||
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
|
|
||||||
|
|
||||||
// Material-UI stuff
|
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
import TextField from "@material-ui/core/TextField";
|
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
|
||||||
|
|
||||||
const styles = {
|
|
||||||
form: {
|
|
||||||
textAlign: "center"
|
|
||||||
},
|
|
||||||
textField: {
|
|
||||||
marginBottom: 30
|
|
||||||
},
|
|
||||||
pageTitle: {
|
|
||||||
// marginTop: 20,
|
|
||||||
marginBottom: 40
|
|
||||||
},
|
|
||||||
button: {
|
|
||||||
positon: "relative",
|
|
||||||
marginBottom: 10
|
|
||||||
},
|
|
||||||
progress: {
|
|
||||||
position: "absolute"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export class verify extends Component {
|
|
||||||
|
|
||||||
// Constructor for the state
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.state = {
|
|
||||||
handle: "",
|
|
||||||
loading: false,
|
|
||||||
errors: {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// // Runs whenever the submit button is clicked.
|
|
||||||
handleSubmit = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
const verifyHandle = {
|
|
||||||
user: this.state.handle
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
|
||||||
.post("/verifyUser", verifyHandle)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res);
|
|
||||||
this.setState({
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
// this.props.history.push('/');
|
|
||||||
// TODO: Need to redirect user to their profile page
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
this.setState({
|
|
||||||
errors: err.response.data,
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Updates the state whenever one of the textboxes changes.
|
|
||||||
// The key is the name of the textbox and the value is the
|
|
||||||
// value in the text box.
|
|
||||||
// Also sets errors to null of textboxes that have been edited
|
|
||||||
handleChange = (event) => {
|
|
||||||
this.setState({
|
|
||||||
[event.target.name]: event.target.value,
|
|
||||||
errors: {
|
|
||||||
[event.target.name]: null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { classes } = this.props;
|
|
||||||
const { errors, loading } = this.state;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid container className={classes.form}>
|
|
||||||
<Grid item sm />
|
|
||||||
<Grid item sm>
|
|
||||||
<Typography variant="h4" className={classes.pageTitle}>
|
|
||||||
Verify Users
|
|
||||||
</Typography>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
|
||||||
<TextField
|
|
||||||
id="handle"
|
|
||||||
name="handle"
|
|
||||||
label="Username"
|
|
||||||
className={classes.textField}
|
|
||||||
value={this.state.handle}
|
|
||||||
// helperText={errors.handle}
|
|
||||||
// error={errors.handle ? true : false}
|
|
||||||
variant="outlined"
|
|
||||||
onChange={this.handleChange}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<Grid container direction="column">
|
|
||||||
<Grid item>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.button}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
{loading && (
|
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<Button
|
|
||||||
variant="oulined"
|
|
||||||
color="primary"
|
|
||||||
// className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/user'
|
|
||||||
>
|
|
||||||
Back to Profile
|
|
||||||
</Button>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</form>
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm />
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
verify.propTypes = {
|
|
||||||
classes: PropTypes.object.isRequired
|
|
||||||
};
|
|
||||||
|
|
||||||
export default withStyles(styles)(verify);
|
|
||||||
Reference in New Issue
Block a user