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 promise/always-return */
|
||||
const admin = require('firebase-admin');
|
||||
const { db } = require('../util/admin');
|
||||
|
||||
|
||||
exports.putPost = (req, res) => {
|
||||
const newPost = {
|
||||
@ -12,7 +14,8 @@ exports.putPost = (req, res) => {
|
||||
createdAt: new Date().toISOString(),
|
||||
likeCount: 0,
|
||||
commentCount: 0,
|
||||
microBlogTopics: req.body.microBlogTopics
|
||||
microBlogTopics: req.body.microBlogTopics,
|
||||
quoteBody: null
|
||||
};
|
||||
|
||||
admin.firestore().collection('posts').add(newPost)
|
||||
@ -30,6 +33,7 @@ exports.putPost = (req, res) => {
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||
|
||||
post_query.get()
|
||||
.then(function(myPosts) {
|
||||
let posts = [];
|
||||
@ -39,11 +43,11 @@ exports.getallPostsforUser = (req, res) => {
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||
return;
|
||||
return res.status(200).json("Successfully retrieved all user's posts from database.");
|
||||
|
||||
})
|
||||
.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);
|
||||
})
|
||||
.then(function() {
|
||||
res.status(200).send("Successfully retrieved every post from database.");
|
||||
return;
|
||||
return res.status(200).json("Successfully retrieved every post from database.");
|
||||
})
|
||||
.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) => {
|
||||
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) => {
|
||||
let credentials = {};
|
||||
db.doc(`/users/${req.user.handle}`)
|
||||
@ -449,7 +467,7 @@ exports.addSubscription = (req, res) => {
|
||||
.catch(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 => {
|
||||
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 {
|
||||
getAuthenticatedUser,
|
||||
getAllHandles,
|
||||
getUserDetails,
|
||||
getProfileInfo,
|
||||
login,
|
||||
@ -39,6 +40,10 @@ app.delete("/delete", fbAuth, deleteUser);
|
||||
|
||||
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
|
||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||
|
||||
@ -70,7 +75,7 @@ app.post("/removeSub", fbAuth, removeSub);
|
||||
/*------------------------------------------------------------------*
|
||||
* 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);
|
||||
|
||||
@ -79,6 +84,15 @@ app.get("/getallPosts", getallPosts);
|
||||
// Adds one post to the database
|
||||
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 *
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
@ -10,11 +10,13 @@
|
||||
"axios": "^0.19.0",
|
||||
"clsx": "^1.0.4",
|
||||
"create-react-app": "^3.1.2",
|
||||
"fuse.js": "^3.4.6",
|
||||
"install": "^0.13.0",
|
||||
"jwt-decode": "^2.2.0",
|
||||
"node-pre-gyp": "^0.13.0",
|
||||
"react": "^16.9.0",
|
||||
"react-dom": "^16.9.0",
|
||||
"react-modal": "^3.11.1",
|
||||
"react-redux": "^7.1.1",
|
||||
"react-router-dom": "^5.1.0",
|
||||
"react-scripts": "0.9.5",
|
||||
@ -41,5 +43,5 @@
|
||||
"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 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 {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -27,7 +48,7 @@ class Writing_Microblogs extends Component {
|
||||
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);
|
||||
const postData = {
|
||||
body: this.state.value,
|
||||
@ -40,20 +61,34 @@ class Writing_Microblogs extends Component {
|
||||
};
|
||||
|
||||
axios
|
||||
.post("/putPost", postData, headers)
|
||||
.post("/putPost", postData, headers) // TODO: add topics
|
||||
.then(res => {
|
||||
alert("Post was shared successfully!");
|
||||
// alert("Post was shared successfully!");
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
alert("An error occured.");
|
||||
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();
|
||||
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
||||
}
|
||||
|
||||
handleChangeforPost(event) {
|
||||
|
||||
this.setState({ value: event.target.value });
|
||||
}
|
||||
|
||||
@ -64,65 +99,68 @@ class Writing_Microblogs extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
width: "200px",
|
||||
height: "50px",
|
||||
marginTop: "180px",
|
||||
marginLeft: "50px"
|
||||
}}
|
||||
>
|
||||
<form>
|
||||
<textarea
|
||||
placeholder="Enter Microblog Title"
|
||||
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 className={classes.container}>
|
||||
<form noValidate className={classes.form}>
|
||||
<TextField
|
||||
id="title"
|
||||
name="title"
|
||||
label="Title"
|
||||
className={classes.textField}
|
||||
value={this.state.title}
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
|
||||
<div style={{ width: "200px", marginLeft: "50px" }}>
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<textarea
|
||||
value={this.state.value}
|
||||
required
|
||||
maxLength="250"
|
||||
placeholder="Write Microblog 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>
|
||||
<div style={{ marginRight: "-100px" }}>
|
||||
<button onClick>Share Post</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<TextField
|
||||
id="topics"
|
||||
name="topics"
|
||||
label="Topics"
|
||||
className={classes.textField}
|
||||
value={this.state.topics}
|
||||
variant="outlined"
|
||||
onChange={this.handleChangeforTopics}
|
||||
color="primary"
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
|
||||
<TextField
|
||||
id="content"
|
||||
name="content"
|
||||
label="Content"
|
||||
color="primary"
|
||||
className={classes.textField}
|
||||
value={this.state.value}
|
||||
helperText={`${this.state.characterCount} characters left`}
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Writing_Microblogs;
|
||||
export default withStyles(styles)(Writing_Microblogs);
|
||||
|
||||
@ -1,24 +1,36 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import axios from 'axios';
|
||||
import React, { Component } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { connect } from "react-redux";
|
||||
import axios from "axios";
|
||||
|
||||
// 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 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 withStyles from '@material-ui/styles/withStyles';
|
||||
|
||||
// component
|
||||
import '../App.css';
|
||||
import logo from '../images/twistter-logo.png';
|
||||
import noImage from '../images/no-img.png';
|
||||
import Writing_Microblogs from '../Writing_Microblogs';
|
||||
import ReactModal from 'react-modal';
|
||||
|
||||
|
||||
const styles = {
|
||||
card: {
|
||||
marginBottom: 5
|
||||
}
|
||||
}
|
||||
|
||||
class Home extends Component {
|
||||
state = {};
|
||||
state = {
|
||||
|
||||
};
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
axios
|
||||
@ -27,41 +39,53 @@ class Home extends Component {
|
||||
console.log(res.data);
|
||||
this.setState({
|
||||
posts: res.data
|
||||
})
|
||||
});
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
}
|
||||
|
||||
formatDate(dateString) {
|
||||
let newDate = new Date(Date.parse(dateString));
|
||||
return newDate.toDateString();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { UI:{ loading } } = this.props;
|
||||
let authenticated = this.props.user.authenticated;
|
||||
let {classes} = this.props;
|
||||
let username = this.props.user.credentials.handle;
|
||||
|
||||
let postMarkup = this.state.posts ? (
|
||||
this.state.posts.map(post =>
|
||||
<Card>
|
||||
<Card className={classes.card}>
|
||||
<CardContent>
|
||||
<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"/>)
|
||||
}
|
||||
</Typography>
|
||||
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
||||
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
||||
<br />
|
||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} 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>
|
||||
</Card>
|
||||
)
|
||||
) : (<p>My Posts</p>);
|
||||
) : (
|
||||
<p>Loading post...</p>
|
||||
);
|
||||
|
||||
return (
|
||||
authenticated ?
|
||||
return authenticated ? (
|
||||
<Grid container spacing={16}>
|
||||
<Grid item sm={4} xs={8}>
|
||||
<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) => ({
|
||||
user: state.user,
|
||||
UI: state.UI
|
||||
})
|
||||
});
|
||||
|
||||
Home.propTypes = {
|
||||
user: PropTypes.object.isRequired,
|
||||
clases: 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
|
||||
id="email"
|
||||
name="email"
|
||||
label="Email*"
|
||||
label="Email or Username*"
|
||||
className={classes.textField}
|
||||
value={this.state.email}
|
||||
helperText={errors.email}
|
||||
@ -127,6 +127,7 @@ export class Login extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="password"
|
||||
@ -140,6 +141,7 @@ export class Login extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
|
||||
@ -2,38 +2,75 @@ import React, { Component } from "react";
|
||||
// import props
|
||||
import { TextField, Button } from "@material-ui/core";
|
||||
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 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 {
|
||||
state = {
|
||||
searchPhase: null,
|
||||
searchResult: null
|
||||
handles: [],
|
||||
// searchPhrase: null,
|
||||
searchResult: null,
|
||||
loading: false
|
||||
};
|
||||
|
||||
handleSearch = () => {
|
||||
console.log(this.state.searchPhase);
|
||||
Axios.post("/getUserHandles", {
|
||||
userHandle: this.state.searchPhase
|
||||
})
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
|
||||
this.setState({
|
||||
searchResult: res.data
|
||||
});
|
||||
componentDidMount() {
|
||||
this.setState({loading: true});
|
||||
axios.get("/getAllHandles")
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
handles: res.data,
|
||||
loading: false
|
||||
}, () => {
|
||||
console.log(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({
|
||||
searchPhase: event.target.value
|
||||
});
|
||||
console.log(this.state.searchPhase);
|
||||
searchResult: parsed.length !== 0 ? parsed : "No Results"
|
||||
})
|
||||
}
|
||||
|
||||
handleRedirect() {
|
||||
@ -41,38 +78,49 @@ export class Search extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
let resultMarkup = this.state.searchResult ? (
|
||||
<Router>
|
||||
<div>
|
||||
<a href={`/user/${this.state.searchResult}`}>
|
||||
{this.state.searchResult}
|
||||
</a>
|
||||
</div>
|
||||
</Router>
|
||||
) : (
|
||||
// console.log(this.state.searchResult)
|
||||
<p> No result </p>
|
||||
);
|
||||
let resultMarkup = this.state.searchResult && this.state.searchResult !== "No Results" ? (
|
||||
this.state.searchResult.map(res =>
|
||||
<Router>
|
||||
<div>
|
||||
<a href={`/user/${res}`}>
|
||||
{res}
|
||||
</a>
|
||||
</div>
|
||||
</Router>
|
||||
)
|
||||
)
|
||||
:
|
||||
this.state.searchResult === "No Results" ?
|
||||
(
|
||||
<p> No results </p>
|
||||
)
|
||||
:
|
||||
(
|
||||
null
|
||||
)
|
||||
|
||||
return (
|
||||
<Grid>
|
||||
this.state.loading
|
||||
?
|
||||
<CircularProgress size={60} style={{marginTop: "300px"}}></CircularProgress>
|
||||
:
|
||||
<Grid>
|
||||
<TextField
|
||||
id="standard-required"
|
||||
label="Search"
|
||||
defaultValue="username"
|
||||
margin="normal"
|
||||
value={this.state.searchPhase}
|
||||
onChange={event => this.handleInput(event)}
|
||||
/>
|
||||
<Grid>
|
||||
<TextField
|
||||
id="standard-required"
|
||||
label="Username"
|
||||
margin="normal"
|
||||
// value={this.state.searchPhrase}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
{/* <Button color="primary" onClick={this.handleSearch}>
|
||||
Search
|
||||
</Button> */}
|
||||
</Grid>
|
||||
<Grid>{resultMarkup}</Grid>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<Button color="primary" onClick={this.handleSearch}>
|
||||
Search
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid>{resultMarkup}</Grid>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,6 +122,7 @@ export class Signup extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="email"
|
||||
@ -134,6 +135,7 @@ export class Signup extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="password"
|
||||
@ -147,6 +149,7 @@ export class Signup extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="confirmPassword"
|
||||
@ -160,6 +163,7 @@ export class Signup extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<br></br>
|
||||
<br></br>
|
||||
|
||||
@ -28,6 +28,14 @@ const styles = {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
},
|
||||
back: {
|
||||
float: "left",
|
||||
marginLeft: 15
|
||||
},
|
||||
delete: {
|
||||
float: "right",
|
||||
marginRight: 15
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
}
|
||||
@ -135,7 +143,17 @@ export class edit extends Component {
|
||||
|
||||
return (
|
||||
<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>
|
||||
<Typography variant="h2" className={classes.pageTitle}>
|
||||
Edit Profile
|
||||
@ -154,6 +172,7 @@ export class edit extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item sm>
|
||||
@ -168,6 +187,7 @@ export class edit extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
@ -185,6 +205,7 @@ export class edit extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="handle"
|
||||
@ -200,6 +221,7 @@ export class edit extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<TextField
|
||||
id="bio"
|
||||
@ -214,6 +236,7 @@ export class edit extends Component {
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
autoComplete='off'
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
@ -229,29 +252,20 @@ export class edit extends Component {
|
||||
<CircularProgress size={30} className={classes.progress} />
|
||||
)}
|
||||
</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>
|
||||
</Grid>
|
||||
<Grid item sm />
|
||||
<Grid item sm>
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="secondary"
|
||||
className={classes.delete}
|
||||
component={ Link }
|
||||
to='/delete'
|
||||
>
|
||||
Delete Account
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ const styles = {
|
||||
// marginRight: "10%"
|
||||
},
|
||||
card: {
|
||||
marginBottom: 10
|
||||
marginBottom: 5
|
||||
},
|
||||
profileImage: {
|
||||
marginTop: 20
|
||||
@ -70,12 +70,15 @@ const styles = {
|
||||
};
|
||||
|
||||
class user extends Component {
|
||||
state = {
|
||||
profile: null,
|
||||
imageUrl: null,
|
||||
topics: null,
|
||||
newTopic: null
|
||||
};
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
profile: null,
|
||||
imageUrl: null,
|
||||
topics: null,
|
||||
newTopic: null
|
||||
};
|
||||
}
|
||||
|
||||
handleDelete = topic => {
|
||||
console.log(topic);
|
||||
@ -83,8 +86,16 @@ class user extends Component {
|
||||
.post(`/deleteTopic`, {
|
||||
unfollow: topic
|
||||
})
|
||||
.then(function() {
|
||||
location.reload();
|
||||
.then(() => {
|
||||
let tempTopics = this.state.topics;
|
||||
tempTopics.forEach((oldTopic, index) => {
|
||||
if (oldTopic === topic) {
|
||||
tempTopics.splice(index, 1);
|
||||
}
|
||||
});
|
||||
this.setState({
|
||||
topics: tempTopics
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
@ -96,8 +107,13 @@ class user extends Component {
|
||||
.post("/putTopic", {
|
||||
following: this.state.newTopic
|
||||
})
|
||||
.then(function() {
|
||||
location.reload();
|
||||
.then(() => {
|
||||
let tempTopics = this.state.topics;
|
||||
tempTopics.push(this.state.newTopic);
|
||||
this.setState({
|
||||
topics: tempTopics,
|
||||
newTopic: ""
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
@ -131,11 +147,16 @@ class user extends Component {
|
||||
// console.log(res.data);
|
||||
this.setState({
|
||||
posts: res.data
|
||||
});
|
||||
})
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
}
|
||||
|
||||
formatDate(dateString) {
|
||||
let newDate = new Date(Date.parse(dateString));
|
||||
return newDate.toDateString();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
let authenticated = this.props.user.authenticated;
|
||||
@ -200,19 +221,20 @@ class user extends Component {
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
{post.createdAt}
|
||||
</Typography>
|
||||
|
||||
|
||||
<br />
|
||||
<Typography variant="body1">
|
||||
<b>{post.microBlogTitle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||
|
||||
<br />
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">
|
||||
<b>Topics:</b> {post.microBlogTopics}
|
||||
</Typography>
|
||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
Likes {post.likeCount} Comments {post.commentCount}
|
||||
</Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))
|
||||
@ -295,7 +317,8 @@ const mapStateToProps = state => ({
|
||||
});
|
||||
|
||||
user.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
user: PropTypes.object.isRequired,
|
||||
clases: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user