2019-09-17 11:33:18 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
2019-09-17 17:04:19 +02:00
|
|
|
import CommentList from './CommentList';
|
|
|
|
|
import Spinner from '../shared/Spinner';
|
|
|
|
|
import { DangerText } from '../shared/CustomTexts';
|
|
|
|
|
|
2019-09-17 11:33:18 +02:00
|
|
|
import IComment from '../../interfaces/IComment';
|
2019-09-17 19:09:38 +02:00
|
|
|
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
2019-09-17 11:33:18 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
postId: number;
|
|
|
|
|
|
|
|
|
|
comments: Array<IComment>;
|
2019-09-17 19:09:38 +02:00
|
|
|
replies: Array<CommentRepliesState>;
|
2019-09-17 11:33:18 +02:00
|
|
|
areLoading: boolean;
|
|
|
|
|
error: string;
|
|
|
|
|
|
|
|
|
|
requestComments(postId: number, page?: number);
|
2019-09-17 19:09:38 +02:00
|
|
|
toggleCommentReply(commentId: number);
|
|
|
|
|
setCommentReplyBody(commentId: number, body: string);
|
2019-09-17 11:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CommentsP extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.requestComments(this.props.postId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
comments,
|
2019-09-17 19:09:38 +02:00
|
|
|
replies,
|
2019-09-17 11:33:18 +02:00
|
|
|
areLoading,
|
|
|
|
|
error,
|
2019-09-17 19:09:38 +02:00
|
|
|
|
|
|
|
|
toggleCommentReply,
|
|
|
|
|
setCommentReplyBody,
|
2019-09-17 11:33:18 +02:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
2019-09-17 17:04:19 +02:00
|
|
|
<div className="comments">
|
|
|
|
|
<h2>Comments</h2>
|
|
|
|
|
|
|
|
|
|
{ areLoading ? <Spinner /> : null }
|
|
|
|
|
{ error ? <DangerText>{error}</DangerText> : null }
|
|
|
|
|
|
|
|
|
|
<CommentList
|
|
|
|
|
comments={comments}
|
2019-09-17 19:09:38 +02:00
|
|
|
replies={replies}
|
|
|
|
|
toggleCommentReply={toggleCommentReply}
|
|
|
|
|
setCommentReplyBody={setCommentReplyBody}
|
2019-09-17 17:04:19 +02:00
|
|
|
parentId={null}
|
|
|
|
|
level={1}
|
|
|
|
|
/>
|
2019-09-17 11:33:18 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default CommentsP;
|