From 6db14e38683c18559a0d86462b8c285a1e10ec45 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Tue, 29 Oct 2019 19:39:11 -0400 Subject: [PATCH 1/7] Improved the profile page format --- .../src/components/layout/NavBar.js | 6 ++--- twistter-frontend/src/pages/editProfile.js | 23 +++++++++++++++++++ twistter-frontend/src/pages/user.js | 20 ++++++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/twistter-frontend/src/components/layout/NavBar.js b/twistter-frontend/src/components/layout/NavBar.js index 38434b5..0c5971f 100644 --- a/twistter-frontend/src/components/layout/NavBar.js +++ b/twistter-frontend/src/components/layout/NavBar.js @@ -41,6 +41,9 @@ export class Navbar extends Component { + {authenticated && } {!authenticated && } @@ -50,9 +53,6 @@ export class Navbar extends Component { {authenticated && } - {authenticated && } ) diff --git a/twistter-frontend/src/pages/editProfile.js b/twistter-frontend/src/pages/editProfile.js index ff6f3f7..0a31271 100644 --- a/twistter-frontend/src/pages/editProfile.js +++ b/twistter-frontend/src/pages/editProfile.js @@ -6,6 +6,7 @@ import PropTypes from "prop-types"; // 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"; @@ -220,12 +221,34 @@ export class edit extends Component { color="primary" className={classes.button} disabled={loading} + //component={ Link } + //to='/user' > Submit {loading && ( )} +
+ +
+ diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 27a0c94..7633295 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -3,10 +3,12 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import axios from 'axios'; //import '../App.css'; +import { Link } from 'react-router-dom'; import { makeStyles, styled } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; import Chip from '@material-ui/core/Chip'; +import Button from '@material-ui/core/Button'; import Typography from "@material-ui/core/Typography"; import AddCircle from '@material-ui/icons/AddCircle'; import TextField from '@material-ui/core/TextField'; @@ -14,6 +16,7 @@ import TextField from '@material-ui/core/TextField'; // component import Userline from '../Userline'; import noImage from '../images/no-img.png'; +import Writing_Microblogs from '../Writing_Microblogs'; const MyChip = styled(Chip)({ margin: 2, @@ -71,6 +74,7 @@ class user extends Component { } render() { const classes = this.props; + //const authenticated = this.props.user.authenticated; let profileMarkup = this.state.profile ? (

{this.state.profile} @@ -93,11 +97,8 @@ class user extends Component { ) : (); return ( - - -

Post

-
- + + {imageMarkup} {profileMarkup} {topicsMarkup} @@ -115,6 +116,15 @@ class user extends Component { clickable onClick={this.handleAddCircle} /> +
+ + {/*authenticated && */} +
+ + + + +

Post

); From 8438ce27cf4648a8264e043c8e6dceb457dd0698 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Tue, 29 Oct 2019 22:25:38 -0400 Subject: [PATCH 2/7] Get user's posts works now --- functions/handlers/post.js | 16 ++++++++++------ functions/handlers/users.js | 1 - functions/index.js | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index dc88e45..83f9558 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -27,16 +27,20 @@ exports.putPost = (req, res) => { }; exports.getallPostsforUser = (req, res) => { - admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get() - .then((data) => { + var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle); + post_query.get() + .then(function(myPosts) { let posts = []; - data.forEach(function(doc) { + myPosts.forEach(function(doc) { posts.push(doc.data()); }); return res.status(200).json(posts); }) - .catch((err) => { - console.error(err); - return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) + .then(function() { + res.status(200).send("Successfully retrieved all user's posts from database."); + return; }) + .catch(function(err) { + res.status(500).send("Failed to retrieve all user's posts from database.", err); + }); }; diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 203aa58..b455b02 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -1,5 +1,4 @@ /* eslint-disable promise/catch-or-return */ - const { admin, db } = require("../util/admin"); const config = require("../util/config"); const { validateUpdateProfileInfo } = require("../util/validator"); diff --git a/functions/index.js b/functions/index.js index 33ce166..dfb27f3 100644 --- a/functions/index.js +++ b/functions/index.js @@ -47,7 +47,7 @@ app.get("/user", fbAuth, getAuthenticatedUser); const { getallPostsforUser, putPost } = require("./handlers/post"); -app.get("/getallPostsforUser", getallPostsforUser); +app.get("/getallPostsforUser", fbAuth, getallPostsforUser); // Adds one post to the database app.post("/putPost", fbAuth, putPost); From cd19364efca57d24eb9840356418f80cad7b5dfa Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 30 Oct 2019 11:40:44 -0400 Subject: [PATCH 3/7] Can now display post body on profile page --- twistter-frontend/src/pages/user.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 7633295..af0243c 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -63,6 +63,7 @@ class user extends Component { }); }) .catch(err => console.log(err)); + axios .get("/getAllTopics") .then(res => { @@ -71,16 +72,25 @@ class user extends Component { }) }) .catch(err => console.log(err)); + + axios + .get("/getallPostsforUser") + .then(res => { + console.log(res.data); + this.setState({ + posts: res.data + }) + }) + .catch(err => console.log(err)); } + render() { const classes = this.props; - //const authenticated = this.props.user.authenticated; let profileMarkup = this.state.profile ? (

{this.state.profile}

) : (

loading username...

); - let topicsMarkup = this.state.topics ? ( this.state.topics.map(topic => ) : (); + let postMarkup = this.state.posts ? ( + this.state.posts.map(post =>

{post.body}

) + ) : (

My Posts

); + return ( @@ -118,13 +132,12 @@ class user extends Component { />
- {/*authenticated && */}
-

Post

+ {postMarkup}
); From 1337071bec2a1c1f97652d23699b15f5a4f14c65 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 30 Oct 2019 15:07:19 -0400 Subject: [PATCH 4/7] UI can now display all features of a post --- twistter-frontend/src/pages/user.js | 12 +++++++- twistter-frontend/src/util/PostSkeleton.js | 36 ++++++++++------------ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index af0243c..b9e7247 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -17,6 +17,7 @@ import TextField from '@material-ui/core/TextField'; import Userline from '../Userline'; import noImage from '../images/no-img.png'; import Writing_Microblogs from '../Writing_Microblogs'; +import PostSkeleton from '../util/PostSkeleton'; const MyChip = styled(Chip)({ margin: 2, @@ -107,7 +108,16 @@ class user extends Component { ) : (); let postMarkup = this.state.posts ? ( - this.state.posts.map(post =>

{post.body}

) + this.state.posts.map(post => +

+ {imageMarkup}
+ {post.userHandle}
+ {post.createdAt}
+ {post.microBlogTitle}
+ {post.body}
+ {post.microBlogTopics}
+ Likes {post.likeCount} Comments {post.commentCount}
+

) ) : (

My Posts

); return ( diff --git a/twistter-frontend/src/util/PostSkeleton.js b/twistter-frontend/src/util/PostSkeleton.js index ff14e16..25cbac5 100644 --- a/twistter-frontend/src/util/PostSkeleton.js +++ b/twistter-frontend/src/util/PostSkeleton.js @@ -1,12 +1,12 @@ /* eslint-disable */ -import React, { Fragment } from 'react'; +import React, { Component } from 'react'; import NoImg from '../images/no-img.png'; import PropTypes from 'prop-types'; // MUI import Card from '@material-ui/core/Card'; import CardMedia from '@material-ui/core/CardMedia'; import CardContent from '@material-ui/core/CardContent'; - +import Typography from '@material-ui/core/Typography'; import withStyles from '@material-ui/core/styles/withStyles'; const styles = (theme) => ({ @@ -50,23 +50,20 @@ const styles = (theme) => ({ } }); -const PostSkeleton = (props) => { - const { classes } = props; - - const content = Array.from({ length: 5 }).map((item, index) => ( - - - -
-
-
-
-
- - - )); - - return {content}; +class PostSkeleton extends Component { + render() { + const { classes, post: { body, createdAt, userImage, userHandle, screamId, likeCount, commentCount } } = this.props; + return ( + + + + {userHandle} + {createdAt} + {body} + + + ); + }; }; PostSkeleton.propTypes = { @@ -74,4 +71,3 @@ PostSkeleton.propTypes = { }; export default withStyles(styles)(PostSkeleton); - From a61c296ddf1a2eeb6715ce8da1dff2135afc32f4 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 30 Oct 2019 16:12:53 -0400 Subject: [PATCH 5/7] Made the posts look prettier --- twistter-frontend/src/pages/user.js | 47 +++++++++++++--------- twistter-frontend/src/util/PostSkeleton.js | 36 +++++++++-------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index b9e7247..75f1703 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -7,6 +7,8 @@ import { Link } from 'react-router-dom'; import { makeStyles, styled } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; +import CardMedia from '@material-ui/core/CardMedia'; +import CardContent from '@material-ui/core/CardContent'; import Chip from '@material-ui/core/Chip'; import Button from '@material-ui/core/Button'; import Typography from "@material-ui/core/Typography"; @@ -17,7 +19,6 @@ import TextField from '@material-ui/core/TextField'; import Userline from '../Userline'; import noImage from '../images/no-img.png'; import Writing_Microblogs from '../Writing_Microblogs'; -import PostSkeleton from '../util/PostSkeleton'; const MyChip = styled(Chip)({ margin: 2, @@ -99,25 +100,31 @@ class user extends Component { onDelete={ (topic) => this.handleDelete(topic)}/>) ) : (

loading topics...

); - let imageMarkup = this.state.imageUrl ? ( - - ) : (); + let imageMarkup = this.state.imageUrl ? () : + (); let postMarkup = this.state.posts ? ( this.state.posts.map(post => -

- {imageMarkup}
- {post.userHandle}
- {post.createdAt}
- {post.microBlogTitle}
- {post.body}
- {post.microBlogTopics}
- Likes {post.likeCount} Comments {post.commentCount}
-

) + + + + { + this.state.imageUrl ? () : + () + } + + {post.userHandle} + {post.createdAt} +
+ {post.microBlogTitle} + {post.body} +
+ Topics: {post.microBlogTopics} +
+ Likes {post.likeCount} Comments {post.commentCount} +
+
+ ) ) : (

My Posts

); return ( @@ -133,7 +140,7 @@ class user extends Component { margin="normal" variant="outlined" value={this.state.newTopic} - onChange={ (event) => this.handleChange(event)} + onChange={(event) => this.handleChange(event)} /> Edit Profile Info - + {postMarkup} - {postMarkup} + ); diff --git a/twistter-frontend/src/util/PostSkeleton.js b/twistter-frontend/src/util/PostSkeleton.js index 25cbac5..ff14e16 100644 --- a/twistter-frontend/src/util/PostSkeleton.js +++ b/twistter-frontend/src/util/PostSkeleton.js @@ -1,12 +1,12 @@ /* eslint-disable */ -import React, { Component } from 'react'; +import React, { Fragment } from 'react'; import NoImg from '../images/no-img.png'; import PropTypes from 'prop-types'; // MUI import Card from '@material-ui/core/Card'; import CardMedia from '@material-ui/core/CardMedia'; import CardContent from '@material-ui/core/CardContent'; -import Typography from '@material-ui/core/Typography'; + import withStyles from '@material-ui/core/styles/withStyles'; const styles = (theme) => ({ @@ -50,20 +50,23 @@ const styles = (theme) => ({ } }); -class PostSkeleton extends Component { - render() { - const { classes, post: { body, createdAt, userImage, userHandle, screamId, likeCount, commentCount } } = this.props; - return ( - - - - {userHandle} - {createdAt} - {body} - - - ); - }; +const PostSkeleton = (props) => { + const { classes } = props; + + const content = Array.from({ length: 5 }).map((item, index) => ( + + + +
+
+
+
+
+ + + )); + + return {content}; }; PostSkeleton.propTypes = { @@ -71,3 +74,4 @@ PostSkeleton.propTypes = { }; export default withStyles(styles)(PostSkeleton); + From 26afabe7095377dbd3e15fee3e2d7623e090c694 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 30 Oct 2019 18:04:35 -0400 Subject: [PATCH 6/7] All posts from db can now show on home page timeline --- functions/handlers/post.js | 23 +++++- functions/index.js | 5 +- twistter-frontend/src/App.js | 19 ++--- .../src/components/layout/NavBar.js | 6 +- twistter-frontend/src/pages/Home.js | 78 ++++++++++++++++++- twistter-frontend/src/pages/user.js | 21 +++-- 6 files changed, 123 insertions(+), 29 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 83f9558..48fbbcc 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -22,7 +22,7 @@ exports.putPost = (req, res) => { }) .catch((err) => { console.error(err); - return res.status(500).json({ error: 'something is wrong'}); + return res.status(500).json({ error: 'something went wrong'}); }); }; @@ -41,6 +41,25 @@ exports.getallPostsforUser = (req, res) => { return; }) .catch(function(err) { - res.status(500).send("Failed to retrieve all user's posts from database.", err); + res.status(500).send("Failed to retrieve user's posts from database.", err); + }); +}; + +exports.getallPosts = (req, res) => { + var post_query = admin.firestore().collection("posts"); + post_query.get() + .then(function(allPosts) { + let posts = []; + allPosts.forEach(function(doc) { + posts.push(doc.data()); + }); + return res.status(200).json(posts); + }) + .then(function() { + res.status(200).send("Successfully retrieved every post from database."); + return; + }) + .catch(function(err) { + res.status(500).send("Failed to retrieve posts from database.", err); }); }; diff --git a/functions/index.js b/functions/index.js index dfb27f3..12bb46d 100644 --- a/functions/index.js +++ b/functions/index.js @@ -44,11 +44,12 @@ app.get("/user", fbAuth, getAuthenticatedUser); /*------------------------------------------------------------------* * handlers/post.js * *------------------------------------------------------------------*/ -const { getallPostsforUser, putPost -} = require("./handlers/post"); +const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post"); app.get("/getallPostsforUser", fbAuth, getallPostsforUser); +app.get("/getallPosts", getallPosts); + // Adds one post to the database app.post("/putPost", fbAuth, putPost); diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index 0420d45..d3a3163 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -63,23 +63,20 @@ class App extends Component {
-
- {/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */} - - - - + + + - - - + + - + + +
- diff --git a/twistter-frontend/src/components/layout/NavBar.js b/twistter-frontend/src/components/layout/NavBar.js index 0c5971f..9c720b0 100644 --- a/twistter-frontend/src/components/layout/NavBar.js +++ b/twistter-frontend/src/components/layout/NavBar.js @@ -10,7 +10,7 @@ import Button from '@material-ui/core/Button'; import withStyles from "@material-ui/core/styles/withStyles"; // Redux stuff -// import { logoutUser } from '../../redux/actions/userActions'; +import { logoutUser } from '../../redux/actions/userActions'; import { connect } from 'react-redux'; const styles = { @@ -63,13 +63,9 @@ const mapStateToProps = (state) => ({ user: state.user }) -// const mapActionsToProps = { logoutUser }; - Navbar.propTypes = { user: PropTypes.object.isRequired, classes: PropTypes.object.isRequired } export default connect(mapStateToProps)(withStyles(styles)(Navbar)); - -// export default Navbar; diff --git a/twistter-frontend/src/pages/Home.js b/twistter-frontend/src/pages/Home.js index e0eae74..cee0a93 100644 --- a/twistter-frontend/src/pages/Home.js +++ b/twistter-frontend/src/pages/Home.js @@ -1,12 +1,74 @@ +/* eslint-disable */ 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 Typography from "@material-ui/core/Typography"; + +// component import '../App.css'; - import logo from '../images/twistter-logo.png'; - +import noImage from '../images/no-img.png'; +import Writing_Microblogs from '../Writing_Microblogs'; class Home extends Component { + state = {}; + + componentDidMount() { + axios + .get("/getallPosts") + .then(res => { + console.log(res.data); + this.setState({ + posts: res.data + }) + }) + .catch(err => console.log(err)); + } + render() { + let authenticated = this.props.user.authenticated; + + let postMarkup = this.state.posts ? ( + this.state.posts.map(post => + + + + { + this.state.imageUrl ? () : + () + } + + {post.userHandle} + {post.createdAt} +
+ {post.microBlogTitle} + {post.body} +
+ Topics: {post.microBlogTopics} +
+ Likes {post.likeCount} Comments {post.commentCount} +
+
+ ) + ) : (

My Posts

); + return ( + authenticated ? + + + + + + {postMarkup} + + + :
logo @@ -31,7 +93,15 @@ class Home extends Component {
); - } } +} -export default Home; \ No newline at end of file +const mapStateToProps = (state) => ({ + user: state.user +}) + +Home.propTypes = { + user: PropTypes.object.isRequired +} + +export default connect(mapStateToProps)(Home); \ No newline at end of file diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 75f1703..76589f6 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -1,8 +1,10 @@ /* 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 { Link } from 'react-router-dom'; import { makeStyles, styled } from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; @@ -16,7 +18,7 @@ import AddCircle from '@material-ui/icons/AddCircle'; import TextField from '@material-ui/core/TextField'; // component -import Userline from '../Userline'; +import '../App.css'; import noImage from '../images/no-img.png'; import Writing_Microblogs from '../Writing_Microblogs'; @@ -87,7 +89,8 @@ class user extends Component { } render() { - const classes = this.props; + let authenticated = this.props.user.authenticated; + let classes = this.props; let profileMarkup = this.state.profile ? (

{this.state.profile} @@ -148,7 +151,7 @@ class user extends Component { onClick={this.handleAddCircle} />
- + {authenticated && } {postMarkup} @@ -161,4 +164,12 @@ class user extends Component { } } -export default user; +const mapStateToProps = (state) => ({ + user: state.user +}) + +user.propTypes = { + user: PropTypes.object.isRequired +} + +export default connect(mapStateToProps)(user); From da14700987170801aded9338c31216c5bb0620fd Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Wed, 30 Oct 2019 18:15:01 -0400 Subject: [PATCH 7/7] Fixed a small bug with the Delete Account button --- twistter-frontend/src/pages/editProfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twistter-frontend/src/pages/editProfile.js b/twistter-frontend/src/pages/editProfile.js index 0a31271..7272e76 100644 --- a/twistter-frontend/src/pages/editProfile.js +++ b/twistter-frontend/src/pages/editProfile.js @@ -245,7 +245,7 @@ export class edit extends Component { color="secondary" className={classes.button} component={ Link } - to='/user' + to='/delete' > Delete Account