diff options
author | 2018-06-16 18:37:01 +0300 | |
---|---|---|
committer | 2023-01-13 10:37:52 +0300 | |
commit | 683bd826dfc3885a8f15f9db4e0a8af7f158c967 (patch) | |
tree | 6400e380b30a2686b38fd323250cf3c6ce5ee68a /vnext/src/components/Thread.js | |
parent | c754cbba643d7ea1e6312c685f4b321ab5efba6b (diff) |
loadReplies
Diffstat (limited to 'vnext/src/components/Thread.js')
-rw-r--r-- | vnext/src/components/Thread.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index a17a2022..5393d7d3 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -1,6 +1,9 @@ import 'whatwg-fetch'; import React from 'react'; +import Message from './Message'; +import Spinner from './Spinner'; + export default class Thread extends React.Component { constructor(props) { super(props); @@ -10,14 +13,27 @@ export default class Thread extends React.Component { }; } componentDidMount() { + this.loadReplies(); + } + loadReplies() { + this.setState({ replies: []}) + const { mid } = this.props.match.params; + const url = `https://api.juick.com/thread?mid=${mid}`; + fetch(url) + .then(response => { + return response.json() + }) + .then(data => + this.setState({ replies: data }) + ).catch(ex => { + console.log(ex); + }); } render() { - const { user, mid } = this.props.match.params; - return ( - <div> - <h1>{user}</h1> - <p>{mid}</p> - </div> + return this.state.replies && this.state.replies.length > 0 ? ( + <Message data={this.state.replies[0]}/> + ) : ( + <Spinner /> ); } } |