File size: 1,560 Bytes
597ee18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import { connect } from 'react-redux';
import {parseJSON} from '../utils';

const actions = {
  initPage: (page) => ({
      type: 'PAGE_INIT',
      payload: {
        initedPage: page
      }
  }),
  initialize: (type) => (dispatch) => {
    dispatch(actions.initPage(type));
  }
}

const mapStateToProps = (state) => ({
  location: state.router.location
});

const DEV_SITE = 'http://medialeaks.ru';

class PostPage extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      post: null
    };
  }
  componentDidMount() {
    this.props.dispatch(actions.initialize('post'));
  }
  componentWillMount () {
    return fetch(DEV_SITE + '/wp-json/wp/v2/posts/' + this.props.params.id,{
      method: 'get',
      credentials: 'include',
      headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
      }
    })
    .then(parseJSON)
    .then(post => {
      this.setState({
        post: post
      });
    })
    .catch((error) => console.log(error));
  }
  render(){
    if (!this.state.post) return <div>Загрузка...</div>
    return(
      <div className="post">
        <div className="post_title">
          <div>
            <h1>{this.state.post.title.rendered}</h1>
          </div>
        </div>
        <div className="post_content">
          <div dangerouslySetInnerHTML={{ __html : this.state.post.content.rendered }}></div>
        </div>
      </div>
    )
  }
}

PostPage = connect(mapStateToProps)(PostPage);

export default PostPage;