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

import APINotLoaded from 'es6!display/not_loaded';
import ChangesLinks from 'es6!display/changes/links';
import ChangesUI from 'es6!display/changes/ui';
import SectionHeader from 'es6!display/section_header';
import { ChangesPage, APINotLoadedPage } from 'es6!display/page_chrome';
import { Grid } from 'es6!display/grid';
import { ManyBuildsStatus } from 'es6!display/changes/builds';
import { TimeText } from 'es6!display/time';
import { get_runnable_condition, get_runnable_condition_color_cls } from 'es6!display/changes/build_conditions';

import * as api from 'es6!server/api';

import * as utils from 'es6!utils/utils';
import custom_content_hook from 'es6!utils/custom_content';

var HomePage = React.createClass({

  getInitialTitle: function() {
    if (!this.props.author) {
      return 'My Changes';
    }
    // if this is being used as an author page, we'll set the title later
  },

  getInitialState: function() {
    return {
      commits: null,
      diffs: null
    }
  },

  componentDidMount: function() {
    var author = this.props.author || 'me';

    api.fetch(this, {
      diffs: `/api/0/authors/${author}/diffs/`,
      commits: `/api/0/authors/${author}/commits/?per_page=20`,
      projects: '/api/0/projects/' // no fetch_extra
    });
  },


  render: function() {
    // NOTE: so right now, this page still basically works even when
    // phabricator is down. Keep it that way.

    // I want to display just a single loading indicator until we have content
    // to show
    if (!api.isLoaded(this.state.commits)) {
      // special rendering for not logged in
      if (api.isError(this.state.commits) &&
          this.state.commits.getStatusCode() === '401') {
        return this.renderNotLoggedIn();
      }

      return <APINotLoadedPage
        highlight="My Changes"
        calls={this.state.commits}
        oldUI="/projects/"
      />;
    }

    // hack to use homepage as user page
    // TODO: not this
    var header_markup = null;
    if (this.props.author) {
      var author_info = this.state.commits.getReturnedData()[0].builds[0].author;
      header_markup = <div style={{paddingBottom: 30, paddingTop: 10}}>
        Diffs and Commits by {utils.email_head(this.props.author)} ({author_info.name})
      </div>;
      utils.setPageTitle(`${utils.email_head(this.props.author)} - Changes`);
    }

    var projects = null;
    if (!this.props.author) {
      projects = <div className="marginTopL">
        <Projects projects={this.state.projects} />
      </div>;
    }

    return <ChangesPage highlight="My Changes" oldUI="/projects/">
      {header_markup}
      <div>
        <Diffs
          diffs={this.state.diffs}
          author={this.props.author}
        />
        <Commits
          commits={this.state.commits}
          author={this.props.author}
        />
      </div>
      {projects}
    </ChangesPage>;
  },

  renderNotLoggedIn: function() {
    var current_location = encodeURIComponent(window.location.href);
    var login_href = '/auth/login/?orig_url=' + current_location;

    var login_markup = [
      <a href={login_href}>
        Log in
      </a>,
      " to see your recent diffs and commits."
    ];

    var custom_login_image = custom_content_hook('customLoginImage');
    if (custom_login_image) {
      var image_href = '/v2/custom_image/' + custom_login_image;
      login_markup = <center style={{ marginTop: 24, display: "block" }}>
        <img
          className="block"
          src={image_href}
          style={{ width: "30%" }}
        />
        <div style={{fontSize: 18}}>{login_markup}</div>
      </center>;
    }

    return <ChangesPage highlight="My Changes" oldUI="/projects/">
      <div className="marginBottomL">
        {login_markup}
      </div>
      <Projects projects={this.state.projects} />
    </ChangesPage>;
  }
});

