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() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; this.loadReplies(); } loadReplies() { this.setState({ replies: [] }) const { mid } = this.props.match.params; let params = { mid: mid } if (this.props.visitor && this.props.visitor.hash) { params.hash = this.props.visitor.hash }; const url = `https://api.juick.com/thread?${qs.stringify(params)}`; fetch(url) .then(response => { return response.json() }) .then(data => { let msg = data.shift(); this.setState({ msg: msg, replies: data }) } ).catch(ex => { console.log(ex); }); } loaded() { return this.state.msg.mid; } render() { const msg = this.state.msg; return ( { this.loaded() && (
{ this.props.visitor.uid > 0 && }

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

) }
) } }