<commit_before>import React, {Component} from 'react';

//93 把reducer 里面装入state里面的东西调入 component
import { connect } from 'react-redux';
import {fetchPost,deletePost} from '../actions/index';

//94 add linker
import {Link} from 'react-router';

class PostsShow extends Component {
  componentWillMount(){
    this.props.fetchPost(this.props.params.id);
  }
  onDeleteClick(){
    this.props.deletePost(this.props.params.id);
  }

  render() {
    const {post} = this.props;
    console.log(this.props.post);
    if(!this.props.post) {
      return <div>Loading....</div>
    }
    return (
      <div>
        <Link to="/">Back To Index</Link>
        <button className="btn btn-danger pull-xs-right"
        onClick={this.onDeleteClick.bind(this)}>
          Delete Post<commit_msg>97 删除后返回index的page<commit_after>import React, {Component, PropTypes} from 'react';

//93 把reducer 里面装入state里面的东西调入 component
import { connect } from 'react-redux';
import {fetchPost,deletePost} from '../actions/index';

//94 add linker
import {Link} from 'react-router';

class PostsShow extends Component {
  static contextTypes = {
    router: PropTypes.object
  }

  componentWillMount(){
    this.props.fetchPost(this.props.params.id);
  }
  onDeleteClick(){
    this.props.deletePost(this.props.params.id)
    .then(() => {
      this.context.router.push('/');
    });
  }

  render() {
    const {post} = this.props;
    console.log(this.props.post);
    if(!this.props.post) {
      return <div>Loading....</div>
    }
    return (
      <div>
        <Link to="/">Back To Index</Link>
        <button className="btn btn-danger pull-xs-right"
        onClick={this.onDeleteClick.bind(this)}>
          Delete Post
{'fraction_non_alphanumeric': 0.15158636897767333, 'fraction_numerical': 0.005875440658049354, 'mean_word_length': 3.0547619047619046, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1853869', 'n_tokens_mistral': 572, 'n_tokens_neox': 574, 'n_words': 113}