import React, { Component } from 'react'
import axios from 'axios'
import FeedHomeV from './FeedHomeV'

class FeedHomeC extends Component {
  constructor(props) {
    super(props)

    this.state = {
      state_matters: null
    }
  }

  queryForFeedItems() {
    console.log("In the queryForFeedItems of Component 'FeedHomeC'")
    const queryParams = sessionStorage.getItem('userID')
    let data = {
      localMatters: ''
    }
    let url = '' +
    'http://localhost:4000/api/home?' +
    'q_uid=' + queryParams
    axios.get(url, data.localMatters)
      .then(res => {
        this.setState({
          state_matters: res.data.results_matters
        })
      })
      .catch(err => {
        console.log('ERROR: ' + err)
      })
  }

  componentDidMount () {
    if (sessionStorage.getItem('token') != null) {
      this.queryForFeedItems()
    }
  }

  render () {
    return (
      <FeedHomeV
        data={this.state.state_matters}
      />
    )
  }
}

export default FeedHomeC
