<commit_before>import React, { Component } from 'react';
import {
  BrowserRouter as Router,
  Route,
  Switch,
  Link,
  NavLink
} from 'react-router-dom';
import firebase from 'firebase';

import QuizList from './quiz/QuizList';
import QuizListEdit from './quiz/QuizListEdit';
import QuizView from './quiz/QuizView';
import QuizEdit from './quiz/QuizEdit';
import QuizAdd from './quiz/QuizAdd';

import logo from './logo.svg';
import './App.css';

class App extends Component {

  constructor() {

    super();

    this.state = {
      quiz: {},
      answer: {},
      quizOrder: {},
      firstQuiz: ""
    };
  }

  componentWillMount() {

    const data = firebase.database().ref();

    data.on('value', snapshot => {
      this.setState((prevState, props) => {

        const quiz = snapshot.val().quiz;

        let orderArray = [];
        Object.keys(quiz).forEach((key) => {
          orderArray.push(quiz[key].order);
          prevState.quizOrder[quiz[key].order] = {
            current: key
          };
        });

        orderArray = orderArray.sort();
        orderArray.forEach((order, index) => {
          if (index > 0) {
            prevState.quizOrder[order].prev = prevState.quizOrder[orderArray[index - 1]].current;
          } else {
            prevState.quizOrder[order].prev = "";
            prevState.firstQuiz = prevState.quizOrder[order].current;
          }
          if (index < orderArray.length - 1) {
            prevState.quizOrder[order].next = prevState.quizOrder[orderArray[index + 1]].current;
          } else {
            prevState.quizOrder[order].next = "";
          }
        });

        return {
          quiz: quiz,
          answer: snapshot.val().answer,
          quizOrder: prevState.quizOrder,
          firstQuiz: prevState.firstQuiz
        };
      });
    });
  }

  render() {

    const HomePage = () => {
      const quiz = this.state.quiz;
      const order = this.state.quizOrder;
      const first = this.state.firstQuiz;
      const answer = this.state.answer;
      return (
        <section key={this.state.firstQuiz} className="Quiz">
          <QuizView 
            prev={order[quiz[first].order].prev} 
            next={order[quiz[first].order].next} 
            answer={answer[first]} {...quiz[first]} <commit_msg>fix undefined data for initial loading<commit_after>import React, { Component } from 'react';
import {
  BrowserRouter as Router,
  Route,
  Switch,
  Link,
  NavLink
} from 'react-router-dom';
import firebase from 'firebase';

import QuizList from './quiz/QuizList';
import QuizListEdit from './quiz/QuizListEdit';
import QuizView from './quiz/QuizView';
import QuizEdit from './quiz/QuizEdit';
import QuizAdd from './quiz/QuizAdd';

import logo from './logo.svg';
import './App.css';

class App extends Component {

  constructor() {

    super();

    this.state = {
      quiz: {},
      answer: {},
      quizOrder: {},
      firstQuiz: ""
    };
  }

  componentWillMount() {

    const data = firebase.database().ref();

    data.on('value', snapshot => {
      this.setState((prevState, props) => {

        const quiz = snapshot.val().quiz;

        let orderArray = [];
        Object.keys(quiz).forEach((key) => {
          orderArray.push(quiz[key].order);
          prevState.quizOrder[quiz[key].order] = {
            current: key
          };
        });

        orderArray = orderArray.sort();
        orderArray.forEach((order, index) => {
          if (index > 0) {
            prevState.quizOrder[order].prev = prevState.quizOrder[orderArray[index - 1]].current;
          } else {
            prevState.quizOrder[order].prev = "";
            prevState.firstQuiz = prevState.quizOrder[order].current;
          }
          if (index < orderArray.length - 1) {
            prevState.quizOrder[order].next = prevState.quizOrder[orderArray[index + 1]].current;
          } else {
            prevState.quizOrder[order].next = "";
          }
        });

        return {
          quiz: quiz,
          answer: snapshot.val().answer,
          quizOrder: prevState.quizOrder,
          firstQuiz: prevState.firstQuiz
        };
      });
    });
  }

  render() {

    const HomePage = () => {
      const quiz = this.state.quiz;
      const order = this.state.quizOrder;
      const first = this.state.firstQuiz;
      const answer = this.state.answer;
      const prev = quiz[first] ? order[quiz[first].order].prev : "";
      const next = quiz[first] ? order[quiz[first].order].next : "";

      return (
        <section key={this.state.firstQuiz} className="Quiz">
          <QuizView 
            prev={prev} 
            next={next} 
            answer={answer[first]} {...quiz[first]} 
{'fraction_non_alphanumeric': 0.14437367303609341, 'fraction_numerical': 0.0016985138004246285, 'mean_word_length': 2.130232558139535, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4168771', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1426, 'n_words': 273}