mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
comment out redux
This commit is contained in:
parent
84ad61b954
commit
12938e8e9a
@ -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));
|
|
||||||
};
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
export const SET_POST = 'SET_POST';
|
|
||||||
export const LIKE_POST = 'LIKE_POST';
|
|
||||||
export const UNLIKE_POST = 'UNLIKE_POST';
|
|
||||||
@ -1,16 +1,15 @@
|
|||||||
import React, { Component } from "react";
|
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 axios from 'axios';
|
||||||
import Box from '@material-ui/core/Box'
|
import Box from '@material-ui/core/Box';
|
||||||
import {connect} from 'react-redux';
|
//import {connect } from 'react-redux';
|
||||||
import {getPosts} from '../redux/actions/dataActions';
|
//import { likePost, unlikePost } from '../redux/actions/dataActions';
|
||||||
import PropTypes from 'prop-types';
|
//import PropTypes from 'prop-types';
|
||||||
import { likePost, unlikePost} from '../redux/actions/dataActions';
|
|
||||||
|
|
||||||
class Feed extends Component {
|
class Feed extends Component {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@ -26,13 +25,11 @@ class Feed extends Component {
|
|||||||
this.setState({microBlogs : post})
|
this.setState({microBlogs : post})
|
||||||
|
|
||||||
})
|
})
|
||||||
this.props.getPosts();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
const {posts} = this.props.data;
|
|
||||||
|
|
||||||
const sortedPosts = (this.state.microBlogs).sort((a,b) =>
|
const sortedPosts = (this.state.microBlogs).sort((a,b) =>
|
||||||
-a.createdAt.localeCompare(b.createdAt)
|
-a.createdAt.localeCompare(b.createdAt)
|
||||||
@ -52,7 +49,9 @@ class Feed extends Component {
|
|||||||
<br></br>Who wrote the microBlog: {microBlog.userHandle}
|
<br></br>Who wrote the microBlog: {microBlog.userHandle}
|
||||||
<br></br>Body of post: {microBlog.body}
|
<br></br>Body of post: {microBlog.body}
|
||||||
<br></br>Tagged topics: {microBlog.microBlogTopics.join("," + " ")}
|
<br></br>Tagged topics: {microBlog.microBlogTopics.join("," + " ")}
|
||||||
<br></br><br></br><br></br><br></br><br></br><br></br><br></br>
|
<br></br><br></br><br></br>
|
||||||
|
|
||||||
|
<span>Likes: {microBlog.likeCount}</span><br></br><br></br><br></br><br></br>
|
||||||
|
|
||||||
</p>)}
|
</p>)}
|
||||||
</p>
|
</p>
|
||||||
@ -63,13 +62,21 @@ class Feed extends Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Feed.propTypes = {
|
||||||
home.propTypes = {
|
likePost: PropTypes.func.isRequired,
|
||||||
getPosts: PropTypes.func.isRequired,
|
unlikePost: PropTypes.func.isRequired,
|
||||||
data: PropTypes.object.isRequired
|
user: PropTypes.object.isRequired,
|
||||||
|
post: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
data: state.data
|
user: state.user
|
||||||
})
|
})
|
||||||
|
|
||||||
export default connect(mapStateToProps, { getPosts })(Feed);
|
const mapActionsToProps = {
|
||||||
|
likePost,
|
||||||
|
unlikePost
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapActionsToProps)(Feed); */
|
||||||
|
export default Feed;
|
||||||
Loading…
Reference in New Issue
Block a user