diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index df7d4224..c388c72a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -5,7 +5,7 @@ class CommentsController < ApplicationController comments = Comment .where(post_id: params[:post_id]) .left_outer_joins(:user) - .select('comments.id, comments.body, comments.updated_at, users.full_name as user_full_name') + .select('comments.id, comments.body, comments.parent_id, comments.updated_at, users.full_name as user_full_name') .order(updated_at: :desc) render json: comments diff --git a/app/javascript/components/Comments/Comment.tsx b/app/javascript/components/Comments/Comment.tsx new file mode 100644 index 00000000..cc687b25 --- /dev/null +++ b/app/javascript/components/Comments/Comment.tsx @@ -0,0 +1,36 @@ +import * as React from 'react'; + +import { MutedText } from '../shared/CustomTexts'; + +interface Props { + id: number; + body: string; + parentId: number; + userFullName: string; + updatedAt: string; + + level: number; +} + +const Comment = ({ + id, + body, + parentId, + userFullName, + updatedAt, + + level, +}: Props) => ( +
+
+ {userFullName} +
+

{body}

+
+ Reply + {updatedAt} +
+
+); + +export default Comment; \ No newline at end of file diff --git a/app/javascript/components/Comments/CommentList.tsx b/app/javascript/components/Comments/CommentList.tsx new file mode 100644 index 00000000..635717a7 --- /dev/null +++ b/app/javascript/components/Comments/CommentList.tsx @@ -0,0 +1,33 @@ +import * as React from 'react'; + +import Comment from './Comment'; + +import IComment from '../../interfaces/IComment'; + +interface Props { + comments: Array; + parentId: number; + level: number; +} + +const CommentList = ({ comments, parentId, level }: Props) => ( + + {comments.map((comment, i) => { + if (comment.parentId === parentId) { + return ( +
+ + + +
+ ); + } else return null; + })} +
+); + +export default CommentList; \ No newline at end of file diff --git a/app/javascript/components/Comments/CommentsP.tsx b/app/javascript/components/Comments/CommentsP.tsx index d799f7e2..74b412d5 100644 --- a/app/javascript/components/Comments/CommentsP.tsx +++ b/app/javascript/components/Comments/CommentsP.tsx @@ -1,5 +1,9 @@ import * as React from 'react'; +import CommentList from './CommentList'; +import Spinner from '../shared/Spinner'; +import { DangerText } from '../shared/CustomTexts'; + import IComment from '../../interfaces/IComment'; interface Props { @@ -25,10 +29,17 @@ class CommentsP extends React.Component { } = this.props; return ( -
- {comments.map((comment, i) => ( -
{comment.body}
- ))} +
+

Comments

+ + { areLoading ? : null } + { error ? {error} : null } + +
); } diff --git a/app/javascript/interfaces/IComment.ts b/app/javascript/interfaces/IComment.ts index 7a5d44ef..42f51017 100644 --- a/app/javascript/interfaces/IComment.ts +++ b/app/javascript/interfaces/IComment.ts @@ -1,6 +1,7 @@ interface IComment { id: number; body: string; + parentId: number; userFullName: string; updatedAt: string; } diff --git a/app/javascript/interfaces/json/IComment.ts b/app/javascript/interfaces/json/IComment.ts index 6ade8404..4d5da8f5 100644 --- a/app/javascript/interfaces/json/IComment.ts +++ b/app/javascript/interfaces/json/IComment.ts @@ -1,6 +1,7 @@ interface ICommentJSON { id: number; body: string; + parent_id: number; user_full_name: string; updated_at: string; } diff --git a/app/javascript/reducers/commentReducer.ts b/app/javascript/reducers/commentReducer.ts index 0ad233b0..9a6d1915 100644 --- a/app/javascript/reducers/commentReducer.ts +++ b/app/javascript/reducers/commentReducer.ts @@ -7,8 +7,9 @@ import IComment from '../interfaces/IComment'; const initialState: IComment = { id: 0, body: '', - userFullName: '', - updatedAt: '', + parentId: null, + userFullName: '', + updatedAt: undefined, }; const commentReducer = ( @@ -20,6 +21,7 @@ const commentReducer = ( return { id: action.comment.id, body: action.comment.body, + parentId: action.comment.parent_id, userFullName: action.comment.user_full_name, updatedAt: action.comment.updated_at, }; diff --git a/app/javascript/stylesheets/components/Comments.scss b/app/javascript/stylesheets/components/Comments.scss new file mode 100644 index 00000000..f44c567f --- /dev/null +++ b/app/javascript/stylesheets/components/Comments.scss @@ -0,0 +1,21 @@ +.comments { + .commentList > .commentList { + padding-left: 32px; + } + + .comment { + margin-bottom: 32px; + + .commentHeader { + @extend + .font-weight-bolder; + + font-size: 17px; + } + + .commentBody { + @extend + .my-2; + } + } +} \ No newline at end of file diff --git a/app/javascript/stylesheets/main.scss b/app/javascript/stylesheets/main.scss index 1db06dc3..6b60134f 100644 --- a/app/javascript/stylesheets/main.scss +++ b/app/javascript/stylesheets/main.scss @@ -6,11 +6,8 @@ @import 'general/index'; @import 'general/navbar'; -/* - Components stylesheets are not imported here. Instead, - they are imported in the specific React components - that use them -*/ +/* Components */ @import 'components/Board'; +@import 'components/Comments'; @import 'components/Post'; @import 'components/Roadmap'; \ No newline at end of file