Merge pull request #19 from ClaytonWWilson/user-line

added entering topics field and database call for adding topics when …
This commit is contained in:
asankaran35 2019-10-01 19:16:02 -04:00 committed by GitHub
commit 16973fb340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 9 deletions

View File

@ -11,6 +11,7 @@ exports.putPost = (req, res) => {
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
likeCount: 0, likeCount: 0,
commentCount: 0, commentCount: 0,
microBlogTopics: req.body.microBlogTopics
}; };

View File

@ -43,7 +43,8 @@ const {putPost, getallPostsforUser} = require('./handlers/post');
app.get('/getallPostsforUser', getallPostsforUser); app.get('/getallPostsforUser', getallPostsforUser);
// Adds one post to the database // Adds one post to the database
app.post('/putPost', fbAuth, putPost); app.post('/putPost', firebaseAuth, putPost);
exports.api = functions.https.onRequest(app); exports.api = functions.https.onRequest(app);

View File

@ -9,7 +9,8 @@ class Userline extends Component {
{ {
super(props); super(props);
this.state = { this.state = {
microBlogs : [] microBlogs : [],
} }
} }
@ -24,9 +25,13 @@ class Userline extends Component {
}) })
} }
render() { render() {
let sortedPosts = [];
return ( return (
<ul> <ul>
{ this.state.microBlogs.map(microBlog => <p>{microBlog.body}</p>)} { this.state.microBlogs.map(microBlog => <p>{microBlog.body}</p>)}

View File

@ -11,6 +11,7 @@ class Writing_Microblogs extends Component {
this.state = { this.state = {
value: '', value: '',
title: '', title: '',
topics: '',
characterCount: 10 characterCount: 10
}; };
@ -19,12 +20,18 @@ class Writing_Microblogs extends Component {
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);
} }
handleChange(event) { handleChange(event) {
this.setState( {title: event.target.value }); this.setState( {title: event.target.value });
} }
handleChangeforTopics(event) {
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); // alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
@ -33,7 +40,8 @@ class Writing_Microblogs extends Component {
{ body: this.state.value, { body: this.state.value,
userHandle: "new user", userHandle: "new user",
userImage: "bing-url", userImage: "bing-url",
microBlogTitle: this.state.title microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')
}, },
{ headers: { 'Content-Type': 'application/json'} } { headers: { 'Content-Type': 'application/json'} }
@ -41,7 +49,7 @@ class Writing_Microblogs extends Component {
) )
console.log(response.data); console.log(response.data);
event.preventDefault(); event.preventDefault();
this.setState({value: '', title: '',characterCount: 10}) this.setState({value: '', title: '',characterCount: 10, topics: ''})
} }
handleChangeforPost(event) { handleChangeforPost(event) {
@ -55,13 +63,18 @@ class Writing_Microblogs extends Component {
} }
render() { render() {
return ( return (
<div> <div>
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "30px" }}> <div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
<form> <form>
<input type="text" placeholder="Enter Microblog Title" value={this.state.title} onChange={this.handleChange} /> <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> </form>
</div> </div>