From 12938e8e9ad34f740cebe93e2f4ec9326eb7702d Mon Sep 17 00:00:00 2001 From: Aditya Sankaran Date: Wed, 30 Oct 2019 21:55:48 -0400 Subject: [PATCH] comment out redux --- .../redux/actions/dataActions.js | 55 ------------------- .../redux/reducers/userReducer.js | 31 ----------- twistter-frontend/redux/types.js | 3 - twistter-frontend/src/Feed.js | 39 +++++++------ 4 files changed, 23 insertions(+), 105 deletions(-) diff --git a/twistter-frontend/redux/actions/dataActions.js b/twistter-frontend/redux/actions/dataActions.js index e0198d4..e69de29 100644 --- a/twistter-frontend/redux/actions/dataActions.js +++ b/twistter-frontend/redux/actions/dataActions.js @@ -1,55 +0,0 @@ -import {LIKE_POST, UNLIKE_POST, SET_POST, SET_POSTS} from '../types'; -import axios from 'axios'; - -export const getPosts = () => (dispatch) => { - axios - .get('/posts') - .then((res) => { - dispatch({ - type: SET_POSTS, - payload: res.data - }); - }) - .catch((err) => { - dispatch({ - type: SET_POSTS, - payload: [] - }); - }); - }; - -export const likePost = (postId) => (dispatch) => { - axios - .get(`/posts/${postId}/like`) - .then((res) => { - dispatch({ - type: LIKE_POST, - payload: res.data - }); - }) - .catch((err) => console.log(err)); - }; - - export const unlikePost = (postId) => (dispatch) => { - axios - .get(`/posts/${postId}/unlike`) - .then((res) => { - dispatch({ - type: UNLIKE_POST, - payload: res.data - }); - }) - .catch((err) => console.log(err)); - }; - - export const getPost = (postId) => (dispatch) => { - axios - .get(`/posts/${postId}`) - .then((res) => { - dispatch({ - type: SET_POST, - payload: res.data - }); - }) - .catch((err) => console.log(err)); - }; \ No newline at end of file diff --git a/twistter-frontend/redux/reducers/userReducer.js b/twistter-frontend/redux/reducers/userReducer.js index 4e6f681..e69de29 100644 --- a/twistter-frontend/redux/reducers/userReducer.js +++ b/twistter-frontend/redux/reducers/userReducer.js @@ -1,31 +0,0 @@ -import { LIKE_POST, UNLIKE_POST} from '../types'; - -const initialState = { - likes: [], - credentials: {} -} - -export default function(state = initialState, action) { - switch (action.type) { - case LIKE_POST: - return { - ...state, - likes: [ - ...state.likes, - { - userHandle: state.credentials.handle, - postId: action.payload.postId - } - ] - } - case UNLIKE_POST: - return { - ...state, - likes: state.likes.filter( - (like) => like.postId === action.payload.postId - ) - }; - default: - return state; - } -} \ No newline at end of file diff --git a/twistter-frontend/redux/types.js b/twistter-frontend/redux/types.js index 3cd2bd7..e69de29 100644 --- a/twistter-frontend/redux/types.js +++ b/twistter-frontend/redux/types.js @@ -1,3 +0,0 @@ -export const SET_POST = 'SET_POST'; -export const LIKE_POST = 'LIKE_POST'; -export const UNLIKE_POST = 'UNLIKE_POST'; diff --git a/twistter-frontend/src/Feed.js b/twistter-frontend/src/Feed.js index d624c65..3b301d2 100644 --- a/twistter-frontend/src/Feed.js +++ b/twistter-frontend/src/Feed.js @@ -1,16 +1,15 @@ 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 Box from '@material-ui/core/Box' -import {connect} from 'react-redux'; -import {getPosts} from '../redux/actions/dataActions'; -import PropTypes from 'prop-types'; -import { likePost, unlikePost} from '../redux/actions/dataActions'; +import Box from '@material-ui/core/Box'; +//import {connect } from 'react-redux'; +//import { likePost, unlikePost } from '../redux/actions/dataActions'; +//import PropTypes from 'prop-types'; class Feed extends Component { + constructor(props) { super(props); this.state = { @@ -26,13 +25,11 @@ class Feed extends Component { this.setState({microBlogs : post}) }) - this.props.getPosts(); } render() { - const {posts} = this.props.data; const sortedPosts = (this.state.microBlogs).sort((a,b) => -a.createdAt.localeCompare(b.createdAt) @@ -52,7 +49,9 @@ class Feed extends Component {

Who wrote the microBlog: {microBlog.userHandle}

Body of post: {microBlog.body}

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













+





+ + Likes: {microBlog.likeCount}







)}

@@ -63,13 +62,21 @@ class Feed extends Component { ) } } - -home.propTypes = { - getPosts: PropTypes.func.isRequired, - data: PropTypes.object.isRequired +/* Feed.propTypes = { + likePost: PropTypes.func.isRequired, + unlikePost: PropTypes.func.isRequired, + user: PropTypes.object.isRequired, + post: PropTypes.object.isRequired } + const mapStateToProps = state => ({ - data: state.data + user: state.user }) -export default connect(mapStateToProps, { getPosts })(Feed); \ No newline at end of file +const mapActionsToProps = { + likePost, + unlikePost +} + +export default connect(mapStateToProps, mapActionsToProps)(Feed); */ +export default Feed; \ No newline at end of file