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}
+
+
+ :

@@ -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);