mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Merge branch 'master' into fix-login-loading
This commit is contained in:
commit
c26ff21b20
@ -1,6 +1,8 @@
|
|||||||
/* 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 = {
|
||||||
@ -12,7 +14,8 @@ exports.putPost = (req, res) => {
|
|||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
admin.firestore().collection('posts').add(newPost)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
@ -30,6 +33,7 @@ exports.putPost = (req, res) => {
|
|||||||
|
|
||||||
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 = [];
|
||||||
@ -39,11 +43,11 @@ exports.getallPostsforUser = (req, res) => {
|
|||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
res.status(200).send("Successfully retrieved all user's posts from database.");
|
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
||||||
return;
|
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
res.status(500).send("Failed to retrieve user's posts from database.", err);
|
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,14 +62,236 @@ exports.getallPosts = (req, res) => {
|
|||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
res.status(200).send("Successfully retrieved every post from database.");
|
return res.status(200).json("Successfully retrieved every post from database.");
|
||||||
return;
|
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
res.status(500).send("Failed to retrieve posts from database.", err);
|
return res.status(500).json("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({
|
||||||
|
quoteId : req.params.postId,
|
||||||
|
userHandle : req.user.handle,
|
||||||
|
quoteBody : req.body.quoteBody
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
const post = {
|
||||||
|
body: quoteData.body,
|
||||||
|
userHandle : req.user.handle,
|
||||||
|
quoteBody: req.body.quoteBody,
|
||||||
|
createdAt : new Date().toISOString(),
|
||||||
|
userImage: req.body.userImage,
|
||||||
|
likeCount: 0,
|
||||||
|
commentCount: 0,
|
||||||
|
userID: req.user.uid,
|
||||||
|
microBlogTitle: quoteData.microBlogTitle,
|
||||||
|
microBlogTopics: quoteData.microBlogTopics,
|
||||||
|
quoteId: req.params.postId
|
||||||
|
}
|
||||||
|
return admin.firestore().collection('posts').add(post)
|
||||||
|
.then((doc) => {
|
||||||
|
doc.update({postId: doc.id})
|
||||||
|
const resPost = post;
|
||||||
|
resPost.postId = doc.id;
|
||||||
|
return res.status(200).json(resPost);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
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({
|
||||||
|
quoteId : req.params.postId,
|
||||||
|
userHandle : req.user.handle,
|
||||||
|
quoteBody: null
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
const post = {
|
||||||
|
userHandle : req.user.handle,
|
||||||
|
body: quoteData.body,
|
||||||
|
quoteBody: null,
|
||||||
|
createdAt : new Date().toISOString(),
|
||||||
|
likeCount: 0,
|
||||||
|
commentCount: 0,
|
||||||
|
userID: req.user.uid,
|
||||||
|
userImage: req.body.userImage,
|
||||||
|
microBlogTitle: quoteData.microBlogTitle,
|
||||||
|
microBlogTopics: quoteData.microBlogTopics,
|
||||||
|
quoteId: req.params.postId
|
||||||
|
}
|
||||||
|
return admin.firestore().collection('posts').add(post)
|
||||||
|
.then((doc) => {
|
||||||
|
doc.update({postId: doc.id})
|
||||||
|
const resPost = post;
|
||||||
|
resPost.postId = doc.id;
|
||||||
|
return res.status(200).json(resPost);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return res.status(400).json({ error: 'Post has already been quoted.' });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
return res.status(500).json({error: 'Something is wrong'});
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.checkforLikePost = (req, res) => {
|
||||||
|
const likedPostDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
|
||||||
|
.where('postId', '==', req.params.postId).limit(1);
|
||||||
|
let result;
|
||||||
|
|
||||||
|
likedPostDoc.get()
|
||||||
|
.then((data) => {
|
||||||
|
if (data.empty) {
|
||||||
|
result = false;
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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', '==')
|
||||||
};
|
};
|
||||||
|
|||||||
@ -331,6 +331,24 @@ 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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.getAuthenticatedUser = (req, res) => {
|
exports.getAuthenticatedUser = (req, res) => {
|
||||||
let credentials = {};
|
let credentials = {};
|
||||||
db.doc(`/users/${req.user.handle}`)
|
db.doc(`/users/${req.user.handle}`)
|
||||||
@ -449,7 +467,7 @@ exports.addSubscription = (req, res) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
return res.status(200).json({ message: "ok" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -489,6 +507,6 @@ exports.removeSub = (req, res) => {
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({ err });
|
return res.status(500).json({ err });
|
||||||
});
|
});
|
||||||
return res.status(500).json({ error: "shouldn't execute" });
|
return res.status(200).json({ message: "ok" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,6 +11,7 @@ app.use(cors());
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const {
|
||||||
getAuthenticatedUser,
|
getAuthenticatedUser,
|
||||||
|
getAllHandles,
|
||||||
getUserDetails,
|
getUserDetails,
|
||||||
getProfileInfo,
|
getProfileInfo,
|
||||||
login,
|
login,
|
||||||
@ -39,6 +40,10 @@ 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);
|
||||||
|
|
||||||
@ -70,7 +75,7 @@ app.post("/removeSub", fbAuth, removeSub);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
@ -79,6 +84,15 @@ 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.get("/checkforLikePost/:postId", fbAuth, checkforLikePost);
|
||||||
|
|
||||||
|
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
|
||||||
|
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
|||||||
@ -10,11 +10,13 @@
|
|||||||
"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",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
"react-dom": "^16.9.0",
|
"react-dom": "^16.9.0",
|
||||||
|
"react-modal": "^3.11.1",
|
||||||
"react-redux": "^7.1.1",
|
"react-redux": "^7.1.1",
|
||||||
"react-router-dom": "^5.1.0",
|
"react-router-dom": "^5.1.0",
|
||||||
"react-scripts": "0.9.5",
|
"react-scripts": "0.9.5",
|
||||||
@ -41,5 +43,5 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,27 @@ 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,68 @@ 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
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
id="content"
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
name="content"
|
||||||
</div>
|
label="Content"
|
||||||
<div style={{ marginRight: "-100px" }}>
|
color="primary"
|
||||||
<button onClick>Share Post</button>
|
className={classes.textField}
|
||||||
</div>
|
value={this.state.value}
|
||||||
</form>
|
helperText={`${this.state.characterCount} characters left`}
|
||||||
</div>
|
multiline
|
||||||
|
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,24 +1,36 @@
|
|||||||
/* 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 Grid from '@material-ui/core/Grid';
|
|
||||||
import Card from '@material-ui/core/Card';
|
|
||||||
import CardContent from '@material-ui/core/CardContent';
|
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||||
|
import Grid from "@material-ui/core/Grid";
|
||||||
|
import Card from "@material-ui/core/Card";
|
||||||
|
import CardContent from "@material-ui/core/CardContent";
|
||||||
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';
|
||||||
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';
|
||||||
|
|
||||||
|
|
||||||
|
const styles = {
|
||||||
|
card: {
|
||||||
|
marginBottom: 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
state = {};
|
state = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
@ -27,41 +39,53 @@ class Home 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 { UI:{ loading } } = this.props;
|
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 postMarkup = this.state.posts ? (
|
let postMarkup = this.state.posts ? (
|
||||||
this.state.posts.map(post =>
|
this.state.posts.map(post =>
|
||||||
<Card>
|
<Card className={classes.card}>
|
||||||
<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"/>)
|
||||||
}
|
}
|
||||||
</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>
|
||||||
|
<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} Comments {post.commentCount}</Typography>
|
{/* <Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography> */}
|
||||||
|
<Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like>
|
||||||
|
<Quote microblog = {post.postId}></Quote>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
) : (<p>My Posts</p>);
|
) : (
|
||||||
|
<p>Loading post...</p>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return authenticated ? (
|
||||||
authenticated ?
|
|
||||||
<Grid container spacing={16}>
|
<Grid container spacing={16}>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
<Writing_Microblogs />
|
<Writing_Microblogs />
|
||||||
@ -100,14 +124,233 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 post = {
|
||||||
|
|
||||||
|
userImage: "bing-url",
|
||||||
|
}
|
||||||
|
const headers = {
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
};
|
||||||
|
axios.post(`/quoteWithoutPost/${this.props.microblog}`, post, headers)
|
||||||
|
.then((res) => {
|
||||||
|
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
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 = {
|
||||||
|
quoteBody: this.state.value,
|
||||||
|
userImage: "bing-url",
|
||||||
|
};
|
||||||
|
const headers = {
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
};
|
||||||
|
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
|
||||||
|
.then((res) => {
|
||||||
|
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
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 = {
|
||||||
|
num : this.props.count,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleClick = this.handleClick.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.setState({
|
||||||
|
like: localStorage.getItem(this.props.microBlog + this.props.name) === "false"
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
handleClick(){
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
like: !this.state.like
|
||||||
|
});
|
||||||
|
localStorage.setItem(this.props.microBlog + this.props.name, this.state.like.toString())
|
||||||
|
|
||||||
|
if(this.state.like == false)
|
||||||
|
{
|
||||||
|
this.setState(() => {
|
||||||
|
return {num: this.state.num + 1}
|
||||||
|
});
|
||||||
|
axios.get(`/like/${this.props.microBlog}`)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setState(() => {
|
||||||
|
return {num: this.state.num - 1}
|
||||||
|
});
|
||||||
|
axios.get(`/unlike/${this.props.microBlog}`)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* componentDidMount() {
|
||||||
|
axios.get(`/checkforLikePost/${this.props.microBlog}`)
|
||||||
|
.then((res) => {
|
||||||
|
this.setState({
|
||||||
|
like2: res.data
|
||||||
|
})
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
if (this.state.like2 === this.state.like)
|
||||||
|
{
|
||||||
|
this.setState({
|
||||||
|
like: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
|
render() {
|
||||||
|
|
||||||
|
const label = this.state.like ? 'Unlike' : 'Like'
|
||||||
|
return(
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>Likes {this.state.num}</Typography>
|
||||||
|
<button onClick={this.handleClick}>{label}</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
user: state.user,
|
user: state.user,
|
||||||
UI: state.UI
|
UI: state.UI
|
||||||
})
|
});
|
||||||
|
|
||||||
Home.propTypes = {
|
Home.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
|
clases: PropTypes.object.isRequired,
|
||||||
UI: PropTypes.object.isRequired
|
UI: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(Home);
|
Like.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
Quote.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(withStyles(styles)(Home, Like, Quote));
|
||||||
|
|||||||
@ -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"
|
||||||
|
|||||||
@ -2,38 +2,75 @@ import React, { Component } from "react";
|
|||||||
// import props
|
// import props
|
||||||
import { TextField, Button } from "@material-ui/core";
|
import { TextField, Button } 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 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,38 +78,49 @@ 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>
|
||||||
<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>
|
this.state.loading
|
||||||
|
?
|
||||||
|
<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>
|
||||||
|
:
|
||||||
<Grid>
|
<Grid>
|
||||||
<TextField
|
<Grid>
|
||||||
id="standard-required"
|
<TextField
|
||||||
label="Search"
|
id="standard-required"
|
||||||
defaultValue="username"
|
label="Username"
|
||||||
margin="normal"
|
margin="normal"
|
||||||
value={this.state.searchPhase}
|
// value={this.state.searchPhrase}
|
||||||
onChange={event => this.handleInput(event)}
|
onChange={this.handleChange}
|
||||||
/>
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid>
|
||||||
|
{/* <Button color="primary" onClick={this.handleSearch}>
|
||||||
|
Search
|
||||||
|
</Button> */}
|
||||||
|
</Grid>
|
||||||
|
<Grid>{resultMarkup}</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid>
|
|
||||||
<Button color="primary" onClick={this.handleSearch}>
|
|
||||||
Search
|
|
||||||
</Button>
|
|
||||||
</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>
|
||||||
|
|||||||
@ -28,6 +28,14 @@ const styles = {
|
|||||||
positon: "relative",
|
positon: "relative",
|
||||||
marginBottom: 30
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
|
back: {
|
||||||
|
float: "left",
|
||||||
|
marginLeft: 15
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
float: "right",
|
||||||
|
marginRight: 15
|
||||||
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
}
|
}
|
||||||
@ -135,7 +143,17 @@ export class edit extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container className={classes.form}>
|
<Grid container className={classes.form}>
|
||||||
<Grid item sm />
|
<Grid item sm >
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="primary"
|
||||||
|
className={classes.back}
|
||||||
|
component={ Link }
|
||||||
|
to='/user'
|
||||||
|
>
|
||||||
|
Back to Profile
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<Typography variant="h2" className={classes.pageTitle}>
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
Edit Profile
|
Edit Profile
|
||||||
@ -154,6 +172,7 @@ export class edit extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
@ -168,6 +187,7 @@ export class edit extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -185,6 +205,7 @@ export class edit extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="handle"
|
id="handle"
|
||||||
@ -200,6 +221,7 @@ export class edit extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
id="bio"
|
id="bio"
|
||||||
@ -214,6 +236,7 @@ export class edit extends Component {
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
autoComplete='off'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
@ -229,29 +252,20 @@ export class edit extends Component {
|
|||||||
<CircularProgress size={30} className={classes.progress} />
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
//variant="contained"
|
|
||||||
color="primary"
|
|
||||||
className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/user'
|
|
||||||
>
|
|
||||||
Back to Profile
|
|
||||||
</Button>
|
|
||||||
<br />
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
className={classes.button}
|
|
||||||
component={ Link }
|
|
||||||
to='/delete'
|
|
||||||
>
|
|
||||||
Delete Account
|
|
||||||
</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
<Grid item sm>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="secondary"
|
||||||
|
className={classes.delete}
|
||||||
|
component={ Link }
|
||||||
|
to='/delete'
|
||||||
|
>
|
||||||
|
Delete Account
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const styles = {
|
|||||||
// marginRight: "10%"
|
// marginRight: "10%"
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
marginBottom: 10
|
marginBottom: 5
|
||||||
},
|
},
|
||||||
profileImage: {
|
profileImage: {
|
||||||
marginTop: 20
|
marginTop: 20
|
||||||
@ -70,12 +70,15 @@ const styles = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class user extends Component {
|
class user extends Component {
|
||||||
state = {
|
constructor() {
|
||||||
profile: null,
|
super();
|
||||||
imageUrl: null,
|
this.state = {
|
||||||
topics: null,
|
profile: null,
|
||||||
newTopic: null
|
imageUrl: null,
|
||||||
};
|
topics: null,
|
||||||
|
newTopic: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
handleDelete = topic => {
|
handleDelete = topic => {
|
||||||
console.log(topic);
|
console.log(topic);
|
||||||
@ -83,8 +86,16 @@ class user extends Component {
|
|||||||
.post(`/deleteTopic`, {
|
.post(`/deleteTopic`, {
|
||||||
unfollow: topic
|
unfollow: topic
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(() => {
|
||||||
location.reload();
|
let tempTopics = this.state.topics;
|
||||||
|
tempTopics.forEach((oldTopic, index) => {
|
||||||
|
if (oldTopic === topic) {
|
||||||
|
tempTopics.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setState({
|
||||||
|
topics: tempTopics
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -96,8 +107,13 @@ class user extends Component {
|
|||||||
.post("/putTopic", {
|
.post("/putTopic", {
|
||||||
following: this.state.newTopic
|
following: this.state.newTopic
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(() => {
|
||||||
location.reload();
|
let tempTopics = this.state.topics;
|
||||||
|
tempTopics.push(this.state.newTopic);
|
||||||
|
this.setState({
|
||||||
|
topics: tempTopics,
|
||||||
|
newTopic: ""
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -131,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;
|
||||||
@ -200,19 +221,20 @@ class user extends Component {
|
|||||||
<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>
|
||||||
|
|
||||||
|
<br />
|
||||||
<Typography variant="body2">{post.body}</Typography>
|
<Typography variant="body2">{post.body}</Typography>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2">
|
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
||||||
<b>Topics:</b> {post.microBlogTopics}
|
|
||||||
</Typography>
|
|
||||||
<br />
|
<br />
|
||||||
<Typography variant="body2" color={"textSecondary"}>
|
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||||
Likes {post.likeCount} Comments {post.commentCount}
|
|
||||||
</Typography>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
))
|
))
|
||||||
@ -295,7 +317,8 @@ const mapStateToProps = state => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
user.propTypes = {
|
user.propTypes = {
|
||||||
user: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired,
|
||||||
|
clases: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user