Username and user id now show in post data

This commit is contained in:
Aaron Sun 2019-10-27 23:11:24 -04:00
parent 5fa4caf0a3
commit 657277bcad
4 changed files with 51 additions and 59 deletions

View File

@ -1,17 +1,17 @@
/* eslint-disable promise/always-return */ /* eslint-disable promise/always-return */
const admin = require('firebase-admin'); const admin = require('firebase-admin');
exports.putPost = (req, res) => {
exports.putPost = (req, res) => {
const newPost = { const newPost = {
body: req.body.body, body: req.body.body,
userHandle: req.body.userHandle, userHandle: req.user.handle,
userImage: req.body.userImage, userImage: req.body.userImage,
userID: req.user.uid,
microBlogTitle: req.body.microBlogTitle, microBlogTitle: req.body.microBlogTitle,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
likeCount: 0, likeCount: 0,
commentCount: 0, commentCount: 0,
microBlogTopics: req.body.microBlogTopics microBlogTopics: req.body.microBlogTopics
}; };
admin.firestore().collection('posts').add(newPost) admin.firestore().collection('posts').add(newPost)
@ -27,7 +27,7 @@ exports.putPost = (req, res) => {
}; };
exports.getallPostsforUser = (req, res) => { exports.getallPostsforUser = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get() admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
.then((data) => { .then((data) => {
let posts = []; let posts = [];
data.forEach(function(doc) { data.forEach(function(doc) {

View File

@ -67,7 +67,6 @@ class App extends Component {
<Route exact path="/user" component={user} /> <Route exact path="/user" component={user} />
<Route exact path="/home" component={writeMicroblog} /> <Route exact path="/home" component={writeMicroblog} />
<Route exact path="/edit" component={editProfile} /> <Route exact path="/edit" component={editProfile} />
{/* <Route exact path="/user" component={userLine} /> */}
<AuthRoute exact path="/" component={home}/> <AuthRoute exact path="/" component={home}/>
</Switch> </Switch>

View File

@ -5,7 +5,7 @@ import axios from 'axios';
class Writing_Microblogs extends Component { class Writing_Microblogs extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
@ -15,13 +15,13 @@ class Writing_Microblogs extends Component {
characterCount: 250 characterCount: 250
}; };
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.handleChangeforPost = this.handleChangeforPost.bind(this); this.handleChangeforPost = this.handleChangeforPost.bind(this);
this.handleChangeforTopics = this.handleChangeforTopics.bind(this); this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
} }
handleChange(event) { handleChange(event) {
@ -33,10 +33,10 @@ class Writing_Microblogs extends Component {
} }
handleSubmit(event) { handleSubmit(event) {
// 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,
userHandle: "new user",
userImage: "bing-url", userImage: "bing-url",
microBlogTitle: this.state.title, microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ') microBlogTopics: this.state.topics.split(', ')
@ -102,7 +102,7 @@ class Writing_Microblogs extends Component {
); );
} }
} }
export default Writing_Microblogs; export default Writing_Microblogs;

View File

@ -1,7 +1,7 @@
/* eslint-disable */ /* eslint-disable */
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
// import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
// Material UI stuff // Material UI stuff
import AppBar from '@material-ui/core/AppBar'; import AppBar from '@material-ui/core/AppBar';
@ -10,70 +10,63 @@ 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 { connect } from 'react-redux';
// import { connect } from 'react-redux';
// const styles = {
// form: {
// textAlign: "center"
// },
// textField: {
// marginBottom: 30
// },
// pageTitle: {
// marginBottom: 40
// },
// button: {
// positon: "relative",
// marginBottom: 30
// },
// progress: {
// position: "absolute"
// }
// };
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Navbar extends Component { export class Navbar extends Component {
render() { render() {
const authenticated = this.props.user.authenticated;
return ( return (
<AppBar> <AppBar>
<ToolBar> <ToolBar>
<Button component={ Link } to='/'> <Button component={ Link } to='/'>
Home Home
</Button> </Button>
<Button component={ Link } to='/login'> {!authenticated && <Button component={ Link } to='/login'>
Login Login
</Button> </Button>}
<Button component={ Link } to='/signup'> {!authenticated && <Button component={ Link } to='/signup'>
Sign Up Sign Up
</Button> </Button>}
<Button component={ Link } to='/logout'> {authenticated && <Button component={ Link } to='/logout'>
Logout Logout
</Button> </Button>}
<Button component={ Link } to='/delete'> {authenticated && <Button component={ Link } to='/delete'>
Delete Account Delete Account
</Button> </Button>}
</ToolBar> </ToolBar>
</AppBar> </AppBar>
) )
} }
} }
// const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
// user: state.user user: state.user
// }) })
// const mapActionsToProps = { logoutUser }; Navbar.propTypes = {
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
}
// Navbar.propTypes = { export default connect(mapStateToProps)(withStyles(styles)(Navbar));
// logoutUser: PropTypes.func.isRequired,
// user: PropTypes.object.isRequired,
// classes: PropTypes.object.isRequired
// }
// export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Navbar)); // export default Navbar;
export default Navbar;