<commit_before>/*
 * Displays a campus' location on a map, relative to a user's location, as well as a list of the stops
 * near the campus.
 */
'use strict';

// Imports
const React = require('react-native');
const {
  Component,
  Image,
  StyleSheet,
  TouchableOpacity,
  View,
} = React;

const Configuration = require('../../util/Configuration');
const Constants = require('../../Constants');
const LanguageUtils = require('../../util/LanguageUtils');
const MapView = require('react-native-maps');
const Preferences = require('../../util/Preferences');
const SectionHeader = require('../../components/SectionHeader');

class CampusStops extends Component {

  /*
   * Properties which the parent component should make available to this component.
   */
  static propTypes = {
    campusName: React.PropTypes.string.isRequired,
  };

  /*
   * Pass props and declares initial state.
   */
  constructor(props) {
    super(props);

    this.state = {
      campus: null,
    }

    // Explicitly binding 'this' to all methods that need it
    this._getCampusMap = this._getCampusMap.bind(this);
    this._loadCampusInfo = this._loadCampusInfo.bind(this);
  };

  _getCampusMap() {
    let lat = 0;
    let long = 0;
    let markers = []

    if (this.state.campus == null) {
      let university = Configuration.getUniversity();
      lat = university['lat'];
      long = university['long'];
    } else {
      // TODO: replace with campus location
      let university = Configuration.getUniversity();
      lat = university['lat'];
      long = university['long'];

      for (let stop in this.state.campus) {
        markers.push({
          'title': this.state.campus[stop].name,
          'desc': this.state.campus[stop].code,
          'id': stop,
          'latlng': {
            'latitude': this.state.campus[stop].lat,
            'longitude': this.state.campus[stop].long,
          },
        });
      }
    }

    return (
      <MapView
          style={_styles.map}
          initialRegion={{
            latitude: lat,
            longitude: long,
            latitudeDelta: 0.04,
            longitudeDelta: 0.04,
          }}>
        {markers.map((marker) => (
          <MapView.Marker
            key={marker.id}
            coordinate={marker.latlng}
            title={marker.title}
            description={marker.desc}
          />
        ))}
      </MapView>
    );
  };

  /*
   * Retrieves data about the stop provided as this.props.campusName.
   */
  _loadCampusInfo() {
    let campuses = require('../../../assets/static/json/transit_stops.json');
    if (this.props.campusName in campuses) {
      this.setState({
        campus: campuses[this.props.campusName],
      });
    }
  };

  componentDidMount() {
    if (this.state.campus == null) {
      this._loadCampusInfo();
    }
  }

  render() {
    // Get current language for translations
    let Translations = null;
    if (Preferences.getSelectedLanguage() === 'fr') {
      Translations = require('../../../assets/static/js/Translations.fr.js');
    } else {
      Translations = require('../../../assets/static/js/Translations.en.js');
    }

    return (
      <View style={_styles.container}>
        <View style={_styles.container}>
          {this._getCampusMap()}
        </View>
        <View style={_styles.container} />
      </View>
    );
  };<commit_msg>Map shows location of campus on load<commit_after>/*
 * Displays a campus' location on a map, relative to a user's location, as well as a list of the stops
 * near the campus.
 */
'use strict';

// Imports
const React = require('react-native');
const {
  Component,
  Image,
  StyleSheet,
  TouchableOpacity,
  View,
} = React;

const Configuration = require('../../util/Configuration');
const Constants = require('../../Constants');
const LanguageUtils = require('../../util/LanguageUtils');
const MapView = require('react-native-maps');
const Preferences = require('../../util/Preferences');
const SectionHeader = require('../../components/SectionHeader');

class CampusStops extends Component {

  /*
   * Properties which the parent component should make available to this component.
   */
  static propTypes = {
    campusName: React.PropTypes.string.isRequired,
  };

  /*
   * Pass props and declares initial state.
   */
  constructor(props) {
    super(props);

    this.state = {
      campus: null,
    }

    // Explicitly binding 'this' to all methods that need it
    this._getCampusMap = this._getCampusMap.bind(this);
    this._loadCampusInfo = this._loadCampusInfo.bind(this);
  };

  _getCampusMap() {
    let lat = 0;
    let long = 0;
    let markers = []

    if (this.state.campus == null) {
      let university = Configuration.getUniversity();
      lat = university['lat'];
      long = university['long'];
    } else {
      lat = this.state.campus['lat'];
      long = this.state.campus['long'];

      for (let stop in this.state.campus['stops']) {
        markers.push({
          'title': this.state.campus['stops'][stop].name,
          'desc': this.state.campus['stops'][stop].code,
          'id': stop,
          'latlng': {
            'latitude': this.state.campus['stops'][stop].lat,
            'longitude': this.state.campus['stops'][stop].long,
          },
        });
      }
    }

    return (
      <MapView
          style={_styles.map}
          initialRegion={{
            latitude: lat,
            longitude: long,
            latitudeDelta: 0.04,
            longitudeDelta: 0.04,
          }}>
        {markers.map((marker) => (
          <MapView.Marker
            key={marker.id}
            coordinate={marker.latlng}
            title={marker.title}
            description={marker.desc}
          />
        ))}
      </MapView>
    );
  };

  _getCampusStops() {
    if (this.state.campus == null) {
      return (
        <View style={_styles.container} />
      );
    }

    return (
      <View style={_styles.container}>
        <SectionHeader
            sectionName={LanguageUtils.getTranslatedName(Preferences.getSelectedLanguage(), this.state.campus)}
            sectionIcon={'directions-bus'}
            sectionIconClass={'material'} />
      </View>
    );
  };

  /*
   * Retrieves data about the stop provided as this.props.campusName.
   */
  _loadCampusInfo() {
    let campuses = require('../../../assets/static/json/transit_stops.json');
    if (this.props.campusName in campuses) {
      this.setState({
        campus: campuses[this.props.campusName],
      });
    }
  };

  componentDidMount() {
    if (this.state.campus == null) {
      this._loadCampusInfo();
    }
  }

  render() {
    // Get current language for translations
    let Translations = null;
    if (Preferences.getSelectedLanguage() === 'fr') {
      Translations = require('../../../assets/static/js/Translations.fr.js');
    } else {
      Translations = require('../../../assets/static/js/Translations.en.js');
    }

    return (
      <View style={_styles.container}>
        <View style={_styles.container}>
          {this._getCampusMap()}
        </View>
        {this._getCampusStops()}
      </View>
    );
  };
{'fraction_non_alphanumeric': 0.15002101134612691, 'fraction_numerical': 0.0022412102535369098, 'mean_word_length': 2.2046678635547576, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 24, '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': '4990337', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2110, 'n_words': 447}