aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/app.js
blob: 7971c71f4f336380bd82b1399f31534d88b2e600 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import "whatwg-fetch"
import React from "react"
import PropTypes from "prop-types"
import ReactDOM from "react-dom"

import Message from "./components/Message.jsx"

class Page extends React.Component {
  constructor(props) {
    super(props)
    this.state = {msgs: [], loading: false}
  }
  render() { 
    var nodes = this.state.msgs.map(msg => {
      return (<Message key={msg.mid} mid={msg.mid} user={msg.user} body={msg.body} timestamp={msg.timestamp}/>) 
    });
    return (<div className="msgs">{nodes}</div>)    
  }
  componentDidMount() {
      fetch(this.props.source)
          .then(response => {
              return response.json()
          })
          .then(data =>
              this.setState({ msgs: data })
          ).catch(ex => {
        console.log(ex)
      });
  }
};

Page.propTypes = {
    msgs: PropTypes.array,
    source: PropTypes.string.isRequired
}

ReactDOM.render(<Page source="https://api.juick.com/messages" />, document.getElementById("content"));