<commit_before>var App = React.createClass({
  getInitialState: function() {
    return {
      returnedFerries: null,
      returnedRoute: null,
      errorType: '',
    };
  },

  returnedFerries: function(parsedData) {
    if (parsedData.get(transit.keyword('times')).rep.length > 0) {
      this.setState({returnedFerries: parsedData});
    } else {
      this.setState({
        returnedFerries: null,
        returnedRoute: null,
        errorType: 'ferries'
      });
    }
  },

  returnedRoute: function(parsedData) {
    this.setState({returnedRoute: parsedData});
  },

  requestErrored: function() {
    this.setState({
      returnedFerries: null,
      returnedRoute: null,
      errorType: 'routes',
    });
  },

  resetSelections: function() {
    this.setState({
      returnedFerries: null,
      returnedRoute: null,
      errorType: '',
    });
  },

  render: function() {
    if (this.state.returnedRoute) {
      return (
        <div>
          <Header />
          <Intro />
          <FerryPicker
            onFerryReturn={this.returnedFerries}
            onRouteReturn={this.returnedRoute}
            onRequestError={this.requestErrored}
            resetSelections={this.resetSelections}
            errorType={this.state.errorType}
            ferries={this.state.returnedFerries} />
          <Directions
            parsedData={this.state.returnedRoute} />
          <Extra />
          <Footer />
        </div>
      )
    } else {
      return (
        <div>
          <Header />
          <Intro />
          <FerryPicker
            onFerryReturn={this.returnedFerries}
            onRouteReturn={this.returnedRoute}
            onRequestError={this.requestErrored}
            resetSelections={this.resetSelections}
            errorType={this.state.errorType}
            ferries={this.state.returnedFerries} />
          <Footer />
        </div>
      )
    }
  }
});

var Header = React.createClass({
  setupHideShow: function() {
    // https://medium.com/design-startups/hide-header-on-scroll-down-show-on-scroll-up-67bbaae9a78c

    var scrolling = false;
    var lastScrollTop = 0;
    var scrollChange = 5;
    var navbarHeight = $('header').outerHeight();

    function hasScrolled(){
      var st = $(this).scrollTop();

      if(Math.abs(lastScrollTop - st) <= scrollChange) {
        return;
      }

      if (st > lastScrollTop && st > navbarHeight){
        $('header').removeClass('nav-down').addClass('nav-up');
      } else {
        if(st + $(window).height() < $(document).height()) {
          $('header').removeClass('nav-up').addClass('nav-down');
        }
      }

      lastScrollTop = st;
    }

    $(window).scroll(function(){
      scrolling = true;
    });

    setInterval(function(){
      if (scrolling) {
        hasScrolled();
        scrolling = false;
      }
    }, 250);
  },

  render: function() {
    this.setupHideShow();

    return (
      <header>
        <div className="wrapper">
          <a id="home" href="http://sharegurl.com">ShareGurl</a>
          <h1>Getting to Fire Island</h1>
        </div>
      </header>
    )
  }
});

var Intro = React.createClass({
  render: function() {
    return (
      <section id="intro">
        <h2>Welcome to your journey to Fire Island Pines.</h2>
        <p>The trip is famously challenging, but we&rsquo;ll get through it together. Remember the two most important rules:
          <ul>
            <li>If people look gay, you should probably follow them.</li>
            <li>It might seem like everyone knows what they&rsquo;re doing, but everyone had to learn at some point. Don&rsquo;t be afraid to ask.</li>
          </ul>
        </p>
        <p>And if you don&rsquo;t feel like taking the train, Sharegurl&rsquo;s got you covered: this summer, enjoy our new dedicated bus service that will take you directly from Manhattan to the ferry.  <a href="http://new.sharegurl.com/stores/sharegurl-shuttle/about">More info &raquo;</a></p>
      </section>
    )
  }
});

