Files
astuto/app/javascript/containers/Post.tsx

76 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-09-12 15:51:45 +02:00
import { connect } from 'react-redux';
2022-05-07 11:27:07 +02:00
import { requestPost } from '../actions/Post/requestPost';
import { requestLikes } from '../actions/Like/requestLikes';
import { changePostBoard } from '../actions/Post/changePostBoard';
import { changePostStatus } from '../actions/Post/changePostStatus';
import { submitFollow } from '../actions/Follow/submitFollow';
import { requestFollow } from '../actions/Follow/requestFollow';
import { requestPostStatusChanges } from '../actions/PostStatusChange/requestPostStatusChanges';
import { postStatusChangeSubmitted } from '../actions/PostStatusChange/submittedPostStatusChange';
2019-09-12 15:51:45 +02:00
import { State } from '../reducers/rootReducer';
import PostP from '../components/Post/PostP';
import { fromJavascriptDateToRailsString } from '../helpers/datetime';
2019-09-12 15:51:45 +02:00
const mapStateToProps = (state: State) => ({
post: state.currentPost.item,
2019-09-30 16:54:37 +02:00
likes: state.currentPost.likes,
followed: state.currentPost.followed,
2019-10-01 19:15:03 +02:00
comments: state.currentPost.comments,
postStatusChanges: state.currentPost.postStatusChanges,
2019-09-12 15:51:45 +02:00
});
const mapDispatchToProps = (dispatch) => ({
requestPost(postId: number) {
dispatch(requestPost(postId));
},
2019-09-30 16:54:37 +02:00
requestLikes(postId: number) {
dispatch(requestLikes(postId));
},
requestFollow(postId: number) {
dispatch(requestFollow(postId));
},
requestPostStatusChanges(postId: number) {
dispatch(requestPostStatusChanges(postId));
},
2019-09-21 12:54:57 +02:00
changePostBoard(postId: number, newBoardId: number, authenticityToken: string) {
dispatch(changePostBoard(postId, newBoardId, authenticityToken));
},
changePostStatus(
postId: number,
newPostStatusId: number,
userFullName: string,
userEmail: string,
authenticityToken: string
) {
2019-09-12 18:03:19 +02:00
if (isNaN(newPostStatusId)) newPostStatusId = null;
dispatch(changePostStatus(postId, newPostStatusId, authenticityToken)).then(res => {
if (res && res.status !== 204) return;
dispatch(postStatusChangeSubmitted({
postStatusId: newPostStatusId,
userFullName,
userEmail,
updatedAt: fromJavascriptDateToRailsString(new Date()),
}));
});
},
submitFollow(postId: number, isFollow: boolean, authenticityToken: string) {
dispatch(submitFollow(postId, isFollow, authenticityToken));
2019-09-12 15:51:45 +02:00
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(PostP);