From 6dbca16ace5d80806d2382ff68fa575ab1b94d26 Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Fri, 1 Nov 2019 04:42:44 -0400 Subject: [PATCH] connecting --- functions/handlers/post.js | 7 ++++++- twistter-frontend/src/App.js | 5 +---- twistter-frontend/src/Feed.js | 33 ++++++++++++++++++++++++--------- twistter-frontend/src/Like.js | 30 ++++++++++++++++++++++++++---- twistter-frontend/src/Quote.js | 13 +++++-------- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 831dba9..816e8a8 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -118,8 +118,13 @@ exports.getallPostsforFeed = (req, res) => { admin.firestore().collection('posts').get() .then((data) => { let posts = []; + data.forEach(function(doc) { - posts.push(doc.data()); + posts.push( { + microBlogs: doc.data(), + id: doc.id, + }) + }); return res.status(200).json(posts); }) diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js index b4659ae..c80c0f1 100644 --- a/twistter-frontend/src/App.js +++ b/twistter-frontend/src/App.js @@ -33,8 +33,7 @@ import Delete from './pages/Delete'; import writeMicroblog from './Writing_Microblogs.js'; import editProfile from './pages/editProfile'; import userLine from './Userline.js'; -import like from './Like.js'; -import quote from './Quote.js'; + import feed from './Feed.js'; const theme = createMuiTheme(themeObject); @@ -82,8 +81,6 @@ class App extends Component { - - diff --git a/twistter-frontend/src/Feed.js b/twistter-frontend/src/Feed.js index 3b301d2..07cc9e9 100644 --- a/twistter-frontend/src/Feed.js +++ b/twistter-frontend/src/Feed.js @@ -5,6 +5,10 @@ import Box from '@material-ui/core/Box'; //import {connect } from 'react-redux'; //import { likePost, unlikePost } from '../redux/actions/dataActions'; //import PropTypes from 'prop-types'; +import Like from "./Like.js"; +import Route from 'react-router-dom/Route'; + +import Quote from "./Quote.js"; class Feed extends Component { @@ -13,20 +17,22 @@ class Feed extends Component { constructor(props) { super(props); this.state = { - microBlogs: [] + microBlogs: [], + }; + + } - componentDidMount() { + componentDidMount() { - axios.get('/getallPostsforFeed') - .then(res => { + axios.get("https://us-central1-twistter-e4649.cloudfunctions.net/api/getallPostsforFeed") + .then((res) => { const post = res.data; this.setState({microBlogs : post}) - }) - - } + }) + } render() { @@ -34,6 +40,7 @@ class Feed extends Component { const sortedPosts = (this.state.microBlogs).sort((a,b) => -a.createdAt.localeCompare(b.createdAt) ) + return(
@@ -48,10 +55,18 @@ class Feed extends Component { " " + microBlog.createdAt.substring(11,19)}

Who wrote the microBlog: {microBlog.userHandle}

Body of post: {microBlog.body} +

ID of post: {microBlog.id}

Tagged topics: {microBlog.microBlogTopics.join("," + " ")}





- - Likes: {microBlog.likeCount}







+
+ + + + Likes: {microBlog.likeCount} + + +







+

)}

diff --git a/twistter-frontend/src/Like.js b/twistter-frontend/src/Like.js index 879e2a7..3dc3aa8 100644 --- a/twistter-frontend/src/Like.js +++ b/twistter-frontend/src/Like.js @@ -9,20 +9,42 @@ class Like extends Component { super(props); this.state = { like : false, - count : 0 + Id : null }; this.handleSubmit = this.handleSubmit.bind(this); } - handleSubmit() { + handleSubmit = post => { + + this.setState({ like: !this.state.like }); - const LikedPost = { - + + axios.get("https://us-central1-twistter-e4649.cloudfunctions.net/api/getallPostsforFeed") + .then((res) => { + const postData = res.data; + this.setState({Id: postData.id}) + + }) + + if(this.state.like == false) + { + + axios.get(`/putPost/${this.state.Id}/like`) + .then((res) => { + console.log(res.data); + }) } + else + { + axios.get(`/putPost/${this.state.Id}/unlike`) + .then((res) => { + console.log(res.data); + }) + } } diff --git a/twistter-frontend/src/Quote.js b/twistter-frontend/src/Quote.js index 3d9e045..81dc7c7 100644 --- a/twistter-frontend/src/Quote.js +++ b/twistter-frontend/src/Quote.js @@ -2,10 +2,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'; -import DropdownButton from 'react-bootstrap/DropdownButton' -import Dropdown from 'react-bootstrap/Dropdown' -import Modal from 'react-bootstrap/Modal' -import Button from 'react-bootstrap/Button' + @@ -31,10 +28,10 @@ class Quote extends Component { } render() { return( - - Quote with comment - Quote without comment - +
+ + +
) } }