<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux'
import { addCategory} from "../actions/index"


/**
 * @description Creates a list of all posts ordered by voteScore (highest score first)
 * @constructor
 */
class Categories extends Component {
    // generate random integer for key index where no unique value available
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
    getRandomInt = (min = 1, max = 999999) =>  {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min)) + min;
    }

    submitCategory = () => {

        this.props.dispatch(addCategory({
            name: this.input.value,
            pathName : this.input.value,
        }))
        this.input.value = ''
    };

    render() {
        return (
            <div id="cat-view">
                <div>
                    <ul id="cat-list">
                        {/*TODO: using forEach did not work, because does not return array??*/}
                        {console.log(this.props)}
                        {/*{*/}
                            {/*this.props.categories.map( (category, idx) => (*/}
                                {/*<li key={idx}>*/}
                                    {/*{ category.name }*/}
                                {/*</li>*/}
                            {/*) )*/}
                        {/*}*/}

                    </ul>
                </div>
                <div>

                    <input
                        type="'text"
                        ref={(input) => this.input = input}
                        placeholder="enter new category"
                    />
                    <button onClick={this.submitCategory}>Submit</button>
                </div>

            </div>
        )
    }
}

// mapStateToProps must return a plain object
function mapStateToProps({ categories }) {
    console.log( categories.categories );
    let catArray =  Object.keys( categories ).map(key => categories[key]);
    console.log(catArray)
    // return Object.keys( categories ).map(key => categories[key])
    return catArray
}

export default connect(mapStateToProps)(Categories);<commit_msg>Bug: categories in state nested in object, component map function undefined error<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux'
import { addCategory} from "../actions/index"


/**
 * @description Creates a list of all posts ordered by voteScore (highest score first)
 * @constructor
 */
class Categories extends Component {
    // generate random integer for key index where no unique value available
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
    getRandomInt = (min = 1, max = 999999) =>  {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min)) + min;
    }

    submitCategory = () => {

        this.props.dispatch(addCategory({
            name: this.input.value,
            pathName : this.input.value,
        }))
        this.input.value = ''
    };

    render() {
        return (
            <div id="cat-view">
                <div>
                    <ul id="cat-list">
                        {/*TODO: using forEach did not work, because does not return array??*/}
                        {console.log(this.props.categories)}
                        {/*{*/}
                            {/*this.props.categories.map( (category, idx) => (*/}
                                {/*<li key={idx}>*/}
                                    {/*{ category.name }*/}
                                {/*</li>*/}
                            {/*) )*/}
                        {/*}*/}

                    </ul>
                </div>
                <div>

                    <input
                        type="'text"
                        ref={(input) => this.input = input}
                        placeholder="enter new category"
                    />
                    <button onClick={this.submitCategory}>Submit</button>
                </div>

            </div>
        )
    }
}

// mapStateToProps must return a plain object
function mapStateToProps({ posts, categories }) {
    console.log( categories );
    let catArray =  Object.keys( categories ).map(key => categories[key]);
    console.log(catArray)
    // return Object.keys( categories ).map(key => categories[key])
    return categories
}

export default connect(mapStateToProps)(Categories);
{'fraction_non_alphanumeric': 0.13269024651661307, 'fraction_numerical': 0.0030010718113612006, 'mean_word_length': 1.459673168160253, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4598732', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1172, 'n_words': 285}