<commit_before>import React, { Component } from 'react';
import Section from 'shared/components/section/section';
import SchoolCard from 'shared/components/schoolCard/schoolCard';
import FormInput from 'shared/components/form/formInput/formInput';
import styles from './stateSortedSchools.css';


const gettingSchoolData = fetch('https://api.operationcode.org/api/v1/code_schools.json')
  .then(response => response.json());

class StateSortedSchools extends Component {
  constructor(props) {
    super(props);
    this.state = {
      query: null,
      schoolsByState: null,
      schools: null
    };

    gettingSchoolData.then(data =>
      this.setState({ schools: data })
    );
  }

  onSearchChange = (value) => {
    if (value.length > 1) {
      // Prevent query with just one character in search field
      this.setState({ query: value });
      this.setState({ schoolsByState: this.searchState(value) });
    } else {
      // Clear results when search field is 1 char or blank
      this.setState({ query: null });
      this.setState({ schoolsByState: null });
    }
  }

  searchState = (string) => {
    const stringFormat = string.replace(/\w\S*/g, txt => txt.toUpperCase());
    const schools = [];
    this.state.schools.forEach((school) => {
      const locations = school.locations.filter(location =>
        location.state === stringFormat
      );
      if (locations.length > 0) {
        const newSchool = Object.assign({}, school);
        newSchool.locations = locations;
        schools.push(newSchool);
      }
    });
    return schools;
  }

  render() {
    const stateSchools = !this.state.schoolsByState ? null : this.state.schoolsByState
      .map(school =>
        (
          <SchoolCard
            key={school.name}
            alt={school.name}
            schoolName={school.name}
            link={school.url}
            schoolAddress={school.locations[0].address1}
            schoolCity={school.locations[0].city}
            schoolState={school.locations[0].state}
            logo={school.logo}
            GI={'Yes'}
            // GI={school.locations[0].va_accepted ? 'Yes' : 'No'}
            fullTime={school.full_time ? 'Full-Time' : 'Flexible'}
            hardware={school.hardware_included ? 'Yes' : 'No'}
          />
        )
      );

    return (
      <Section
        id="schoolsByState"<commit_msg>Push progress for Evan<commit_after>import React, { Component } from 'react';
import Section from 'shared/components/section/section';
import SchoolCard from 'shared/components/schoolCard/schoolCard';
import FormInput from 'shared/components/form/formInput/formInput';
import styles from './stateSortedSchools.css';
import stateCodes from '../stateCodes.json';

const gettingSchoolData = fetch('https://api.operationcode.org/api/v1/code_schools.json')
  .then(response => response.json());

class StateSortedSchools extends Component {
  constructor(props) {
    super(props);
    this.state = {
      query: null,
      schoolsByState: null,
      schools: null
    };

    gettingSchoolData.then(data =>
      this.setState({ schools: data })
    );
  }

  onSearchChange = (value) => {
    if (value.length > 1) {
      // Prevent query with just one character in search field
      this.setState({ query: value });
      this.setState({ schoolsByState: this.searchState(value) });
    } else {
      // Clear results when search field is 1 char or blank
      this.setState({ query: null });
      this.setState({ schoolsByState: null });
    }
  }

  searchState = (string) => {
    const userInput = string.replace(/\w\S*/g, txt => txt.toUpperCase());
    const schools = [];

    // Return true if input matches state code or name (ex: "CA or California")
    function matchesState(school, input) {
      const stateName = stateCodes[school.state].toUpperCase();
      return school.state.includes(input) || stateName.includes(input);
    }

    this.state.schools.forEach((school) => {
      for (location of school.locations.filter(_school => matchesState(_school, userInput))) {
        schools.push({
          name: school.name,
          url: school.url,
          address: school.location.address1,
          city: school.location.city,
          state: school.location.state,
          zip: school.location.zip,
          va_accepted: school.location.va_accepted,
          full_time: school.full_time,
          hardware_included: school.hardware_included
        });
      }
    });

    return schools;
  };

  render() {
    console.log(this.state.schoolsByState);
    const stateSchools = !this.state.schoolsByState ? null : this.state.schoolsByState
      .map(school =>
        (
          <SchoolCard
            key={school.name}
            alt={school.name}
            schoolName={school.name}
            link={school.url}
            schoolAddress={school.address}
            schoolCity={school.city}
            schoolState={school.state}
            logo={school.logo}
            GI={school.va_accepted ? 'Yes' : 'No'}
            fullTime={school.full_time ? 'Full-Time' : 'Flexible'}
            hardware={school.hardware_included ? 'Yes' : 'No'}
          />
        )
      );

    return (
      <Section
        id="schoolsByState"
{'fraction_non_alphanumeric': 0.12987012987012986, 'fraction_numerical': 0.002482811306340718, 'mean_word_length': 2.4890073284477015, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 2, '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': '4556166', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1489, 'n_words': 310}