<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {
  StyleSheet,
  Text,
  RefreshControl,
  View,
  ActivityIndicator,
  Dimensions,
} from 'react-native';
import { ListItem } from 'react-native-elements';

import {
  ViewContainer,
  UserProfile,
  SectionList,
  ParallaxScroll,
  UserListItem,
  EntityInfo,
} from 'components';
import { colors, fonts, normalize } from 'config';
import { getUser, getOrgs, getStarCount } from 'auth';
import { emojifyText, openURLInView, translate } from 'utils';

const mapStateToProps = state => ({
  user: state.auth.user,
  orgs: state.auth.orgs,
  locale: state.auth.locale,
  starCount: state.auth.starCount,
  isPendingUser: state.auth.isPendingUser,
  isPendingOrgs: state.auth.isPendingOrgs,
  hasInitialUser: state.auth.hasInitialUser,
});

const mapDispatchToProps = dispatch =>
  bindActionCreators(
    {
      getUser,
      getOrgs,
      getStarCount,
    },
    dispatch
  );

const styles = StyleSheet.create({
  listTitle: {
    color: colors.black,
    ...fonts.fontPrimary,
  },
  listSubTitle: {
    color: colors.greyDark,
    ...fonts.fontPrimary,
  },
  update: {
    flex: 1,
    alignItems: 'center',
    marginVertical: 40,
  },
  updateText: {
    color: colors.greyDark,
    ...fonts.fontPrimary,
  },
  updateTextSub: {
    fontSize: normalize(11),
  },
  note: {
    fontSize: normalize(11),
    color: colors.primaryDark,
    ...fonts.fontPrimaryLight,
    textAlign: 'center',
    padding: 10,
  },
  noteLink: {
    ...fonts.fontPrimarySemiBold,
  },
});

class AuthProfile extends Component {
  props: {
    getUser: Function,
    getOrgs: Function,
    getStarCount: Function,
    user: Object,
    orgs: Array,
    locale: string,
    starCount: string,
    isPendingUser: boolean,
    isPendingOrgs: boolean,
    hasInitialUser: boolean,
    navigation: Object,
  };

  componentDidMount() {
    this.refreshProfile();
  }

  refreshProfile = () => {
    this.props.getUser();
    this.props.getOrgs();
    this.props.getStarCount();
  };

