<commit_before>import React from "react";

require("../../css/2-components/home.scss");

const fs = window.require("fs");
const axios = require("axios");
const global = require("../app/global.js");
import IO from "../app/IO";

const Home = React.createClass({
    getInitialState: function() {
        return {
            listPath: global.userItems,
            jsonList: "",
            omdbData: ""
        };
    },

    componentDidMount: function() {
        this.readListContents();
        this.fetchEpisodeData();
    },

    componentWillMount: function() {
        let io = new IO;
        io.createFileIfNotExists(global.userItems);
    },

    render: function() {
        let cards = [];

        cards = this.constructCardArray();

        return (
            <div className="row">
                {cards}
            </div>
        );
    },

    readListContents: function() {
        let data = fs.readFileSync(this.state.listPath, "utf8");

        if (data === "")
            this.state.jsonList = data;
        else
            this.state.jsonList = JSON.parse(data);
    },

    fetchEpisodeData: function() {
        let list = this.state.jsonList;
        let data = [];
        let temp;
        let item;
        let currentData;
        let finalStateValue;

        Object.keys(list).forEach((key,index) => {
            axios.get(`http://www.omdbapi.com/?t=${list[index].name}&Season=${list[index].season}&Episode=${list[index].episode}`)
            .then((response) => {<commit_msg>Refactor reading userlist in home component<commit_after>import React from "react";

require("../../css/2-components/home.scss");

const fs = window.require("fs");
const axios = require("axios");
const global = require("../app/global.js");
import IO from "../app/IO";

const Home = React.createClass({
    getInitialState: function() {
        return {
            listPath: global.userItems,
            jsonList: "",
            omdbData: ""
        };
    },

    componentDidMount: function() {
        this.readListContents();
        this.fetchEpisodeData();
    },

    componentWillMount: function() {
        let io = new IO;
        io.createFileIfNotExists(global.userItems);
    },

    render: function() {
        let cards = [];

        cards = this.constructCardArray();

        return (
            <div className="row">
                {cards}
            </div>
        );
    },

    readListContents: function() {
        const io = new IO;
        let data = io.readJSON(global.userItems);
        this.setState({jsonList: data});
    },

    fetchEpisodeData: function() {
        let list = this.state.jsonList;
        let data = [];
        let temp;
        let item;
        let currentData;
        let finalStateValue;

        Object.keys(list).forEach((key,index) => {
            axios.get(`http://www.omdbapi.com/?t=${list[index].name}&Season=${list[index].season}&Episode=${list[index].episode}`)
            .then((response) => {
{'fraction_non_alphanumeric': 0.15191146881287726, 'fraction_numerical': 0.001006036217303823, 'mean_word_length': 2.0284263959390865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2984777', 'n_tokens_mistral': 871, 'n_tokens_neox': 844, 'n_words': 165}