<commit_before>import React, { Component, PropTypes } from 'react';
import { isDirty } from 'redux-form';
import { connect } from 'react-redux';
import RaisedButton from 'material-ui/RaisedButton';
import { withRouter } from 'react-router';
import MeetingForm from './MeetingForm';

import meetingActions from '../../actions/meetings';
import * as headerActions from '../../actions/header';

class MeetingEdit extends Component {
  constructor() {
    super();
    this.onDelete = this.onDelete.bind(this);
    this.onSubmit = this.onSubmit.bind(this);
    this.warnIfUnsavedChanges = this.warnIfUnsavedChanges.bind(this);
  }

  componentDidMount() {
    this.props.setText('Edit Meeting');
    console.log(`componentDidMount ${this.props.location.pathname} ${this.props.route.path}`);

    this.props.router.setRouteLeaveHook(this.props.route, this.warnIfUnsavedChanges);
    window.onbeforeunload = () => this.warnIfUnsavedChanges();
  }

  componentDidUpdate(prevProps) {
    if (this.props.route.path !== prevProps.route.path) {
    this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route));
    }
  }

  onDelete() {
    this.props.remove(this.props.params.id);
  }

  onSubmit(meeting) {
    this.props.update(this.props.params.id, meeting);
  }

  warnIfUnsavedChanges(nextLocation) {
    if (this.props.dirty) {
      return 'Are you sure you want to leave this page? You have unsaved changes.';
    }
  }

  render() {
    return (
      <div className="container">
        <MeetingForm
          {...this.props}
          onSubmit={this.onSubmit}
        />
        <RaisedButton
          label="Delete"
          secondary={true}
          style={{ marginTop: 20 }}
          onTouchTap={this.onDelete}
        />
      </div>
    );
  }
}

MeetingEdit.propTypes = {
  update: PropTypes.func.isRequired,
  remove: PropTypes.func.isRequired,
  setText: PropTypes.func.isRequired,
  params: PropTypes.object.isRequired,
  router: PropTypes.shape({
    setRouteLeaveHook: PropTypes.func,
  }).isRequired,
  // route: PropTypes.object.isRequired,
  location: PropTypes.shape({
    pathname: PropTypes.string,
  }),
};

const mapStateToProps = (state) => {
  const meeting = state.meetings.activeMeeting;
  const initialValues = {
    ...meeting,
    meetingDate: meeting.meetingDate ? new Date(meeting.meetingDate) : null,
  };
  return {
    initialValues,
    formType: 'edit',
    dirty: isDirty('meeting')(state),
    error: state.meetings.error,
    directs: state.directs.list,
    directsKeys: state.directs.keys,
  };
};

const mapDispatchToProps = {
  update: meetingActions.update,
  remove: meetingActions.remove,
  setText: headerActions.setText,
};

export default connect(mapStateToProps, mapDispatchToProps)(withRouter(MeetingEdit));<commit_msg>fix(MeetingEdit.jsx): was always asking to confirm navigation<commit_after>import React, { Component, PropTypes } from 'react';
import { isDirty, hasSubmitSucceeded } from 'redux-form';
import { connect } from 'react-redux';
import RaisedButton from 'material-ui/RaisedButton';
import { withRouter } from 'react-router';
import MeetingForm from './MeetingForm';

import meetingActions from '../../actions/meetings';
import * as headerActions from '../../actions/header';

class MeetingEdit extends Component {
  constructor() {
    super();
    this.onDelete = this.onDelete.bind(this);
    this.onSubmit = this.onSubmit.bind(this);
    this.warnIfUnsavedChanges = this.warnIfUnsavedChanges.bind(this);
  }

  componentDidMount() {
    this.props.setText('Edit Meeting');
    this.props.router.setRouteLeaveHook(this.props.route, this.warnIfUnsavedChanges);
    window.onbeforeunload = () => this.warnIfUnsavedChanges();
  }

  componentDidUpdate(prevProps) {
    if (this.props.route.path !== prevProps.route.path) {
      this.props.router.setRouteLeaveHook(
        this.props.route, (route) => this.warnIfUnsavedChanges(route)
      );
    }
  }

  onDelete() {
    this.props.remove(this.props.params.id);
  }

  onSubmit(meeting) {
    this.props.update(this.props.params.id, meeting);
  }

  warnIfUnsavedChanges(nextLocation) {
    if (this.props.dirty && !this.props.submitted) {
      return 'Are you sure you want to leave this page? You have unsaved changes.';
    }
  }

  render() {
    return (
      <div className="container">
        <MeetingForm
          {...this.props}
          onSubmit={this.onSubmit}
        />
        <RaisedButton
          label="Delete"
          secondary={true}
          style={{ marginTop: 20 }}
          onTouchTap={this.onDelete}
        />
      </div>
    );
  }
}

MeetingEdit.propTypes = {
  update: PropTypes.func.isRequired,
  remove: PropTypes.func.isRequired,
  setText: PropTypes.func.isRequired,
  params: PropTypes.object.isRequired,
  router: PropTypes.shape({
    setRouteLeaveHook: PropTypes.func,
  }).isRequired,
};

const mapStateToProps = (state) => {
  const meeting = state.meetings.activeMeeting;
  const initialValues = {
    ...meeting,
    meetingDate: meeting.meetingDate ? new Date(meeting.meetingDate) : null,
  };
  return {
    initialValues,
    formType: 'edit',
    dirty: isDirty('meeting')(state),
    submitted: hasSubmitSucceeded('meeting')(state),
    error: state.meetings.error,
    directs: state.directs.list,
    directsKeys: state.directs.keys,
  };
};

const mapDispatchToProps = {
  update: meetingActions.update,
  remove: meetingActions.remove,
  setText: headerActions.setText,
};

export default connect(mapStateToProps, mapDispatchToProps)(withRouter(MeetingEdit));
{'fraction_non_alphanumeric': 0.13407420684710522, 'fraction_numerical': 0.000716974368166338, 'mean_word_length': 3.4568690095846644, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '7377721', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1741, 'n_words': 319}