<commit_before>var React = require('react/addons');

var api = require('../../lib/api');
var render = require('../../lib/render.jsx');
var router = require('../../lib/router');
var TextInput = require('../../components/text-input/text-input.jsx');

var ProjectSettings = React.createClass({
  mixins: [
    React.addons.LinkedStateMixin,
    router
  ],
  getInitialState: function () {
    return {
      title: ''
    };
  },
  componentWillMount: function () {
    var _this = this;

    // Build up URI for API requests
    var uri = '/users/' + this.state.params.user + '/projects/' + this.state.params.project;

    // Fetch a fresh copy of the project's metadata & update state
    api({
      uri: uri
    }, function (err, body) {
      if (err) {
        // @todo Handle error state (GH-1922)
      }

      _this.setState({
        uri: uri,
        title: body.project.title
      });

      _this.refs.title.setState({
        inputLength: body.project.title.length
      });
    });
  },
  render: function () {
    return (
      <div id="projectSettings">
        <TextInput id="title" ref="title" label="Title" maxlength={25} minlength={4} linkState={this.linkState} />
        <button className="btn" onClick={this.onDoneClick} style={{marginBottom: "20px"}}>Save</button>
      </div>
    );
  },

  /**
   * Click handler for persisting changes to project settings.
   *
   * @return {void}
   */
  onDoneClick: function () {
    var _this = this;

    // @todo Client-side validation
    // console.log(_this.refs.title.validate());

    // Update project settings via the API
    api({
      method: 'PATCH',
      uri: _this.state.uri,
      json: {
        title: _this.state.title
      }
    }, function (err, body) {
      if (err) {
        // @todo Handle error state (GH-1922)
        console.error('Could not update project settings.');
      }

      // "Go back" to the previous activity
      if (window.Android) {
        window.Android.goBack();
      }
    });
  }
});

render(ProjectSettings);<commit_msg>[#2056] Remove save button from project settings<commit_after>var React = require('react/addons');

var api = require('../../lib/api');
var render = require('../../lib/render.jsx');
var TextInput = require('../../components/text-input/text-input.jsx');
var Loading = require('../../components/loading/loading.jsx');

var ProjectSettings = React.createClass({

  mixins: [
    React.addons.LinkedStateMixin,
    require('../../lib/router')
  ],

  getInitialState: function () {
    return {
      title: '',
      loading: false
    };
  },

  uri: function () {
    return '/users/' + this.state.params.user + '/projects/' + this.state.params.project;
  },

  componentWillMount: function () {

    this.load();

    // Set up the save method when we press the back button
    this.props.update({
      onBackPressed: () => {
        this.save(() => window.Android.goBack());
      }
    });

  },

  componentDidUpdate: function (prevProps) {
    if (this.props.isVisible && !prevProps.isVisible) {
      this.load();
    }
  },

  render: function () {
    return (
      <div id="projectSettings">
        <TextInput id="title" ref="title" label="Title" maxlength={25} minlength={4} linkState={this.linkState} />
        <button hidden={window.Android} onClick={this.save}>DEBUG:Save</button>
        <Loading on={this.state.loading} />
      </div>
    );
  },

  /**
   * Fetches a fresh copy of project's metadata.
   */
  load: function () {
    this.setState({loading: true});
    api({
      uri: this.uri()
    }, (err, body) => {
      this.setState({loading: false});
      if (err) {
        // @todo Handle error state (GH-1922)
      }

      this.setState({
        title: body.project.title
      });

      this.refs.title.setState({
        inputLength: body.project.title.length
      });
    });
  },

  /**
   * Persists changes to project settings.
   */
  save: function (onSaveComplete) {

    // @todo Client-side validation
    // console.log(_this.refs.title.validate());

    // Update project settings via the API
    this.setState({loading: true});
    api({
      method: 'PATCH',
      uri: this.uri(),
      json: {
        title: this.state.title
      }
    }, (err, body) => {
      this.setState({loading: false});
      if (err) {
        // @todo Handle error state (GH-1922)
        console.error('Could not update project settings.');
      }
      if (typeof onSaveComplete === 'function') {
        onSaveComplete();
      }
    });
  }
});

render(ProjectSettings);
{'fraction_non_alphanumeric': 0.16644707949055776, 'fraction_numerical': 0.006148440931049627, 'mean_word_length': 2.2983345401882693, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, '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': '671273', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1391, 'n_words': 312}