import React from 'react'; import { Link } from 'react-router-dom'; import moment from 'moment'; import Message from './Message'; import MessageInput from './MessageInput'; import Spinner from './Spinner'; import Avatar from './Avatar'; import Icon from './Icon'; import Button from './Button'; import { format } from '../utils/embed'; import { getMessages, comment, markReadTracker } from '../api'; export default class Thread extends React.Component { constructor(props) { super(props); const { msg } = (this.props.location.state || {}); this.state = { msg: msg || {}, replies: [], loading: false, active: 0 }; } componentDidMount() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; this.loadReplies(); } loadReplies() { this.setState({ replies: [], loading: true }) const { mid } = this.props.match.params; let params = { mid: mid } if (this.props.visitor && this.props.visitor.hash) { params.hash = this.props.visitor.hash }; getMessages('/thread', params) .then(response => { let msg = response.data.shift(); this.setState({ msg: msg, replies: response.data, loading: false, active: 0 }) } ).catch(ex => { console.log(ex); }); } setActive(msg, event) { this.setState({ active: msg.rid || 0 }) } postComment = (template) => { const { mid, rid, body, attach } = template; comment(mid, rid, body, attach).then(res => { this.loadReplies() }) .catch(console.log) } render() { const msg = this.state.msg; return ( { { this.props.visitor.uid > 0 && msg.mid &&

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

} {!this.state.loading ? ( ) : ( )}
}
) } } function Recommendations(props) { const recomms = props.src; return recomms && (
{`Recommended by (${recomms.length}): `} { recomms.map(it => ( {it} )).reduce((prev, curr) => [prev, ', ', curr]) }
) || null; }