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

119 lines
3.4 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';
2019-09-21 12:54:57 +02:00
import IBoard from '../../interfaces/IBoard';
2019-09-12 15:51:45 +02:00
2019-09-21 12:54:57 +02:00
import PostBoardSelect from './PostBoardSelect';
2019-09-12 15:51:45 +02:00
import PostStatusSelect from './PostStatusSelect';
2019-09-21 12:54:57 +02:00
import PostBoardLabel from '../shared/PostBoardLabel';
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;
2019-09-21 12:54:57 +02:00
boards: Array<IBoard>;
2019-09-12 15:51:45 +02:00
postStatuses: Array<IPostStatus>;
isLoggedIn: boolean;
isPowerUser: boolean;
authenticityToken: string;
requestPost(postId: number): void;
2019-09-21 12:54:57 +02:00
changePostBoard(
postId: number,
newBoardId: number,
authenticityToken: string,
): void;
2019-09-12 15:51:45 +02:00
changePostStatus(
postId: number,
newPostStatusId: number,
authenticityToken: string,
): void;
}
class PostP extends React.Component<Props> {
componentDidMount() {
this.props.requestPost(this.props.postId);
}
render() {
const {
post,
2019-09-21 12:54:57 +02:00
boards,
2019-09-12 15:51:45 +02:00
postStatuses,
2019-09-20 18:43:24 +02:00
isLoggedIn,
2019-09-12 15:51:45 +02:00
isPowerUser,
authenticityToken,
2019-09-21 12:54:57 +02:00
changePostBoard,
2019-09-12 15:51:45 +02:00
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">
2019-09-25 11:50:23 +02:00
<div className="postHeader">
<h2>{post.title}</h2>
{
isPowerUser && post ?
<a href={`/admin/posts/${post.id}`} data-turbolinks="false">Edit</a> : null
}
</div>
{
isPowerUser && post ?
2019-09-21 12:54:57 +02:00
<div className="postSettings">
<PostBoardSelect
boards={boards}
selectedBoardId={post.boardId}
handleChange={
newBoardId => changePostBoard(post.id, newBoardId, authenticityToken)
}
/>
<PostStatusSelect
postStatuses={postStatuses}
selectedPostStatusId={post.postStatusId}
handleChange={
newPostStatusId => changePostStatus(post.id, newPostStatusId, authenticityToken)
}
/>
</div>
:
2019-09-21 12:54:57 +02:00
<div className="postInfo">
<PostBoardLabel
{...boards.find(board => board.id === post.boardId)}
/>
<PostStatusLabel
{...postStatuses.find(postStatus => postStatus.id === post.postStatusId)}
/>
</div>
}
<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}
2019-09-25 11:50:23 +02:00
isPowerUser={isPowerUser}
authenticityToken={authenticityToken}
/>
</div>
2019-09-12 15:51:45 +02:00
</div>
);
}
}
export default PostP;