<commit_before>// dependencies ------------------------------------------------------------------------------

import React from 'react';

// component setup ---------------------------------------------------------------------------

export default class Paginator extends React.Component {

// life cycle events -------------------------------------------------------------------------

    render() {
        let self       = this,
            page       = this.props.page,
            breakLabel = this.props.breakLabel;

        // generate page buttons
        let Pages = this.createPageArr().map(function(p, i) {
            if (p == 'break') return ( <li key={'pgn'+ p +'-'+ i}><span>{breakLabel}</span></li> );

            // display page number
            if (page != p) {
                return (
                    <li key={'pgn'+ p +'-'+ i}>
                        <a href="#" data-page={p} onClick={self.onPageSelect.bind(self)}>
                            {(p + 1)}
                        </a>
                    </li>
                );
            } else {
                return (
                    <li key={'pgn'+ p +'-'+ i} className="active">
                        <span>{(p + 1)}</span>
                    </li>
                );
            }
        });

        // conditionally create previous button
        let prevBtn;
        if (this.props.prevLabel != false && page != 0) {
            prevBtn = (
                <li key="pgn-prev">
                    <a href="#" data-page={(page - 1)} onClick={self.onPageSelect.bind(self)}>
                        {this.props.prevLabel}
                    </a>
                </li>
            );
        }

        // conditionally create next button
        let nextBtn;
        if (this.props.nextLabel != false && page != this.props.pagesTotal - 1) {
            nextBtn = (
                <li key="pgn-next">
                    <a href="#" data-page={(page + 1)} onClick={self.onPageSelect.bind(self)}>
                        {this.props.nextLabel}
                    </a>
                </li>
            );
        }

        return (
            <ul className={this.props.containerClass}>
                {prevBtn}
                {Pages}
                {nextBtn}
            </ul>
        );
    }


// custom methods ----------------------------------------------------------------------------

    onPageSelect(e) {
        // get the selected page
         var thePage = e.currentTarget.getAttribute('data-page');
        // call props function
         if(this.props.onPageSelect) this.props.onPageSelect(thePage, e);
        // prevent Default
         e.preventDefault();
    }


    createPageArr() {

        var pageArr = [];

        if (this.props.pagesTotal <= this.props.pageRangeDisplayed) {
            return Array((this.props.pagesTotal - 1));
        } else {

            // shortcut all
            var pagesTotal = this.props.pagesTotal,
                page = parseInt(this.props.page),
                activePageRangeDisplayed = parseInt(this.props.activePageRangeDisplayed),
                pageRangeDisplayed = this.props.pageRangeDisplayed,
                activeRangeStart = (page - activePageRangeDisplayed),
                activeRangeEnd = page + activePageRangeDisplayed,
                lastRange = (pagesTotal - pageRangeDisplayed),
                lastI = 0,
                currentI = 0;


            // walk through all pages and formulate them
            for (var i = 0; i < pagesTotal; i++) {
                if (
                    // if this page is one of the starting pages
                    i < pageRangeDisplayed ||
                    // else if the page is within the active range
                    (i >= activeRangeStart && i <= activeRangeEnd) ||
                    // or if page is at the end
                    (i >= lastRange)
                ) { currentI = i; }

                // else add a break
                else {currentI = 'break'};


                // if we haven't just used a break and this one is too -> add the current I<commit_msg>fixed paginator bug<commit_after>// dependencies ------------------------------------------------------------------------------

import React from 'react';

// component setup ---------------------------------------------------------------------------

export default class Paginator extends React.Component {

// life cycle events -------------------------------------------------------------------------

    render() {
        let self       = this,
            page       = this.props.page,
            breakLabel = this.props.breakLabel;

        // generate page buttons
        let Pages = this.createPageArr().map(function(p, i) {
            if (p == 'break') return ( <li key={'pgn'+ p +'-'+ i}><span>{breakLabel}</span></li> );

            // display page number
            if (page != p) {
                return (
                    <li key={'pgn'+ p +'-'+ i}>
                        <a href="#" data-page={p} onClick={self.onPageSelect.bind(self)}>
                            {(p + 1)}
                        </a>
                    </li>
                );
            } else {
                return (
                    <li key={'pgn'+ p +'-'+ i} className="active">
                        <span>{(p + 1)}</span>
                    </li>
                );
            }
        });

        // conditionally create previous button
        let prevBtn;
        if (this.props.prevLabel != false && page != 0) {
            prevBtn = (
                <li key="pgn-prev">
                    <a href="#" data-page={(page - 1)} onClick={self.onPageSelect.bind(self)}>
                        {this.props.prevLabel}
                    </a>
                </li>
            );
        }

        // conditionally create next button
        let nextBtn;
        if (this.props.nextLabel != false && page != this.props.pagesTotal - 1) {
            nextBtn = (
                <li key="pgn-next">
                    <a href="#" data-page={(page + 1)} onClick={self.onPageSelect.bind(self)}>
                        {this.props.nextLabel}
                    </a>
                </li>
            );
        }

        return (
            <ul className={this.props.containerClass}>
                {prevBtn}
                {Pages}
                {nextBtn}
            </ul>
        );
    }


// custom methods ----------------------------------------------------------------------------

    onPageSelect(e) {
        // get the selected page
         var thePage = e.currentTarget.getAttribute('data-page');
        // call props function
         if(this.props.onPageSelect) this.props.onPageSelect(thePage, e);
        // prevent Default
         e.preventDefault();
    }


    createPageArr() {

        var pageArr = [];

        if (this.props.pagesTotal <= this.props.pageRangeDisplayed) {
            let arr = [];
            for (let i = 0; i < this.props.pagesTotal; i++) {
                arr.push(i);
            }
            return arr;
        } else {

            // shortcut all
            var pagesTotal = this.props.pagesTotal,
                page = parseInt(this.props.page),
                activePageRangeDisplayed = parseInt(this.props.activePageRangeDisplayed),
                pageRangeDisplayed = this.props.pageRangeDisplayed,
                activeRangeStart = (page - activePageRangeDisplayed),
                activeRangeEnd = page + activePageRangeDisplayed,
                lastRange = (pagesTotal - pageRangeDisplayed),
                lastI = 0,
                currentI = 0;


            // walk through all pages and formulate them
            for (var i = 0; i < pagesTotal; i++) {
                if (
                    // if this page is one of the starting pages
                    i < pageRangeDisplayed ||
                    // else if the page is within the active range
                    (i >= activeRangeStart && i <= activeRangeEnd) ||
                    // or if page is at the end
                    (i >= lastRange)
                ) { currentI = i; }

                // else add a break
                else {currentI = 'break'};


                // if we haven't just used a break and this one is too -> add the current I
{'fraction_non_alphanumeric': 0.18123949075186163, 'fraction_numerical': 0.0024021138601969735, 'mean_word_length': 1.0128112158569011, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 53, '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': '6641626', 'n_tokens_mistral': 2084, 'n_tokens_neox': 1936, 'n_words': 504}