From 38345f9c42a205277ad108c2d1d3ebfae5f35a87 Mon Sep 17 00:00:00 2001 From: riggraz Date: Fri, 20 Sep 2019 18:43:24 +0200 Subject: [PATCH] Improve comments component --- .../components/Comments/Comment.tsx | 7 ++++ .../components/Comments/CommentList.tsx | 8 +++++ .../components/Comments/CommentsP.tsx | 11 +++++- .../components/Comments/NewComment.tsx | 36 +++++++++++++------ app/javascript/components/Post/PostP.tsx | 2 ++ app/javascript/components/shared/Button.tsx | 2 +- app/javascript/components/shared/Spinner.tsx | 2 +- .../stylesheets/general/_components.scss | 6 ++++ .../stylesheets/general/_index.scss | 4 +++ 9 files changed, 64 insertions(+), 14 deletions(-) diff --git a/app/javascript/components/Comments/Comment.tsx b/app/javascript/components/Comments/Comment.tsx index b489fe18..647fa6da 100644 --- a/app/javascript/components/Comments/Comment.tsx +++ b/app/javascript/components/Comments/Comment.tsx @@ -20,6 +20,8 @@ interface Props { handleToggleCommentReply(): void; handleCommentReplyBodyChange(e: FormEvent): void; handleSubmitComment(body: string, parentId: number): void; + + isLoggedIn: boolean; } const Comment = ({ @@ -34,6 +36,8 @@ const Comment = ({ handleToggleCommentReply, handleCommentReplyBodyChange, handleSubmitComment, + + isLoggedIn, }: Props) => (
@@ -52,8 +56,11 @@ const Comment = ({ : null diff --git a/app/javascript/components/Comments/CommentList.tsx b/app/javascript/components/Comments/CommentList.tsx index 674409f1..f2b3fe4e 100644 --- a/app/javascript/components/Comments/CommentList.tsx +++ b/app/javascript/components/Comments/CommentList.tsx @@ -15,6 +15,8 @@ interface Props { toggleCommentReply(commentId: number): void; setCommentReplyBody(commentId: number, body: string): void; handleSubmitComment(body: string, parentId: number): void; + + isLoggedIn: boolean; } const CommentList = ({ @@ -26,6 +28,8 @@ const CommentList = ({ toggleCommentReply, setCommentReplyBody, handleSubmitComment, + + isLoggedIn, }: Props) => ( {comments.map((comment, i) => { @@ -43,6 +47,8 @@ const CommentList = ({ } handleSubmitComment={handleSubmitComment} {...comment} + + isLoggedIn={isLoggedIn} />
); diff --git a/app/javascript/components/Comments/CommentsP.tsx b/app/javascript/components/Comments/CommentsP.tsx index 4efd3c5f..58fcb7c6 100644 --- a/app/javascript/components/Comments/CommentsP.tsx +++ b/app/javascript/components/Comments/CommentsP.tsx @@ -11,6 +11,7 @@ import { CommentRepliesState } from '../../reducers/commentRepliesReducer'; interface Props { postId: number; + isLoggedIn: boolean; authenticityToken: string; comments: Array; @@ -45,6 +46,8 @@ class CommentsP extends React.Component { render() { const { + isLoggedIn, + comments, replies, areLoading, @@ -55,17 +58,22 @@ class CommentsP extends React.Component { submitComment, } = this.props; + const postReply = replies.find(reply => reply.commentId === -1); + return (
reply.commentId === -1) && replies.find(reply => reply.commentId === -1).body} + body={postReply && postReply.body} parentId={null} + isSubmitting={postReply && postReply.isSubmitting} handleChange={ (e: FormEvent) => ( setCommentReplyBody(-1, (e.target as HTMLTextAreaElement).value) ) } handleSubmit={this._handleSubmitComment} + + isLoggedIn={isLoggedIn} /> { areLoading ? : null } @@ -83,6 +91,7 @@ class CommentsP extends React.Component { handleSubmitComment={this._handleSubmitComment} parentId={null} level={1} + isLoggedIn={isLoggedIn} />
); diff --git a/app/javascript/components/Comments/NewComment.tsx b/app/javascript/components/Comments/NewComment.tsx index 31494522..f6f230b1 100644 --- a/app/javascript/components/Comments/NewComment.tsx +++ b/app/javascript/components/Comments/NewComment.tsx @@ -2,32 +2,46 @@ import * as React from 'react'; import { FormEvent } from 'react'; import Button from '../shared/Button'; +import Spinner from '../shared/Spinner'; interface Props { body: string; parentId: number; + isSubmitting: boolean; handleChange(e: FormEvent): void; handleSubmit(body: string, parentId: number): void; + + isLoggedIn: boolean; } const NewComment = ({ body, parentId, + isSubmitting, handleChange, handleSubmit, + + isLoggedIn, }: Props) => (
-