<commit_before>import React from 'react';
import {
  ScrollView,
  StyleSheet,
  Text,
  TextInput,
  View,
} from 'react-native';
import {
  Components,
} from 'exponent';
import {
  connect,
} from 'react-redux';

import Alerts from '../constants/Alerts';
import AuthTokenActions from '../../Flux/AuthTokenActions';
import Colors from '../constants/Colors';
import Form from '../components/Form';
import PrimaryButton from '../components/PrimaryButton';
import Auth0Api from '../../Api/Auth0Api';

const DEBUG = false;

@connect(data => SignInScreen.getDataProps(data))
export default class SignInScreen extends React.Component {
  static route = {
    navigationBar: {
      title: 'Sign In',
    },
  }

  static getDataProps(data) {
    return {
      authTokens: data.authTokens,
    };
  }

  state = DEBUG ? {
    email: '<EMAIL>',
    password: '<PASSWORD>',
    isLoading: false,
  } : {
    email: '',
    password: '',
    isLoading: false,
  }

  componentDidMount() {
    this._isMounted = true;
  }

  componentWillUnmount() {
    this._isMounted = false;
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.authTokens.idToken && !this.props.authTokens.isToken) {
      TextInput.State.blurTextInput(TextInput.State.currentlyFocusedField());
      this.props.navigation.dismissModal();
    }
  }

  render() {
    return (
      <ScrollView
        style={styles.container}
        contentContainerStyle={{paddingTop: 15}}
        keyboardShouldPersistTaps="always"
        keyboardDismissMode="on-drag">
        <Form>
          <Form.Input
            autoCapitalize="none"
            autoCorrect={false}
            autofocus
            blurOnSubmit={false}
            keyboardType="email-address"
            label="E-mail address"
            onChangeText={this._handleChangeEmail}
            returnKeyType="next"
            value={this.state.email}
          />
          <Form.Input
            hideBottomBorder
            label="Password"
            onChangeText={this._handleChangePassword}
            returnKeyType="done"
            secureTextEntry
            value={this.state.password}
          />
        </Form>

        <PrimaryButton
          isLoading={this.state.isLoading}
          style={{margin: 20}}
          onPress={this._handleSubmit}>
          Sign In
        </PrimaryButton>
      </ScrollView>
    );
  }

  _handleChangeEmail = (email) => {
    this.setState({email});
  }

  _handleChangePassword = (password) => {
    this.setState({password});
  }

  _handleSubmit = async () => {
    let { email, password, isLoading } = this.state;

    if (isLoading) {
      return;
    }

    this.setState({ isLoading: true });

    try {
      let result = await Auth0Api.signInAsync(email, password);
      if (this._isMounted) {
        if (result.error) {
          this._handleError(result);
        } else {
          this.props.navigator.hideLocalAlert();
          this.props.dispatch(AuthTokenActions.setAuthTokens({
            refreshToken: result.refresh_token,
            accessToken: result.access_token,
            idToken: result.id_token,<commit_msg>Change sign in field text to include username<commit_after>import React from 'react';
import {
  ScrollView,
  StyleSheet,
  Text,
  TextInput,
  View,
} from 'react-native';
import {
  Components,
} from 'exponent';
import {
  connect,
} from 'react-redux';

import Alerts from '../constants/Alerts';
import AuthTokenActions from '../../Flux/AuthTokenActions';
import Colors from '../constants/Colors';
import Form from '../components/Form';
import PrimaryButton from '../components/PrimaryButton';
import Auth0Api from '../../Api/Auth0Api';

const DEBUG = false;

@connect(data => SignInScreen.getDataProps(data))
export default class SignInScreen extends React.Component {
  static route = {
    navigationBar: {
      title: 'Sign In',
    },
  }

  static getDataProps(data) {
    return {
      authTokens: data.authTokens,
    };
  }

  state = DEBUG ? {
    email: '<EMAIL>',
    password: '<PASSWORD>',
    isLoading: false,
  } : {
    email: '',
    password: '',
    isLoading: false,
  }

  componentDidMount() {
    this._isMounted = true;
  }

  componentWillUnmount() {
    this._isMounted = false;
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.authTokens.idToken && !this.props.authTokens.isToken) {
      TextInput.State.blurTextInput(TextInput.State.currentlyFocusedField());
      this.props.navigation.dismissModal();
    }
  }

  render() {
    return (
      <ScrollView
        style={styles.container}
        contentContainerStyle={{paddingTop: 15}}
        keyboardShouldPersistTaps="always"
        keyboardDismissMode="on-drag">
        <Form>
          <Form.Input
            autoCapitalize="none"
            autoCorrect={false}
            autofocus
            blurOnSubmit={false}
            keyboardType="email-address"
            label="E-mail or username"
            onChangeText={this._handleChangeEmail}
            returnKeyType="next"
            value={this.state.email}
          />
          <Form.Input
            hideBottomBorder
            label="Password"
            onChangeText={this._handleChangePassword}
            returnKeyType="done"
            secureTextEntry
            value={this.state.password}
          />
        </Form>

        <PrimaryButton
          isLoading={this.state.isLoading}
          style={{margin: 20}}
          onPress={this._handleSubmit}>
          Sign In
        </PrimaryButton>
      </ScrollView>
    );
  }

  _handleChangeEmail = (email) => {
    this.setState({email});
  }

  _handleChangePassword = (password) => {
    this.setState({password});
  }

  _handleSubmit = async () => {
    let { email, password, isLoading } = this.state;

    if (isLoading) {
      return;
    }

    this.setState({ isLoading: true });

    try {
      let result = await Auth0Api.signInAsync(email, password);

      if (this._isMounted) {
        if (result.error) {
          this._handleError(result);
        } else {
          this.props.navigator.hideLocalAlert();
          this.props.dispatch(AuthTokenActions.setAuthTokens({
            refreshToken: result.refresh_token,
            accessToken: result.access_token,
            idToken: result.id_token,
{'fraction_non_alphanumeric': 0.12248135808345233, 'fraction_numerical': 0.0022211645248294463, 'mean_word_length': 2.331923890063425, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '497901', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1824, 'n_words': 339}