<commit_before>import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import { Redirect } from 'react-router';
import { Helmet } from "react-helmet";
import AppNavigation from './components/mock/AppNavigation';
import MotionDetails from './components/mock/MotionDetails';
import MotionList from './components/mock/MotionList';
import PartyList from './components/mock/PartyList';
import FrontPage from './components/mock/FrontPage';
import PartyMap from './parties';
import analyzer from './lib/analysis';
import _ from 'lodash';
import { populatePartyLogos } from './utils';

const cases = require('../importer/cases.json');

class App extends Component {
  componentWillMount() {
    let partyMap = new PartyMap();
    partyMap.fetch().then((response) => {
      this.partyMap = partyMap;
      this.setState((prevState, props) => {
        return Object.assign({}, prevState, {initialised: true});
      });
    });
  }

  getNextCase(userVotes) {
    const nextCases = _.filter(this.cases, (_case) => {
      return userVotes[_case.issue_id] === undefined;
    });
    const nextCaseObject = nextCases[0];
    return {nextCase: (nextCaseObject ? nextCaseObject.issue_id : undefined), remainingVotes: nextCases.length};
  }

  constructor() {
    super();
    this.voteData = analyzer.get_hack_data();
    this.partyMap = null;
    this.cases = cases;
    this.redirectHandled = true;
    this.state = {
      initialised: false,
      userVotes: {},
      nextCase: this.getNextCase({}).nextCase,
      remainingVotes: this.cases.length,
      partyAgreements: {},
      votesUpdated: null
    };
  }

  castVote(issueId, value) {
    let analyzerVoteId = issueId + '/kamu';
    analyzer.set_user_vote(this.voteData, analyzerVoteId, value);
    let partyAgreements = analyzer.get_user_party_vote_agreements(this.voteData, analyzerVoteId);
    populatePartyLogos(partyAgreements, this.partyMap);
    partyAgreements = _.filter(
      partyAgreements,
      (a) => { return a.party !== "undefined" && a.partyLogo; });

    this.setState(
      (prevState) => {
        partyAgreements = Object.assign({}, prevState.partyAgreements, {[issueId]: partyAgreements});
        const userVotes = Object.assign(prevState.userVotes, {[issueId]: value});
        this.redirectHandled = false;
        const {nextCase, remainingVotes} = this.getNextCase(userVotes);
        const result = Object.assign(
          {}, prevState,
          {userVotes, nextCase, remainingVotes, partyAgreements, votesUpdated: Date.now()});
        return result;
      }
    );
  }

  emptyVotes() {
    this.setState(
      (prevState) => {
        return Object.assign({}, prevState, {userVotes: {}});
      }
    );
  }

  render() {
    if (!this.state.initialised) {
      return <div>LOADING...</div>;
    }
    if (this.state.remainingVotes === 0 && !this.redirectHandled) {
      this.redirectHandled = true;
      return <Redirect to="/party"/>;
    }
    return (
      <div className="App sans-serif">
        <Helmet>
            <meta charSet="utf-8" /><commit_msg>Ensure front page vote link works after clearing.<commit_after>import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import { Redirect } from 'react-router';
import { Helmet } from "react-helmet";
import AppNavigation from './components/mock/AppNavigation';
import MotionDetails from './components/mock/MotionDetails';
import MotionList from './components/mock/MotionList';
import PartyList from './components/mock/PartyList';
import FrontPage from './components/mock/FrontPage';
import PartyMap from './parties';
import analyzer from './lib/analysis';
import _ from 'lodash';
import { populatePartyLogos } from './utils';

const cases = require('../importer/cases.json');

class App extends Component {
  componentWillMount() {
    let partyMap = new PartyMap();
    partyMap.fetch().then((response) => {
      this.partyMap = partyMap;
      this.setState((prevState, props) => {
        return Object.assign({}, prevState, {initialised: true});
      });
    });
  }

  getNextCase(userVotes) {
    const nextCases = _.filter(this.cases, (_case) => {
      return userVotes[_case.issue_id] === undefined;
    });
    const nextCaseObject = nextCases[0];
    return {nextCase: (nextCaseObject ? nextCaseObject.issue_id : undefined), remainingVotes: nextCases.length};
  }

  constructor() {
    super();
    this.voteData = analyzer.get_hack_data();
    this.partyMap = null;
    this.cases = cases;
    this.redirectHandled = true;
    this.state = {
      initialised: false,
      userVotes: {},
      nextCase: this.getNextCase({}).nextCase,
      remainingVotes: this.cases.length,
      partyAgreements: {},
      votesUpdated: null
    };
  }

  castVote(issueId, value) {
    let analyzerVoteId = issueId + '/kamu';
    analyzer.set_user_vote(this.voteData, analyzerVoteId, value);
    let partyAgreements = analyzer.get_user_party_vote_agreements(this.voteData, analyzerVoteId);
    populatePartyLogos(partyAgreements, this.partyMap);
    partyAgreements = _.filter(
      partyAgreements,
      (a) => { return a.party !== "undefined" && a.partyLogo; });

    this.setState(
      (prevState) => {
        partyAgreements = Object.assign({}, prevState.partyAgreements, {[issueId]: partyAgreements});
        const userVotes = Object.assign(prevState.userVotes, {[issueId]: value});
        this.redirectHandled = false;
        const {nextCase, remainingVotes} = this.getNextCase(userVotes);
        const result = Object.assign(
          {}, prevState,
          {userVotes, nextCase, remainingVotes, partyAgreements, votesUpdated: Date.now()});
        return result;
      }
    );
  }

  emptyVotes() {
    this.setState(
      (prevState) => {
        return Object.assign({}, prevState, {userVotes: {}, nextCase: this.getNextCase({}).nextCase});
      }
    );
  }

  render() {
    if (!this.state.initialised) {
      return <div>LOADING...</div>;
    }
    if (this.state.remainingVotes === 0 && !this.redirectHandled) {
      this.redirectHandled = true;
      return <Redirect to="/party"/>;
    }
    return (
      <div className="App sans-serif">
        <Helmet>
            <meta charSet="utf-8" />
{'fraction_non_alphanumeric': 0.1418519110826803, 'fraction_numerical': 0.0009595394210778827, 'mean_word_length': 3.2285327924273157, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '3888795', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1883, 'n_words': 399}