<commit_before>import _ from 'lodash';
import data from 'everest-data';
import React, { Component, PropTypes } from 'react';

import './App.css';

import history from './history';

import BarChartByYear from './BarChartByYear';
import DataContainer from './DataContainer';
import SVGContainer from './SVGContainer';
import Overview from './Overview';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      highlightIndex: null,
      started: false,
      storyIndex: 0,
    };
    this.timer = null;
    this.handleNext = this.handleNext.bind(this);
    this.handleStart = this.handleStart.bind(this);
  }

  static defaultProps = {
    data: _.sortBy(data, (d) => { return d.Date; }),
    stories: [{
      component: Overview,
      container: null,
      path: '/intro',
    }, {
      component: BarChartByYear,
      container: SVGContainer,
      path: '/by-year',
      highlights: [{
        id: 'year2015',
        text: '',
      }, {
        id: 'year1996',
        text: '',
      }],
    }],
  }

  static propTypes = {
    data: PropTypes.array.isRequired,
    stories: PropTypes.array.isRequired,
  }

  findHighlightIndex(location, highlights) {
    return _.findIndex(highlights, (highlight) => {
      return highlight.id === _.get(location, ['query', 'highlight']);
    });
  }

  findStoryIndex(location) {
    return _.findIndex(this.props.stories, (story) => {
      return story.path === location.pathname;
    });
  }

  componentWillMount() {
    const { stories } = this.props;
    const currentLocation = history.getCurrentLocation();
    const currentStoryIndex = this.findStoryIndex(currentLocation);
    if (currentStoryIndex >= 0) {
      this.setState({
        storyIndex: currentStoryIndex,
        started: true,
      });
      if (!_.isEmpty(currentLocation.query)) {
        const highlights = stories[currentStoryIndex].highlights || [];
        const currentHighlightIndex = this.findHighlightIndex(currentLocation, highlights);
        if (currentHighlightIndex >= 0) {
          this.setState({
            highlightIndex: currentHighlightIndex,
          });
        }
      } else {
        if (stories[currentStoryIndex].highlights) {
          this.startHighlights(stories[currentStoryIndex]);
        }
      }
    }

    this.unlisten = history.listen((location) => {
      console.log(location.query);
      const currentStory = this.findStoryIndex(location);
      const highlights = stories[currentStory].highlights;
      if (highlights) {
        const highlightIndex = this.findHighlightIndex(location, highlights);
        this.setState({
          highlightIndex: (highlightIndex >= 0) ? highlightIndex : null,
        });
      } else {
        this.setState({
          highlightIndex: null,
        });
      }
      this.setState({
        storyIndex: currentStory,
      });<commit_msg>sync URL and landing page<commit_after>import _ from 'lodash';
import data from 'everest-data';
import React, { Component, PropTypes } from 'react';

import './App.css';

import history from './history';

import BarChartByYear from './BarChartByYear';
import DataContainer from './DataContainer';
import SVGContainer from './SVGContainer';
import Overview from './Overview';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      highlightIndex: null,
      started: false,
      storyIndex: 0,
    };
    this.timer = null;
    this.handleNext = this.handleNext.bind(this);
    this.handleStart = this.handleStart.bind(this);
  }

  static defaultProps = {
    data: _.sortBy(data, (d) => { return d.Date; }),
    stories: [{
      component: Overview,
      container: null,
      path: '/intro',
    }, {
      component: BarChartByYear,
      container: SVGContainer,
      path: '/by-year',
      highlights: [{
        id: 'year2015',
        text: '',
      }, {
        id: 'year1996',
        text: '',
      }],
    }],
  }

  static propTypes = {
    data: PropTypes.array.isRequired,
    stories: PropTypes.array.isRequired,
  }

  findHighlightIndex(location, highlights) {
    return _.findIndex(highlights, (highlight) => {
      return highlight.id === _.get(location, ['query', 'highlight']);
    });
  }

  findStoryIndex(location) {
    return _.findIndex(this.props.stories, (story) => {
      return story.path === location.pathname;
    });
  }

  componentWillMount() {
    const { stories } = this.props;
    const currentLocation = history.getCurrentLocation();
    const currentStoryIndex = this.findStoryIndex(currentLocation);
    if (currentStoryIndex >= 0) {
      this.setState({
        storyIndex: currentStoryIndex,
        started: true,
      });
      if (!_.isEmpty(currentLocation.query)) {
        const highlights = stories[currentStoryIndex].highlights || [];
        const currentHighlightIndex = this.findHighlightIndex(currentLocation, highlights);
        if (currentHighlightIndex >= 0) {
          this.setState({
            highlightIndex: currentHighlightIndex,
          });
        }
      } else {
        if (stories[currentStoryIndex].highlights) {
          this.startHighlights(stories[currentStoryIndex]);
        }
      }
    }

    this.unlisten = history.listen((location) => {
      if (location.pathname === '/') {
        return this.setState({
          highlightIndex: null,
          storyIndex: 0,
          started: false,
        });
      }
      const currentStory = this.findStoryIndex(location);
      const highlights = stories[currentStory].highlights;
      if (highlights) {
        const highlightIndex = this.findHighlightIndex(location, highlights);
        this.setState({
          highlightIndex: (highlightIndex >= 0) ? highlightIndex : null,
        });
      } else {
        this.setState({
          highlightIndex: null,
        });
      }
      this.setState({
        storyIndex: currentStory,
        started: true,
      });
{'fraction_non_alphanumeric': 0.12867461783974465, 'fraction_numerical': 0.004199563245422476, 'mean_word_length': 2.544047619047619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '590443', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1650, 'n_words': 353}