From 94cb8eaecbca57b104061943ea0670fc618e4236 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 18 Jun 2018 17:07:00 +0300 Subject: Thread replies --- vnext/src/components/Message.js | 12 ++-- vnext/src/components/Thread.js | 145 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 139 insertions(+), 18 deletions(-) (limited to 'vnext/src/components') diff --git a/vnext/src/components/Message.js b/vnext/src/components/Message.js index 53c2a033..5667047c 100644 --- a/vnext/src/components/Message.js +++ b/vnext/src/components/Message.js @@ -12,7 +12,7 @@ export default function Message(props) { const msg = props.data; const visitor = props.visitor; return ( -
+
-

= 0) }}>

+
+

= 0) }}>

+
{msg.photo &&

@@ -87,7 +89,8 @@ export default function Message(props) { Открыть доступ )} -

+ {props.children} + ); } @@ -103,7 +106,8 @@ Message.propTypes = { user: UserType, timestamp: PropTypes.string.isRequired, body: PropTypes.string - }) + }), + children: PropTypes.node }; Tags.propTypes = { diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index 16a662cc..9b26e378 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -1,23 +1,29 @@ import React from 'react'; import * as qs from 'query-string'; +import moment from 'moment'; import Message from './Message'; import Spinner from './Spinner'; +import Avatar from './Avatar'; + +import { format } from '../utils/embed'; export default class Thread extends React.Component { constructor(props) { super(props); this.state = { + msg: {}, replies: [] }; + this.loaded = this.loaded.bind(this); } componentDidMount() { this.loadReplies(); } loadReplies() { - this.setState({ replies: []}) + this.setState({ replies: [] }) const { mid } = this.props.match.params; - let params = { + let params = { mid: mid } if (this.props.visitor && this.props.visitor.hash) { @@ -25,20 +31,131 @@ export default class Thread extends React.Component { }; const url = `https://api.juick.com/thread?${qs.stringify(params)}`; fetch(url) - .then(response => { - return response.json() + .then(response => { + return response.json() + }) + .then(data => { + let msg = data.shift(); + this.setState({ + msg: msg, + replies: data }) - .then(data => - this.setState({ replies: data }) - ).catch(ex => { - console.log(ex); - }); + } + ).catch(ex => { + console.log(ex); + }); + } + loaded() { + return this.state.msg.mid; } render() { - return this.state.replies && this.state.replies.length > 0 ? ( - - ) : ( - - ); + const msg = this.state.msg; + return ( + +
    +
  • + { + this.loaded() ? ( + +
    + +
    +
    + +
    +
    +
    + { + msg.recomm && ( +
    {`Recommended by (${msg.recomm.length}):`} + { + msg.recomm.map((it, index) => ( + {it} + )) + } +
    + ) + } +
    + ) : ( + + ) + } +
  • +
+ { + this.loaded() && ( + +
+ { + this.props.visitor.uid > 0 && + + } +

{`Replies (${msg.replies})`}

+
+ +
+ ) + } +
+ ) + } } -- cgit v1.2.3