import * as React from 'react'; import I18n from 'i18n-js'; import IPost from '../../interfaces/IPost'; import IPostStatus from '../../interfaces/IPostStatus'; import IBoard from '../../interfaces/IBoard'; import PostUpdateList from './PostUpdateList'; import LikeList from './LikeList'; import ActionBox from './ActionBox'; import LikeButton from '../../containers/LikeButton'; import PostBoardSelect from './PostBoardSelect'; import PostStatusSelect from './PostStatusSelect'; import PostBoardLabel from '../shared/PostBoardLabel'; import PostStatusLabel from '../shared/PostStatusLabel'; import Comments from '../../containers/Comments'; import { MutedText } from '../shared/CustomTexts'; import { LikesState } from '../../reducers/likesReducer'; import { CommentsState } from '../../reducers/commentsReducer'; import { PostStatusChangesState } from '../../reducers/postStatusChangesReducer'; import friendlyDate, { fromRailsStringToJavascriptDate } from '../../helpers/datetime'; interface Props { postId: number; post: IPost; likes: LikesState; followed: boolean; comments: CommentsState; postStatusChanges: PostStatusChangesState; boards: Array; postStatuses: Array; isLoggedIn: boolean; isPowerUser: boolean; userFullName: string; userEmail: string; authenticityToken: string; requestPost(postId: number): void; requestLikes(postId: number): void; requestFollow(postId: number): void; requestPostStatusChanges(postId: number): void; changePostBoard( postId: number, newBoardId: number, authenticityToken: string, ): void; changePostStatus( postId: number, newPostStatusId: number, userFullName: string, userEmail: string, authenticityToken: string, ): void; submitFollow( postId: number, isFollow: boolean, authenticityToken: string, ): void; } class PostP extends React.Component { componentDidMount() { const {postId} = this.props; this.props.requestPost(postId); this.props.requestLikes(postId); this.props.requestFollow(postId); this.props.requestPostStatusChanges(postId); } render() { const { post, likes, followed, comments, postStatusChanges, boards, postStatuses, isLoggedIn, isPowerUser, userFullName, userEmail, authenticityToken, changePostBoard, changePostStatus, submitFollow, } = this.props; const postUpdates = [ ...comments.items.filter(comment => comment.isPostUpdate === true), ...postStatusChanges.items, ].sort( (a, b) => fromRailsStringToJavascriptDate(a.updatedAt) < fromRailsStringToJavascriptDate(b.updatedAt) ? 1 : -1 ); return (
submitFollow(post.id, !followed, authenticityToken)} isLoggedIn={isLoggedIn} />
like.email === userEmail) ? 1 : 0} isLoggedIn={isLoggedIn} authenticityToken={authenticityToken} />

{post.title}

{ isPowerUser && post ? {I18n.t('post.edit_button')} : null }
{ isPowerUser && post ?
changePostBoard(post.id, newBoardId, authenticityToken) } /> changePostStatus(post.id, newPostStatusId, userFullName, userEmail, authenticityToken) } />
:
board.id === post.boardId)} /> postStatus.id === post.postStatusId)} />
}

{post.description}

{friendlyDate(post.createdAt)}
); } } export default PostP;