  render() {
    const {
      user,
      orgs,
      isPendingUser,
      isPendingOrgs,
      locale,
      starCount,
      navigation,
      hasInitialUser,
    } = this.props;

    const isPending = isPendingUser || isPendingOrgs;

    return (
      <ViewContainer>
        <ParallaxScroll
          renderContent={() => (
            <UserProfile
              type="user"
              initialUser={hasInitialUser ? user : {}}
              user={hasInitialUser ? user : {}}
              starCount={hasInitialUser ? starCount : ''}
              locale={locale}
              navigation={navigation}
            />
          )}
          refreshControl={
            <RefreshControl
              refreshing={isPendingUser}
              onRefresh={this.refreshProfile}
            />
          }
          stickyTitle={user.login}
          showMenu
          menuIcon="gear"
          menuAction={() =>
            navigation.navigate('UserOptions', {
              title: translate('auth.userOptions.title', locale),
            })}
        >
          {isPending && (
            <ActivityIndicator
              animating={isPending}
              style={{ height: Dimensions.get('window').height / 3 }}
              size="large"
            />
          )}

          {hasInitialUser &&
            user.bio &&
            user.bio !== '' && (
              <SectionList title={translate('common.bio', locale)}>
                <ListItem
                  subtitle={emojifyText(user.bio)}
                  subtitleStyle={styles.listSubTitle}
                  hideChevron
                />
              </SectionList>
            )}

          {!isPending && (
            <EntityInfo entity={user} orgs={orgs} navigation={navigation} locale={locale} />
          )}

          {!isPending && (
            <View>
              <SectionList
                title={translate('common.orgs', locale)}
                noItems={orgs.length === 0}
                noItemsMessage={translate('common.noOrgsMessage', locale)}
              >
                {orgs.map(item => (
                  <UserListItem
                    key={item.id}
                    user={item}
                    navigation={navigation}
                  />
                ))}
                <Text style={styles.note}>
                  {translate('auth.profile.orgsRequestApprovalTop', locale)}<commit_msg>fix(ux): Add back button for AuthProfileScreen (#507)<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {
  StyleSheet,
  Text,
  RefreshControl,
  View,
  ActivityIndicator,
  Dimensions,
} from 'react-native';
import { ListItem } from 'react-native-elements';

import {
  ViewContainer,
  UserProfile,
  SectionList,
  ParallaxScroll,
  UserListItem,
  EntityInfo,
} from 'components';
import { colors, fonts, normalize } from 'config';
import { getUser, getOrgs, getStarCount } from 'auth';
import { emojifyText, openURLInView, translate } from 'utils';

const mapStateToProps = state => ({
  user: state.auth.user,
  orgs: state.auth.orgs,
  locale: state.auth.locale,
  starCount: state.auth.starCount,
  isPendingUser: state.auth.isPendingUser,
  isPendingOrgs: state.auth.isPendingOrgs,
  hasInitialUser: state.auth.hasInitialUser,
});

const mapDispatchToProps = dispatch =>
  bindActionCreators(
    {
      getUser,
      getOrgs,
      getStarCount,
    },
    dispatch
  );

const styles = StyleSheet.create({
  listTitle: {
    color: colors.black,
    ...fonts.fontPrimary,
  },
  listSubTitle: {
    color: colors.greyDark,
    ...fonts.fontPrimary,
  },
  update: {
    flex: 1,
    alignItems: 'center',
    marginVertical: 40,
  },
  updateText: {
    color: colors.greyDark,
    ...fonts.fontPrimary,
  },
  updateTextSub: {
    fontSize: normalize(11),
  },
  note: {
    fontSize: normalize(11),
    color: colors.primaryDark,
    ...fonts.fontPrimaryLight,
    textAlign: 'center',
    padding: 10,
  },
  noteLink: {
    ...fonts.fontPrimarySemiBold,
  },
});

class AuthProfile extends Component {
  props: {
    getUser: Function,
    getOrgs: Function,
    getStarCount: Function,
    user: Object,
    orgs: Array,
    locale: string,
    starCount: string,
    isPendingUser: boolean,
    isPendingOrgs: boolean,
    hasInitialUser: boolean,
    navigation: Object,
  };

  componentDidMount() {
    this.refreshProfile();
  }

  refreshProfile = () => {
    this.props.getUser();
    this.props.getOrgs();
    this.props.getStarCount();
  };

  render() {
    const {
      user,
      orgs,
      isPendingUser,
      isPendingOrgs,
      locale,
      starCount,
      navigation,
      hasInitialUser,
    } = this.props;

    const hasBackButton = navigation.state.routeName === 'AuthProfile';

    const isPending = isPendingUser || isPendingOrgs;

    return (
      <ViewContainer>
        <ParallaxScroll
          renderContent={() => (
            <UserProfile
              type="user"
              initialUser={hasInitialUser ? user : {}}
              user={hasInitialUser ? user : {}}
              starCount={hasInitialUser ? starCount : ''}
              locale={locale}
              navigation={navigation}
            />
          )}
          refreshControl={
            <RefreshControl
              refreshing={isPendingUser}
              onRefresh={this.refreshProfile}
            />
          }
          stickyTitle={user.login}
          navigateBack={hasBackButton}
          navigation={navigation}
          showMenu
          menuIcon="gear"
          menuAction={() =>
            navigation.navigate('UserOptions', {
              title: translate('auth.userOptions.title', locale),
            })}
        >
          {isPending && (
            <ActivityIndicator
              animating={isPending}
              style={{ height: Dimensions.get('window').height / 3 }}
              size="large"
            />
          )}

          {hasInitialUser &&
            user.bio &&
            user.bio !== '' && (
              <SectionList title={translate('common.bio', locale)}>
                <ListItem
                  subtitle={emojifyText(user.bio)}
                  subtitleStyle={styles.listSubTitle}
                  hideChevron
                />
              </SectionList>
            )}

          {!isPending && (
            <EntityInfo
              entity={user}
              orgs={orgs}
              navigation={navigation}
              locale={locale}
            />
          )}

          {!isPending && (
            <View>
              <SectionList
                title={translate('common.orgs', locale)}
                noItems={orgs.length === 0}
                noItemsMessage={translate('common.noOrgsMessage', locale)}
              >
                {orgs.map(item => (
                  <UserListItem
                    key={item.id}
                    user={item}
                    navigation={navigation}
                  />
                ))}
                <Text style={styles.note}>
                  {translate('auth.profile.orgsRequestApprovalTop', locale)}
{'fraction_non_alphanumeric': 0.12002152852529602, 'fraction_numerical': 0.002691065662002153, 'mean_word_length': 1.8622920517560073, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, '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': '3733899', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2626, 'n_words': 475}