aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/Discover.js
blob: 7fde3d8849718a8d6e36c1350e710f3798ae850c (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import "whatwg-fetch"
import React from "react"
import PropTypes from "prop-types"
import queryString from "query-string"

import Message from "./Message"

export default class Discover extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      msgs: [],
      loading: false,
      search: this.props.location.search
    }
    this.loadMessages = this.loadMessages.bind(this);
  }
  componentDidMount() {
    this.loadMessages();
  }
  componentWillReceiveProps(props) {
    if (props.params != this.props.params) {
      this.loadMessages();
    }    
  }
  loadMessages() {
    const url = "https://api.juick.com/messages" + this.state.search;
    fetch(url)
        .then(response => {
            return response.json()
        })
        .then(data =>
            this.setState({ msgs: data })
        ).catch(ex => {
      console.log(ex)
    });
  }

  render() { 
    var nodes = this.state.msgs.map(msg => {
      return (<Message key={msg.mid} data={msg}/>) 
    });    
    return (
      <div className="msgs" id="content">{nodes}</div>
    )    
  }
};

Discover.propTypes = {
  msgs: PropTypes.array
}