From 56f915197db66679743bacae38ad5e464a30e5de Mon Sep 17 00:00:00 2001 From: notnull Date: Sat, 13 Jul 2019 07:56:43 -0400 Subject: [PATCH] collapsible recursive comments --- src/Components/AllComments/AllCommentsView.js | 9 +++-- .../AllComments/CollapsedComment.js | 24 ++++++++++++ src/Components/AllComments/CommentList.js | 6 +-- src/Components/AllComments/CommentRow.js | 37 +++++++++++++------ src/Components/AllComments/ExpandedComment.js | 32 ++++++++++++++++ src/Components/AllComments/ParentComment.js | 36 ------------------ src/Components/AllComments/Replies.js | 23 ++---------- src/Components/AllComments/SingleComment.js | 10 +++++ 8 files changed, 104 insertions(+), 73 deletions(-) create mode 100644 src/Components/AllComments/CollapsedComment.js create mode 100644 src/Components/AllComments/ExpandedComment.js delete mode 100644 src/Components/AllComments/ParentComment.js create mode 100644 src/Components/AllComments/SingleComment.js diff --git a/src/Components/AllComments/AllCommentsView.js b/src/Components/AllComments/AllCommentsView.js index 4e7b5b5..6b0947a 100644 --- a/src/Components/AllComments/AllCommentsView.js +++ b/src/Components/AllComments/AllCommentsView.js @@ -1,9 +1,12 @@ import React from 'react' import CommentList from './CommentList' +import { Container } from 'react-bootstrap' -//this could probably be a stateful component -// that way, we can add some controllers const AllCommentsView = props => { - return + return ( + + + + ) } export default AllCommentsView diff --git a/src/Components/AllComments/CollapsedComment.js b/src/Components/AllComments/CollapsedComment.js new file mode 100644 index 0000000..8f02b22 --- /dev/null +++ b/src/Components/AllComments/CollapsedComment.js @@ -0,0 +1,24 @@ +import React from 'react' + +export default props => { + return ( +
  • +
    + profile + username + One day ago + + expand + +
    +
  • + ) +} diff --git a/src/Components/AllComments/CommentList.js b/src/Components/AllComments/CommentList.js index 3f7168d..2026fc7 100644 --- a/src/Components/AllComments/CommentList.js +++ b/src/Components/AllComments/CommentList.js @@ -1,16 +1,14 @@ import React from 'react' import CommentRow from './CommentRow' -import { Container } from 'react-bootstrap' const CommentList = props => { - console.log('CommentList', props) const { comments } = props return ( -
    +
      {comments.map(comment => ( ))} -
    + ) } diff --git a/src/Components/AllComments/CommentRow.js b/src/Components/AllComments/CommentRow.js index 193ad1a..003d810 100644 --- a/src/Components/AllComments/CommentRow.js +++ b/src/Components/AllComments/CommentRow.js @@ -1,18 +1,33 @@ import React from 'react' -import ParentComment from './ParentComment' +import SingleComment from './SingleComment' import Replies from './Replies' -const CommentRow = props => { - const { text, replies } = props +//todo: rename to 'thread' +class CommentRow extends React.Component { + constructor() { + super() + this.state = {} + this.toggleCollapse = this.toggleCollapse.bind(this) + } - const replyCount = replies.length - const parentId = props.id - return ( -
    - - -
    - ) + toggleCollapse() { + this.setState({ collapsed: !this.state.collapsed }) + } + + render() { + const { text, replies } = this.props + + return ( +
    + + +
    + ) + } } export default CommentRow diff --git a/src/Components/AllComments/ExpandedComment.js b/src/Components/AllComments/ExpandedComment.js new file mode 100644 index 0000000..dfdd36f --- /dev/null +++ b/src/Components/AllComments/ExpandedComment.js @@ -0,0 +1,32 @@ +import React from 'react' + +export default props => { + const { text } = props + + return ( +
  • +
    + profile +
    + username +
    + July 9 2019, 01:32:27 UTC + + collapse + +
    +
    +
    +
    {text}
    + reply +
  • + ) +} diff --git a/src/Components/AllComments/ParentComment.js b/src/Components/AllComments/ParentComment.js deleted file mode 100644 index 394d005..0000000 --- a/src/Components/AllComments/ParentComment.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' -import { Row, Col, Image } from 'react-bootstrap' - -export default props => { - const { replyCount, text } = props - return ( - - - - - - - Title - - - {text} - - - - {replyCount} {replyCount === 1 ? 'comment' : 'comments'} - - - - - ) -} diff --git a/src/Components/AllComments/Replies.js b/src/Components/AllComments/Replies.js index 6ebf196..9622cd4 100644 --- a/src/Components/AllComments/Replies.js +++ b/src/Components/AllComments/Replies.js @@ -1,6 +1,5 @@ import React from 'react' import CommentList from './CommentList' -import { Row, Col } from 'react-bootstrap' class Replies extends React.Component { constructor() { @@ -9,25 +8,11 @@ class Replies extends React.Component { } render() { - const { replies, parentId } = this.props - - if (replies.length > 2) { - return ( - - - Read replies... - - - ) - } + const { replies } = this.props return ( - - - {replies.map(reply => ( - - ))} - - +
    + +
    ) } } diff --git a/src/Components/AllComments/SingleComment.js b/src/Components/AllComments/SingleComment.js new file mode 100644 index 0000000..6b88047 --- /dev/null +++ b/src/Components/AllComments/SingleComment.js @@ -0,0 +1,10 @@ +import React from 'react' +import ExpandedComment from './ExpandedComment' +import CollapsedComment from './CollapsedComment' + +export default props => { + const { text, collapsed, toggleCollapse } = props + if (collapsed) + return + return +}