// Render list of the user's diffs currently in review / uncommitted
var Diffs = React.createClass({

  propTypes: {
    // diffs authored by the user (and associated builds)
    diffs: PropTypes.array,

    // author = null if viewing home page, otherwise the author
    author: PropTypes.string,
  },

  getInitialState: function() {
    return {};
  },

  render: function() {
    if (!api.isLoaded(this.props.diffs)) {
      return <APINotLoaded calls={this.props.diffs} />;
    }

    var diffs = this.props.diffs.getReturnedData();
<commit_msg>minor login tweak<commit_after>import React, { PropTypes } from 'react';

import APINotLoaded from 'es6!display/not_loaded';
import ChangesLinks from 'es6!display/changes/links';
import ChangesUI from 'es6!display/changes/ui';
import SectionHeader from 'es6!display/section_header';
import { ChangesPage, APINotLoadedPage } from 'es6!display/page_chrome';
import { Grid } from 'es6!display/grid';
import { ManyBuildsStatus } from 'es6!display/changes/builds';
import { TimeText } from 'es6!display/time';
import { get_runnable_condition, get_runnable_condition_color_cls } from 'es6!display/changes/build_conditions';

import * as api from 'es6!server/api';

import * as utils from 'es6!utils/utils';
import custom_content_hook from 'es6!utils/custom_content';

var HomePage = React.createClass({

  getInitialTitle: function() {
    if (!this.props.author) {
      return 'My Changes';
    }
    // if this is being used as an author page, we'll set the title later
  },

  getInitialState: function() {
    return {
      commits: null,
      diffs: null
    }
  },

  componentDidMount: function() {
    var author = this.props.author || 'me';

    api.fetch(this, {
      diffs: `/api/0/authors/${author}/diffs/`,
      commits: `/api/0/authors/${author}/commits/?per_page=20`,
      projects: '/api/0/projects/' // no fetch_extra
    });
  },


  render: function() {
    // NOTE: so right now, this page still basically works even when
    // phabricator is down. Keep it that way.

    // I want to display just a single loading indicator until we have content
    // to show
    if (!api.isLoaded(this.state.commits)) {
      // special rendering for not logged in. this shouldn't be possible
      // (unless you're hitting prod apis from a local box)
      if (api.isError(this.state.commits) &&
          this.state.commits.getStatusCode() === '401') {
        return this.renderNotLoggedIn();
      }

      return <APINotLoadedPage
        highlight="My Changes"
        calls={this.state.commits}
        oldUI="/projects/"
      />;
    }

    // hack to use homepage as user page
    // TODO: not this
    var header_markup = null;
    if (this.props.author) {
      var author_info = this.state.commits.getReturnedData()[0].builds[0].author;
      header_markup = <div style={{paddingBottom: 30, paddingTop: 10}}>
        Diffs and Commits by {utils.email_head(this.props.author)} ({author_info.name})
      </div>;
      utils.setPageTitle(`${utils.email_head(this.props.author)} - Changes`);
    }

    var projects = null;
    if (!this.props.author) {
      projects = <div className="marginTopL">
        <Projects projects={this.state.projects} />
      </div>;
    }

    return <ChangesPage highlight="My Changes" oldUI="/projects/">
      {header_markup}
      <div>
        <Diffs
          diffs={this.state.diffs}
          author={this.props.author}
        />
        <Commits
          commits={this.state.commits}
          author={this.props.author}
        />
      </div>
      {projects}
    </ChangesPage>;
  },

  renderNotLoggedIn: function() {
    var current_location = encodeURIComponent(window.location.href);
    var login_href = '/auth/login/?orig_url=' + current_location;

    return <ChangesPage highlight="My Changes" oldUI="/projects/">
      <div className="marginBottomL">
        <a href={login_href}>
          Log in
        </a>,
        to see your recent diffs and commits.
        {login_markup}
      </div>
      <Projects projects={this.state.projects} />
    </ChangesPage>;
  }
});

// Render list of the user's diffs currently in review / uncommitted
var Diffs = React.createClass({

  propTypes: {
    // diffs authored by the user (and associated builds)
    diffs: PropTypes.array,

    // author = null if viewing home page, otherwise the author
    author: PropTypes.string,
  },

  getInitialState: function() {
    return {};
  },

  render: function() {
    if (!api.isLoaded(this.props.diffs)) {
      return <APINotLoaded calls={this.props.diffs} />;
    }

    var diffs = this.props.diffs.getReturnedData();

{'fraction_non_alphanumeric': 0.13263872629360807, 'fraction_numerical': 0.006907047529852494, 'mean_word_length': 2.8019581664441477, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, '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': '6057702', 'n_tokens_mistral': 2690, 'n_tokens_neox': 2629, 'n_words': 641}