<commit_before>// meters.js
// Flow

import React, { Component } from 'react';
import { StyleSheet, Text, Alert, View, TouchableHighlight, Navigator, AsyncStorage } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import ModalDropdown from 'react-native-modal-dropdown';

export default class Meters extends Component {

  static get propTypes() {
    return {
      pushRoute: React.PropTypes.func.isRequired
    };
  }

  constructor(props) {
    super(props);

    // Initialize state variables
    this.state = {
      meterList: [],
      submitReport: ''
    };

    this.dropdownRenderRow = this.dropdownRenderRow.bind(this);
    this.addMeter = this.addMeter.bind(this);
    this.dropMeter = this.dropMeter.bind(this);
    this.viewMeter = this.viewMeter.bind(this);
  }

  componentDidMount() {
    AsyncStorage.getItem('token', (errors, token) => {
      if (errors) {
        Alert.alert('Error', errors.toString());
      }

      fetch('http://192.168.3.11:3000/api/getMeterIdList', {
        method: 'GET',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/x-www-form-urlencoded',
          'x-access-token': token
        }
      })
      .then((response) => {
        switch (response.status) {
          case 200:
            response.json().then((responseObject) => {
              let {meterIds} = responseObject;

              if (!Array.isArray(meterIds)) {
                this.setState({
                  submitReport: 'Failed to retrieve meter ID list - server returned invalid response!',
                  meterList: []
                });
                return;
              }

              let meterList = [];
              for (let i = 0; i < meterIds.length; i++) {
                meterList[i] = meterIds[i].meterId;
              }

              this.setState({submitReport: '', meterList});
            });
            break;
          default:
            response.json().then((responseObject) => {
              this.setState({
                submitReport: `${response.status}: ${responseObject.message}`,
                meterList: []
              });
            });
        }
      });
    });
  }

  render() {
    return (
      <KeyboardAwareScrollView style={styles.container}>
        <Text style={styles.title}>Meters</Text>
        <ModalDropdown style={styles.dropdown}<commit_msg>Add catch for server response 204 to Meters scene<commit_after>// meters.js
// Flow

import React, { Component } from 'react';
import { StyleSheet, Text, Alert, View, TouchableHighlight, Navigator, AsyncStorage } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import ModalDropdown from 'react-native-modal-dropdown';

export default class Meters extends Component {

  static get propTypes() {
    return {
      pushRoute: React.PropTypes.func.isRequired
    };
  }

  constructor(props) {
    super(props);

    // Initialize state variables
    this.state = {
      meterList: [],
      submitReport: ''
    };

    this.dropdownRenderRow = this.dropdownRenderRow.bind(this);
    this.addMeter = this.addMeter.bind(this);
    this.dropMeter = this.dropMeter.bind(this);
    this.viewMeter = this.viewMeter.bind(this);
  }

  componentDidMount() {
    AsyncStorage.getItem('token', (errors, token) => {
      if (errors) {
        Alert.alert('Error', errors.toString());
      }

      fetch('http://192.168.3.11:3000/api/getMeterIdList', {
        method: 'GET',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/x-www-form-urlencoded',
          'x-access-token': token
        }
      })
      .then((response) => {
        switch (response.status) {
          case 200:
            response.json().then((responseObject) => {
              let {meterIds} = responseObject;

              if (!Array.isArray(meterIds)) {
                this.setState({
                  submitReport: 'Failed to retrieve meter ID list - server returned invalid response!',
                  meterList: []
                });
                return;
              }

              let meterList = [];
              for (let i = 0; i < meterIds.length; i++) {
                meterList[i] = meterIds[i].meterId;
              }

              this.setState({submitReport: '', meterList});
            });
            break;
          case 204:
            this.setState({
              submitReport: 'No meters found for this user!',
              meterList: []
            });
            break;
          default:
            response.json().then((responseObject) => {
              this.setState({
                submitReport: `${response.status}: ${responseObject.message}`,
                meterList: []
              });
            });
        }
      });
    });
  }

  render() {
    return (
      <KeyboardAwareScrollView style={styles.container}>
        <Text style={styles.title}>Meters</Text>
        <ModalDropdown style={styles.dropdown}
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.007866273352999017, 'mean_word_length': 1.8996579247434435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '1628596', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1381, 'n_words': 271}