var FerryPicker = React.createClass({
  getInitialState: function() {
    return {waiting: false};
  },

  componentDidMount: function() {
    var resetSelections = this.props.resetSelections;
    var onDateSelect = this.onDateSelect;

    // instantiate bootstrap date picker with callbacks
    $('#departure-date').datepicker({
      'format': 'm/d/yyyy',
    }).on('changeDate', function(e) {
      $('.datepicker').hide();
      resetSelections();
      onDateSelect();
    });

    // suppress month/year-level views
    $('.datepicker .switch').on('click', function(e){
      return false;
    });

    // don't let people type random shit in the date picker, because validation is not worth it
    $('#departure-date').on('keydown', function(e){
      e.preventDefault();
      return false;
    });

    // grab ferry results for today
    onDateSelect();
  },

  onDateSelect: function(e) {
    var data = transit.map([transit.keyword('date'),
               moment($('#departure-date').val(), 'M/D/YYYY').toDate()]);

    $.ajax({'url': '/ferries',
            'type': 'POST',
            'contentType': 'application/transit+json',
            'data': window.transit.writer('json').write(data),
            'headers':
              {'accept': 'application/transit+json'},
            'complete': this.getFerries,
            'error': this.onError});
  },

  getFerries: function(response) {
    var parsedData = window.transit.reader('json').read(response.responseText);
    this.props.onFerryReturn(parsedData);
  },

  onSubmit: function(e) {
    if (this.props.errorType === 'ferries') {
      e.stopPropagation();
    }

    this.setState({waiting: true});
    var dateTimeInputString = $('#departure-date').val() + ' ' + $('#departure-time').val();
    var data = transit.map([transit.keyword('arrive-by'),
               moment(dateTimeInputString, 'M/D/YYYY h:mm a').toDate()]);

    $.ajax({'url': '/directions',
            'type': 'POST',
            'contentType': 'application/transit+json',
            'data': window.transit.writer('json').write(data),
            'headers':
              {'accept': 'application/transit+json'},
            'complete': this.getRoutes,
            'error': this.onError});
  },

  getRoutes: function(response) {
    var parsedData = window.transit.reader('json').read(response.responseText);
    this.setState({waiting: false});
    this.props.onRouteReturn(parsedData);
  },

  onError: function(response) {
    this.setState({waiting: false});
    this.props.onRequestError();
  },

  render: function() {
    var defaultDate = moment().format('M/D/YYYY');
    var ferries = this.props.ferries ? this.props.ferries.get(transit.keyword('times')).rep : [];
    var buttonClassString = this.state.waiting ? 'loading' : '';

    return (
      <section id="departure">
        <h2>Which ferry do you want to catch?</h2>
        <div className="content">
          <div className="input departure-date">
            <input type="text" id="departure-date" className="datetime-input" maxLength="10" defaultValue={defaultDate} />
          </div>
          <FerryTimes ferries={ferries} />
        </div>
        <button onClick={this.onSubmit} id="get-itineraries" className={buttonClassString}><span>Next!</span></button>
        <ErrorMessaging errorType={this.props.errorType} />
      </section>
    )<commit_msg>for real this time<commit_after>var App = React.createClass({
  getInitialState: function() {
    return {
      returnedFerries: null,
      returnedRoute: null,
      errorType: '',
    };
  },

  returnedFerries: function(parsedData) {
    if (parsedData.get(transit.keyword('times')).rep.length > 0) {
      this.setState({returnedFerries: parsedData});
    } else {
      this.setState({
        returnedFerries: null,
        returnedRoute: null,
        errorType: 'ferries'
      });
    }
  },

  returnedRoute: function(parsedData) {
    this.setState({returnedRoute: parsedData});
  },

  requestErrored: function() {
    this.setState({
      returnedFerries: null,
      returnedRoute: null,
      errorType: 'routes',
    });
  },

  resetSelections: function() {
    this.setState({
      returnedFerries: null,
      returnedRoute: null,
      errorType: '',
    });
  },

  render: function() {
    if (this.state.returnedRoute) {
      return (
        <div>
          <Header />
          <Intro />
          <FerryPicker
            onFerryReturn={this.returnedFerries}
            onRouteReturn={this.returnedRoute}
            onRequestError={this.requestErrored}
            resetSelections={this.resetSelections}
            errorType={this.state.errorType}
            ferries={this.state.returnedFerries} />
          <Directions
            parsedData={this.state.returnedRoute} />
          <Extra />
          <Footer />
        </div>
      )
    } else {
      return (
        <div>
          <Header />
          <Intro />
          <FerryPicker
            onFerryReturn={this.returnedFerries}
            onRouteReturn={this.returnedRoute}
            onRequestError={this.requestErrored}
            resetSelections={this.resetSelections}
            errorType={this.state.errorType}
            ferries={this.state.returnedFerries} />
          <Footer />
        </div>
      )
    }
  }
});

var Header = React.createClass({
  setupHideShow: function() {
    // https://medium.com/design-startups/hide-header-on-scroll-down-show-on-scroll-up-67bbaae9a78c

    var scrolling = false;
    var lastScrollTop = 0;
    var scrollChange = 5;
    var navbarHeight = $('header').outerHeight();

    function hasScrolled(){
      var st = $(this).scrollTop();

      if(Math.abs(lastScrollTop - st) <= scrollChange) {
        return;
      }

      if (st > lastScrollTop && st > navbarHeight){
        $('header').removeClass('nav-down').addClass('nav-up');
      } else {
        if(st + $(window).height() < $(document).height()) {
          $('header').removeClass('nav-up').addClass('nav-down');
        }
      }

      lastScrollTop = st;
    }

    $(window).scroll(function(){
      scrolling = true;
    });

    setInterval(function(){
      if (scrolling) {
        hasScrolled();
        scrolling = false;
      }
    }, 250);
  },

  render: function() {
    this.setupHideShow();

    return (
      <header>
        <div className="wrapper">
          <a id="home" href="http://sharegurl.com">ShareGurl</a>
          <h1>Getting to Fire Island</h1>
        </div>
      </header>
    )
  }
});

var Intro = React.createClass({
  render: function() {
    return (
      <section id="intro">
        <h2>Welcome to your journey to Fire Island Pines.</h2>
        <p>The trip is famously challenging, but we&rsquo;ll get through it together. Remember the two most important rules:
          <ul>
            <li>If people look gay, you should probably follow them.</li>
            <li>It might seem like everyone knows what they&rsquo;re doing, but everyone had to learn at some point. Don&rsquo;t be afraid to ask.</li>
          </ul>
        </p>
        <p>And if you don&rsquo;t feel like taking the train, Sharegurl&rsquo;s got you covered: this summer, enjoy our new dedicated bus service that will take you directly from Manhattan to the ferry.  <a href="http://new.sharegurl.com/stores/sharegurl-shuttle/about">More info &raquo;</a></p>
      </section>
    )
  }
});

var FerryPicker = React.createClass({
  getInitialState: function() {
    return {waiting: false};
  },

  componentDidMount: function() {
    var resetSelections = this.props.resetSelections;
    var onDateSelect = this.onDateSelect;

    // instantiate bootstrap date picker with callbacks
    $('#departure-date').datepicker({
      'format': 'm/d/yyyy',
    }).on('changeDate', function(e) {
      $('.datepicker').hide();
      resetSelections();
      onDateSelect();
    });

    // suppress month/year-level views
    $('.datepicker .switch').on('click', function(e){
      return false;
    });

    // don't let people type random shit in the date picker, because validation is not worth it
    $('#departure-date').on('keydown', function(e){
      e.preventDefault();
      return false;
    });

    // grab ferry results for today
    onDateSelect();
  },

  onDateSelect: function(e) {
    var data = transit.map([transit.keyword('date'),
               moment($('#departure-date').val(), 'M/D/YYYY').toDate()]);

    $.ajax({'url': '/ferries',
            'type': 'POST',
            'contentType': 'application/transit+json',
            'data': window.transit.writer('json').write(data),
            'headers':
              {'accept': 'application/transit+json'},
            'complete': this.getFerries,
            'error': this.onError});
  },

  getFerries: function(response) {
    var parsedData = window.transit.reader('json').read(response.responseText);
    this.props.onFerryReturn(parsedData);
  },

  onSubmit: function(e) {
    if (this.props.errorType !== 'ferries') {
      this.setState({waiting: true});
      var dateTimeInputString = $('#departure-date').val() + ' ' + $('#departure-time').val();
      var data = transit.map([transit.keyword('arrive-by'),
                 moment(dateTimeInputString, 'M/D/YYYY h:mm a').toDate()]);

      $.ajax({'url': '/directions',
              'type': 'POST',
              'contentType': 'application/transit+json',
              'data': window.transit.writer('json').write(data),
              'headers':
                {'accept': 'application/transit+json'},
              'complete': this.getRoutes,
              'error': this.onError});
    }
  },

  getRoutes: function(response) {
    var parsedData = window.transit.reader('json').read(response.responseText);
    this.setState({waiting: false});
    this.props.onRouteReturn(parsedData);
  },

  onError: function(response) {
    this.setState({waiting: false});
    this.props.onRequestError();
  },

  render: function() {
    var defaultDate = moment().format('M/D/YYYY');
    var ferries = this.props.ferries ? this.props.ferries.get(transit.keyword('times')).rep : [];
    var buttonClassString = this.state.waiting ? 'loading' : '';

    return (
      <section id="departure">
        <h2>Which ferry do you want to catch?</h2>
        <div className="content">
          <div className="input departure-date">
            <input type="text" id="departure-date" className="datetime-input" maxLength="10" defaultValue={defaultDate} />
          </div>
          <FerryTimes ferries={ferries} />
        </div>
        <button onClick={this.onSubmit} id="get-itineraries" className={buttonClassString}><span>Next!</span></button>
        <ErrorMessaging errorType={this.props.errorType} />
      </section>
    )
{'fraction_non_alphanumeric': 0.1515418502202643, 'fraction_numerical': 0.0025753981701118265, 'mean_word_length': 2.418114431318045, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 115, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855630', 'n_tokens_mistral': 4532, 'n_tokens_neox': 4413, 'n_words': 872}