diff --git a/server/db/seed.js b/server/db/seed.js
index 35380f8..73b8769 100755
--- a/server/db/seed.js
+++ b/server/db/seed.js
@@ -22,7 +22,8 @@ async function runSeed() {
await c1.addReply(2)
- await c2.addReplies([c3, c4, c5])
+ await c2.addReplies([c3, c4])
+ await c5.setParent(c4)
await c6.setParent(c1)
diff --git a/src/App.js b/src/App.js
index dd2d6b7..4629786 100644
--- a/src/App.js
+++ b/src/App.js
@@ -5,18 +5,6 @@ import axios from 'axios'
const API = 'http://localhost:5555'
console.log('Using API at ' + API)
-const comments = [
- { id: 1, text: 'c1', replies: [] },
- {
- id: 2,
- text: 'c2',
- replies: [
- { id: 3, text: 'c3', replies: [] },
- { id: 4, text: 'c4', replies: [] },
- ],
- },
-]
-
class App extends React.Component {
constructor() {
super()
diff --git a/src/Components/Comments/SingleComment/CollapsedComment.js b/src/Components/Comments/SingleComment/CollapsedComment.js
index f6ff902..cc712fb 100644
--- a/src/Components/Comments/SingleComment/CollapsedComment.js
+++ b/src/Components/Comments/SingleComment/CollapsedComment.js
@@ -2,7 +2,7 @@ import React from 'react'
const CollapsedComment = props => {
return (
-
+
username
@@ -14,7 +14,7 @@ const CollapsedComment = props => {
color: 'blue',
cursor: 'pointer',
}}
- onClick={props.toggleCollapse}
+ onClick={() => props.toggleCollapse(props.id)}
>
expand
diff --git a/src/Components/Comments/SingleComment/ExpandedComment.js b/src/Components/Comments/SingleComment/ExpandedComment.js
index 92f8c83..6954424 100644
--- a/src/Components/Comments/SingleComment/ExpandedComment.js
+++ b/src/Components/Comments/SingleComment/ExpandedComment.js
@@ -1,26 +1,29 @@
import React from 'react'
const ExpandedComment = props => {
const { text } = props
-
return (
-
+
username
July 9 2019, 01:32:27 UTC
-
- collapse
-
+ {props.replies.length > 0 ? (
+ props.toggleCollapse(props.id)}
+ >
+ collapse
+
+ ) : (
+ ''
+ )}
diff --git a/src/Components/Comments/SingleComment/index.js b/src/Components/Comments/SingleComment/index.js
index d6738f2..1b4417b 100644
--- a/src/Components/Comments/SingleComment/index.js
+++ b/src/Components/Comments/SingleComment/index.js
@@ -3,9 +3,7 @@ import ExpandedComment from './ExpandedComment'
import CollapsedComment from './CollapsedComment'
const SingleComment = props => {
- console.log(props)
- const { collapsed } = props
- if (collapsed) return
+ if (props.collapsed) return
return
}
diff --git a/src/Components/Comments/index.js b/src/Components/Comments/index.js
index 90fbe6e..a15cfe0 100644
--- a/src/Components/Comments/index.js
+++ b/src/Components/Comments/index.js
@@ -5,39 +5,57 @@ import uuid from 'uuid'
class ThreadList extends React.Component {
constructor() {
super()
- this.state = { collapsed: false }
this.toggleCollapse = this.toggleCollapse.bind(this)
}
- toggleCollapse() {
- this.setState({ collapsed: !this.state.collapsed })
+ toggleCollapse(id) {
+ // select passed comment from the state, toggle it and put it all back
+ const otherComments = this.props.comments.filter(c => c.id !== id)
+ const comment = this.props.comments.find(c => c.id === id)
+ comment['collapsed'] = !comment.collapsed
+ console.log('toggled: ', comment)
+ this.setState({ comments: otherComments.concat(comment) })
}
render() {
- const { comments } = this.props
- console.log(comments)
-
+ const comments = this.props.comments.filter(
+ // only show comments for this parent / thread
+ c =>
+ (!c.parentId && !this.props.threadLevel) ||
+ c.parentId === this.props.threadLevel
+ )
+ console.log('showing comments for thread', this.props.threadLevel, comments)
return (
{comments.map(comment => {
- return (
-
-
-
- {comment.replies && (
-
0) {
+ return (
+
+
- )}
-
- )
+
+ )
+ } else {
+ return (
+
+
+ {!comment.collapsed && (
+
+ )}
+
+ )
+ }
})}
)