diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 71b97eb..3a27c1a 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -1,3 +1,4 @@ +const admin = require('firebase-admin'); /* eslint-disable promise/always-return */ exports.putPost = (req, res) => { if (req.body.body.trim() === '') { @@ -6,18 +7,21 @@ exports.putPost = (req, res) => { const newPost = { body: req.body.body, - userHandle: req.user.handle, - userImage: req.user.imageUrl, + userHandle: req.body.userHandle, + userImage: req.body.userImage, + title: req.body.title, createdAt: new Date().toISOString(), likeCount: 0, - commentCount: 0 + commentCount: 0, + }; - db.collection('post').add(newPost) - .then((doc) => { + admin.firestore().collection('posts').add(newPost) + .then((doc) => { const resPost = newPost; resPost.postId = doc.id; res.json(resPost); + }) .catch((err) => { res.status(500).json({ error: 'something is wrong'}); diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js index eca41d4..4769a9a 100644 --- a/twistter-frontend/src/Writing_Microblogs.js +++ b/twistter-frontend/src/Writing_Microblogs.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import { BrowserRouter as Router } from 'react-router-dom'; import Route from 'react-router-dom/Route'; +import axios from 'axios'; class Writing_Microblogs extends Component { @@ -25,7 +26,13 @@ class Writing_Microblogs extends Component { } 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); + const response = await axios.post( + 'http://localhost:5001/twistter-e4649/us-central1/api/putPost', + { }, + { headers: { 'Content-Type': 'application/json'} } + ) + console.log(response.data); event.preventDefault(); }