mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
All posts from db can now show on home page timeline
This commit is contained in:
parent
a61c296ddf
commit
26afabe709
@ -22,7 +22,7 @@ exports.putPost = (req, res) => {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(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;
|
return;
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -44,11 +44,12 @@ app.get("/user", fbAuth, getAuthenticatedUser);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, putPost
|
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||||
} = require("./handlers/post");
|
|
||||||
|
|
||||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|||||||
@ -63,23 +63,20 @@ class App extends Component {
|
|||||||
<div className='container' >
|
<div className='container' >
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
<AuthRoute exact path="/signup" component={signup} />
|
||||||
<AuthRoute exact path="/signup" component={signup} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
<AuthRoute exact path="/login" component={login} />
|
<AuthRoute exact path="/" component={home}/>
|
||||||
<Route exact path="/logout" component={logout} />
|
|
||||||
<Route exact path="/delete" component={Delete} />
|
|
||||||
|
|
||||||
<Route exact path="/user" component={user} />
|
<Route exact path="/logout" component={logout} />
|
||||||
<Route exact path="/home" component={writeMicroblog} />
|
<Route exact path="/delete" component={Delete} />
|
||||||
<Route exact path="/edit" component={editProfile} />
|
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home}/>
|
<Route exact path="/home" component={home} />
|
||||||
|
<Route exact path="/user" component={user} />
|
||||||
|
<Route exact path="/edit" component={editProfile} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>
|
</Provider>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import Button from '@material-ui/core/Button';
|
|||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
// import { logoutUser } from '../../redux/actions/userActions';
|
import { logoutUser } from '../../redux/actions/userActions';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@ -63,13 +63,9 @@ const mapStateToProps = (state) => ({
|
|||||||
user: state.user
|
user: state.user
|
||||||
})
|
})
|
||||||
|
|
||||||
// const mapActionsToProps = { logoutUser };
|
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|
||||||
// export default Navbar;
|
|
||||||
|
|||||||
@ -1,12 +1,74 @@
|
|||||||
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
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 '../App.css';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
|
import noImage from '../images/no-img.png';
|
||||||
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
|
|
||||||
class Home extends Component {
|
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() {
|
render() {
|
||||||
|
let authenticated = this.props.user.authenticated;
|
||||||
|
|
||||||
|
let postMarkup = this.state.posts ? (
|
||||||
|
this.state.posts.map(post =>
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Typography>
|
||||||
|
{
|
||||||
|
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
||||||
|
(<img src={noImage} height="50" width="50"/>)
|
||||||
|
}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
|
||||||
|
<br />
|
||||||
|
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||||
|
<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>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
) : (<p>My Posts</p>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
authenticated ?
|
||||||
|
<Grid container spacing={16}>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
<Writing_Microblogs />
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
{postMarkup}
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
:
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
@ -31,7 +93,15 @@ class Home extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Home;
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
Home.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(Home);
|
||||||
@ -1,8 +1,10 @@
|
|||||||
/* 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 axios from 'axios';
|
import axios from 'axios';
|
||||||
//import '../App.css';
|
|
||||||
|
// Material UI and React Router
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { makeStyles, styled } from '@material-ui/core/styles';
|
import { makeStyles, styled } from '@material-ui/core/styles';
|
||||||
import Grid from '@material-ui/core/Grid';
|
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';
|
import TextField from '@material-ui/core/TextField';
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import Userline from '../Userline';
|
import '../App.css';
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from '../images/no-img.png';
|
||||||
import Writing_Microblogs from '../Writing_Microblogs';
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
|
|
||||||
@ -87,7 +89,8 @@ class user extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const classes = this.props;
|
let authenticated = this.props.user.authenticated;
|
||||||
|
let classes = this.props;
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<p>
|
<p>
|
||||||
<Typography variant='h5'>{this.state.profile}</Typography>
|
<Typography variant='h5'>{this.state.profile}</Typography>
|
||||||
@ -148,7 +151,7 @@ class user extends Component {
|
|||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<Button component={ Link } to='/edit'>Edit Profile Info</Button>
|
{authenticated && <Button component={ Link } to='/edit'>Edit Profile Info</Button>}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
{postMarkup}
|
{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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user