diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index b367af32..2bb24a4b 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -11,7 +11,11 @@ export default class Root extends Component { constructor(props) { super(props); - this.addThread = this.addThread.bind(this); + this.state = { + loaded: false, + }; + + this.addComment = this.addComment.bind(this); } componentDidMount() { @@ -25,22 +29,32 @@ export default class Root extends Component { }); } - addThread({ text, id }) { + addComment({ text, id, pid }) { const { comments } = this.state; - - const newComments = [{ + const newComment = { comment: { id, text, user: store.get('user'), time: new Date(), + ...(pid ? { pid } : {}), }, - }].concat(comments); + }; + + const newComments = pid + ? Root.pasteReply({ comments, newComment }) + : [newComment].concat(comments); this.setState({ comments: newComments }); + + api.getComment({ id }).then(comment => { + this.setState({ + comments: Root.replaceComment({ comments: newComments, newComment: comment }), + }); + }); } - render({}, { comments = [], user = {}, loaded = false }) { + render({}, { comments = [], user = {}, loaded }) { if (!loaded) { return (