<commit_before>'use strict';

var React = require('react-native');

var {
  ActivityIndicatorIOS,
  AppRegistry,
  AlertIOS,
  Image,
  ListView,
  StyleSheet,
  Text,
  TouchableHighlight,
  View,
  Navigator,
  PixelRatio,
} = React;

var ActionSheetIOS = require('ActionSheetIOS');

var AppReloader = require('NativeModules').AppReloader;
var Api = require("../Api/Core");
var NoResults = require('../Components/NoResults');
var generateAppURL = require('../Utilities/generateAppURL');

var AppList = React.createClass({
  getInitialState() {
    return {
      page: 1,
      data: [],
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
    };
  },

  componentDidMount() {
    this.fetchApps();
  },

  componentDidUpdate: function(prevProps) {
    if (prevProps.url !== this.props.url) {
      this.setState({ loaded: false });
      this.fetchApps();
    }
  },

  fetchApps() {
    if (!this.requestInFlight) {
      this.setState({
        hasError: false
      });

      this.requestInFlight = true;
      var separator = this.props.url.indexOf('?') !== -1 ?
        '&' :
        '?';
      var url = `${this.props.url}${separator}page=${this.state.page}`;

      Api.get(url)
        .then((data) => {
          if (data.error) {
            // TODO: check for 401 Unauthorized
            if (Navigator.getContext(this)) {
              Navigator.getContext(this).replace({id: "login", error: data.error});
            }

            return;
          }

          var page = data.length ?
            this.state.page + 1:
            this.state.page;

          var newData = this.state.data.concat(data);
          this.setState({
            data: newData,
            page,
            dataSource: this.state.dataSource.cloneWithRows(newData),
            loaded: true,
            hasError: false
          });
        })
        .catch((e) => {
          this.setState({hasError: true});
        })
        .finally(() => {
          this.requestInFlight = false;
        })
        .done();

    }
  },

  renderAppList() {
    return (
      <View style={styles.container}>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={this.renderApp}
          initialPageSize={10}
          pageSize={5}
          onEndReachedThreshold={1200}
          onEndReached={this.fetchApps}
          style={styles.listView} />
      </View>
    );
  },

  renderCreator(app) {
    if (app.creator && !this.props.hideCreator) {
      var avatarUrl = 'https://rnplay.org/' + app.creator.avatar_url + "?v=1";

      return (
        <View style={styles.creator}>
          <Image style={styles.avatar} resizeMode="contain" source={{uri: avatarUrl}} />
          <Text style={styles.username} numberOfLines={1}>{app.creator.username || 'guest'}</Text>
        </View>
      )
    }
  },

  shareApp(app) {
    var url = 'https://rnplay.org/plays/' + app.url_token;
    var message = '"' + (app.name || app.module_name) + '" on rnplay.org';

    ActionSheetIOS.showShareActionSheetWithOptions(
      {url: url, message: message},
      (error) => console.log(error),
      (success) => console.log(success)
    );
  },

  renderApp(app) {
    return (
      <View style={{marginBottom: 15}}>
        <TouchableHighlight underlayColor="#F5F5F5" onLongPress={() => this.shareApp(app)}
                                                    onPress={() => this.selectApp(app)}>
          <View style={styles.appContainer}>
            <View style={styles.appTextDescription}>
              <Text style={styles.appTitle} numberOfLines={1}>{app.name || app.module_name}</Text>
              <View style={styles.targetBuild}>
                <Text style={styles.targetBuildText}>Targets <Text>{app.build_name}</Text></Text>
              </View>

              <View style={styles.viewCount}>
                <Text style={styles.viewCountText}>{app.view_count} <Text>views</Text></Text>
              </View>
            </View>

            { this.renderCreator(app) }
          </View>
        </TouchableHighlight>
      </View>
    );
  },

  selectApp(app) {
    AppReloader.reloadAppWithURLString(generateAppURL(app), app.module_name);
  },

  renderLoading() {
    return (
      <View style={styles.loadingContainer}>
        <ActivityIndicatorIOS color={'#712FA9'} style={styles.spinner} size="large" />
      </View>
    );
  },

  renderNoResults() {
    return(
      <NoResults />
    );
  },

  renderRetry() {
    return (
      <View style={styles.retryButtonWrapper}>
        <Image source={require("image!network_error")} style={{opacity: 0.9, marginBottom: 30}} /><commit_msg>increment hit count when loading an app<commit_after>'use strict';

var React = require('react-native');

var {
  ActivityIndicatorIOS,
  AppRegistry,
  AlertIOS,
  Image,
  ListView,
  StyleSheet,
  Text,
  TouchableHighlight,
  View,
  Navigator,
  PixelRatio,
} = React;

var ActionSheetIOS = require('ActionSheetIOS');

var AppReloader = require('NativeModules').AppReloader;
var Api = require("../Api/Core");
var NoResults = require('../Components/NoResults');
var generateAppURL = require('../Utilities/generateAppURL');

var AppList = React.createClass({
  getInitialState() {
    return {
      page: 1,
      data: [],
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
    };
  },

  componentDidMount() {
    this.fetchApps();
  },

  componentDidUpdate: function(prevProps) {
    if (prevProps.url !== this.props.url) {
      this.setState({ loaded: false });
      this.fetchApps();
    }
  },

  fetchApps() {
    if (!this.requestInFlight) {
      this.setState({
        hasError: false
      });

      this.requestInFlight = true;
      var separator = this.props.url.indexOf('?') !== -1 ?
        '&' :
        '?';
      var url = `${this.props.url}${separator}page=${this.state.page}`;

      Api.get(url)
        .then((data) => {
          if (data.error) {
            // TODO: check for 401 Unauthorized
            if (Navigator.getContext(this)) {
              Navigator.getContext(this).replace({id: "login", error: data.error});
            }

            return;
          }

          var page = data.length ?
            this.state.page + 1:
            this.state.page;

          var newData = this.state.data.concat(data);
          this.setState({
            data: newData,
            page,
            dataSource: this.state.dataSource.cloneWithRows(newData),
            loaded: true,
            hasError: false
          });
        })
        .catch((e) => {
          this.setState({hasError: true});
        })
        .finally(() => {
          this.requestInFlight = false;
        })
        .done();

    }
  },

  renderAppList() {
    return (
      <View style={styles.container}>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={this.renderApp}
          initialPageSize={10}
          pageSize={5}
          onEndReachedThreshold={1200}
          onEndReached={this.fetchApps}
          style={styles.listView} />
      </View>
    );
  },

  renderCreator(app) {
    if (app.creator && !this.props.hideCreator) {
      var avatarUrl = 'https://rnplay.org/' + app.creator.avatar_url + "?v=1";

      return (
        <View style={styles.creator}>
          <Image style={styles.avatar} resizeMode="contain" source={{uri: avatarUrl}} />
          <Text style={styles.username} numberOfLines={1}>{app.creator.username || 'guest'}</Text>
        </View>
      )
    }
  },

  shareApp(app) {
    var url = 'https://rnplay.org/plays/' + app.url_token;
    var message = '"' + (app.name || app.module_name) + '" on rnplay.org';

    ActionSheetIOS.showShareActionSheetWithOptions(
      {url: url, message: message},
      (error) => console.log(error),
      (success) => console.log(success)
    );
  },

  renderApp(app) {
    return (
      <View style={{marginBottom: 15}}>
        <TouchableHighlight underlayColor="#F5F5F5" onLongPress={() => this.shareApp(app)}
                                                    onPress={() => this.selectApp(app)}>
          <View style={styles.appContainer}>
            <View style={styles.appTextDescription}>
              <Text style={styles.appTitle} numberOfLines={1}>{app.name || app.module_name}</Text>
              <View style={styles.targetBuild}>
                <Text style={styles.targetBuildText}>Targets <Text>{app.build_name}</Text></Text>
              </View>

              <View style={styles.viewCount}>
                <Text style={styles.viewCountText}>{app.view_count} <Text>views</Text></Text>
              </View>
            </View>

            { this.renderCreator(app) }
          </View>
        </TouchableHighlight>
      </View>
    );
  },

  selectApp(app) {
    Api.post("/apps/"+app.url_token+"/view.json");
    AppReloader.reloadAppWithURLString(generateAppURL(app), app.module_name);
  },

  renderLoading() {
    return (
      <View style={styles.loadingContainer}>
        <ActivityIndicatorIOS color={'#712FA9'} style={styles.spinner} size="large" />
      </View>
    );
  },

  renderNoResults() {
    return(
      <NoResults />
    );
  },

  renderRetry() {
    return (
      <View style={styles.retryButtonWrapper}>
        <Image source={require("image!network_error")} style={{opacity: 0.9, marginBottom: 30}} />
{'fraction_non_alphanumeric': 0.1555508429646909, 'fraction_numerical': 0.006998197433994274, 'mean_word_length': 2.1524064171122994, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 91, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453949', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2888, 'n_words': 473}