Files
astuto/app/javascript/components/Post/PostP.tsx

86 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-09-12 15:51:45 +02:00
import * as React from 'react';
import IPost from '../../interfaces/IPost';
import IPostStatus from '../../interfaces/IPostStatus';
import PostStatusSelect from './PostStatusSelect';
2019-09-12 18:03:19 +02:00
import PostStatusLabel from '../shared/PostStatusLabel';
import Comments from '../../containers/Comments';
import { MutedText } from '../shared/CustomTexts';
import friendlyDate from '../../helpers/friendlyDate';
2019-09-12 15:51:45 +02:00
interface Props {
postId: number;
post: IPost;
postStatuses: Array<IPostStatus>;
isLoggedIn: boolean;
isPowerUser: boolean;
authenticityToken: string;
requestPost(postId: number): void;
changePostStatus(
postId: number,
newPostStatusId: number,
authenticityToken: string,
): void;
}
class PostP extends React.Component<Props> {
componentDidMount() {
this.props.requestPost(this.props.postId);
}
render() {
const {
post,
postStatuses,
2019-09-20 18:43:24 +02:00
isLoggedIn,
2019-09-12 15:51:45 +02:00
isPowerUser,
authenticityToken,
changePostStatus,
} = this.props;
return (
<div className="pageContainer">
<div className="sidebar">
<div className="sidebarCard"></div>
<div className="sidebarCard"></div>
<div className="sidebarCard"></div>
</div>
2019-09-12 15:51:45 +02:00
<div className="postAndCommentsContainer">
<div className="postContainer">
<h2>{post.title}</h2>
{
isPowerUser && post ?
<PostStatusSelect
postStatuses={postStatuses}
selectedPostStatusId={post.postStatusId}
handleChange={
newPostStatusId => changePostStatus(post.id, newPostStatusId, authenticityToken)
}
/>
:
<PostStatusLabel
{...postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
/>
}
<p className="postDescription">{post.description}</p>
<MutedText>{friendlyDate(post.createdAt)}</MutedText>
</div>
<Comments
postId={this.props.postId}
2019-09-20 18:43:24 +02:00
isLoggedIn={isLoggedIn}
authenticityToken={authenticityToken}
/>
</div>
2019-09-12 15:51:45 +02:00
</div>
);
}
}
export default PostP;