mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Improve comments component
This commit is contained in:
@@ -20,6 +20,8 @@ interface Props {
|
|||||||
handleToggleCommentReply(): void;
|
handleToggleCommentReply(): void;
|
||||||
handleCommentReplyBodyChange(e: FormEvent): void;
|
handleCommentReplyBodyChange(e: FormEvent): void;
|
||||||
handleSubmitComment(body: string, parentId: number): void;
|
handleSubmitComment(body: string, parentId: number): void;
|
||||||
|
|
||||||
|
isLoggedIn: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Comment = ({
|
const Comment = ({
|
||||||
@@ -34,6 +36,8 @@ const Comment = ({
|
|||||||
handleToggleCommentReply,
|
handleToggleCommentReply,
|
||||||
handleCommentReplyBodyChange,
|
handleCommentReplyBodyChange,
|
||||||
handleSubmitComment,
|
handleSubmitComment,
|
||||||
|
|
||||||
|
isLoggedIn,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<div className="comment">
|
<div className="comment">
|
||||||
<div className="commentHeader">
|
<div className="commentHeader">
|
||||||
@@ -52,8 +56,11 @@ const Comment = ({
|
|||||||
<NewComment
|
<NewComment
|
||||||
body={reply.body}
|
body={reply.body}
|
||||||
parentId={id}
|
parentId={id}
|
||||||
|
isSubmitting={reply.isSubmitting}
|
||||||
handleChange={handleCommentReplyBodyChange}
|
handleChange={handleCommentReplyBodyChange}
|
||||||
handleSubmit={handleSubmitComment}
|
handleSubmit={handleSubmitComment}
|
||||||
|
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ interface Props {
|
|||||||
toggleCommentReply(commentId: number): void;
|
toggleCommentReply(commentId: number): void;
|
||||||
setCommentReplyBody(commentId: number, body: string): void;
|
setCommentReplyBody(commentId: number, body: string): void;
|
||||||
handleSubmitComment(body: string, parentId: number): void;
|
handleSubmitComment(body: string, parentId: number): void;
|
||||||
|
|
||||||
|
isLoggedIn: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentList = ({
|
const CommentList = ({
|
||||||
@@ -26,6 +28,8 @@ const CommentList = ({
|
|||||||
toggleCommentReply,
|
toggleCommentReply,
|
||||||
setCommentReplyBody,
|
setCommentReplyBody,
|
||||||
handleSubmitComment,
|
handleSubmitComment,
|
||||||
|
|
||||||
|
isLoggedIn,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{comments.map((comment, i) => {
|
{comments.map((comment, i) => {
|
||||||
@@ -43,6 +47,8 @@ const CommentList = ({
|
|||||||
}
|
}
|
||||||
handleSubmitComment={handleSubmitComment}
|
handleSubmitComment={handleSubmitComment}
|
||||||
{...comment}
|
{...comment}
|
||||||
|
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CommentList
|
<CommentList
|
||||||
@@ -54,6 +60,8 @@ const CommentList = ({
|
|||||||
toggleCommentReply={toggleCommentReply}
|
toggleCommentReply={toggleCommentReply}
|
||||||
setCommentReplyBody={setCommentReplyBody}
|
setCommentReplyBody={setCommentReplyBody}
|
||||||
handleSubmitComment={handleSubmitComment}
|
handleSubmitComment={handleSubmitComment}
|
||||||
|
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
postId: number;
|
postId: number;
|
||||||
|
isLoggedIn: boolean;
|
||||||
authenticityToken: string;
|
authenticityToken: string;
|
||||||
|
|
||||||
comments: Array<IComment>;
|
comments: Array<IComment>;
|
||||||
@@ -45,6 +46,8 @@ class CommentsP extends React.Component<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
isLoggedIn,
|
||||||
|
|
||||||
comments,
|
comments,
|
||||||
replies,
|
replies,
|
||||||
areLoading,
|
areLoading,
|
||||||
@@ -55,17 +58,22 @@ class CommentsP extends React.Component<Props> {
|
|||||||
submitComment,
|
submitComment,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const postReply = replies.find(reply => reply.commentId === -1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="commentsContainer">
|
<div className="commentsContainer">
|
||||||
<NewComment
|
<NewComment
|
||||||
body={replies.find(reply => reply.commentId === -1) && replies.find(reply => reply.commentId === -1).body}
|
body={postReply && postReply.body}
|
||||||
parentId={null}
|
parentId={null}
|
||||||
|
isSubmitting={postReply && postReply.isSubmitting}
|
||||||
handleChange={
|
handleChange={
|
||||||
(e: FormEvent) => (
|
(e: FormEvent) => (
|
||||||
setCommentReplyBody(-1, (e.target as HTMLTextAreaElement).value)
|
setCommentReplyBody(-1, (e.target as HTMLTextAreaElement).value)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
handleSubmit={this._handleSubmitComment}
|
handleSubmit={this._handleSubmitComment}
|
||||||
|
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{ areLoading ? <Spinner /> : null }
|
{ areLoading ? <Spinner /> : null }
|
||||||
@@ -83,6 +91,7 @@ class CommentsP extends React.Component<Props> {
|
|||||||
handleSubmitComment={this._handleSubmitComment}
|
handleSubmitComment={this._handleSubmitComment}
|
||||||
parentId={null}
|
parentId={null}
|
||||||
level={1}
|
level={1}
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,21 +2,31 @@ import * as React from 'react';
|
|||||||
import { FormEvent } from 'react';
|
import { FormEvent } from 'react';
|
||||||
|
|
||||||
import Button from '../shared/Button';
|
import Button from '../shared/Button';
|
||||||
|
import Spinner from '../shared/Spinner';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
body: string;
|
body: string;
|
||||||
parentId: number;
|
parentId: number;
|
||||||
|
isSubmitting: boolean;
|
||||||
handleChange(e: FormEvent): void;
|
handleChange(e: FormEvent): void;
|
||||||
handleSubmit(body: string, parentId: number): void;
|
handleSubmit(body: string, parentId: number): void;
|
||||||
|
|
||||||
|
isLoggedIn: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NewComment = ({
|
const NewComment = ({
|
||||||
body,
|
body,
|
||||||
parentId,
|
parentId,
|
||||||
|
isSubmitting,
|
||||||
handleChange,
|
handleChange,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
|
|
||||||
|
isLoggedIn,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<div className="newCommentForm">
|
<div className="newCommentForm">
|
||||||
|
{
|
||||||
|
isLoggedIn ?
|
||||||
|
<React.Fragment>
|
||||||
<textarea
|
<textarea
|
||||||
value={body}
|
value={body}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
@@ -26,8 +36,12 @@ const NewComment = ({
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => handleSubmit(body, parentId)}
|
onClick={() => handleSubmit(body, parentId)}
|
||||||
className="submitCommentButton">
|
className="submitCommentButton">
|
||||||
Submit
|
{ isSubmitting ? <Spinner /> : 'Submit' }
|
||||||
</Button>
|
</Button>
|
||||||
|
</React.Fragment>
|
||||||
|
:
|
||||||
|
<a href="/users/sign_in" className="loginInfo">You need to log in to post comments.</a>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class PostP extends React.Component<Props> {
|
|||||||
post,
|
post,
|
||||||
postStatuses,
|
postStatuses,
|
||||||
|
|
||||||
|
isLoggedIn,
|
||||||
isPowerUser,
|
isPowerUser,
|
||||||
authenticityToken,
|
authenticityToken,
|
||||||
|
|
||||||
@@ -73,6 +74,7 @@ class PostP extends React.Component<Props> {
|
|||||||
|
|
||||||
<Comments
|
<Comments
|
||||||
postId={this.props.postId}
|
postId={this.props.postId}
|
||||||
|
isLoggedIn={isLoggedIn}
|
||||||
authenticityToken={authenticityToken}
|
authenticityToken={authenticityToken}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
import { FormEvent } from 'react';
|
import { FormEvent } from 'react';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: string;
|
children: any;
|
||||||
onClick(e: FormEvent): void;
|
onClick(e: FormEvent): void;
|
||||||
className?: string;
|
className?: string;
|
||||||
outline?: boolean;
|
outline?: boolean;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
const Spinner = () => (
|
const Spinner = () => (
|
||||||
<div className="spinner-border d-block mx-auto" role="status">
|
<div className="spinner-grow d-block mx-auto" role="status">
|
||||||
<span className="sr-only">Loading...</span>
|
<span className="sr-only">Loading...</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
a {
|
||||||
|
color: #333;
|
||||||
|
|
||||||
|
&:hover { color: inherit; }
|
||||||
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
@extend .card;
|
@extend .card;
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,7 @@
|
|||||||
margin-bottom: auto;
|
margin-bottom: auto;
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loginInfo {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user