<commit_before>import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import Loader from 'halogen/ScaleLoader';

import * as api from './api';
import * as constants from './constants';

export default class BanList extends Component {
    constructor(props) {
        super(props);

        this.state = {
            bans: [],
            servers: [],
            aliases: [],
            viewState: constants.STATE_INIT,
            totalBans: 0,
            page: 1,
            sort: { 
                field: 'created_at',
                direction: 'DESC',
            },
        };

        this.renderRow = this.renderRow.bind(this);
        this.handleScroll = this.handleScroll.bind(this);
        this.handleFetch = this.handleFetch.bind(this);
        this.handlePaginateFetch = this.handlePaginateFetch.bind(this);
    }

    componentDidMount() {
        window.addEventListener('scroll', this.handleScroll);
        this.handleFetch();
    }

    componentWillUnmount() {
        window.removeEventListener('scroll', this.handleScroll);
    }

    /**
     * Fetches fresh data from the ban list (and resets back to the first page)
     * 
     * @param object filters 
     */
    handleFetch(sortBy = this.state.sort, filters = {}) {
        this.setState({ viewState: constants.STATE_FETCHING });

        api.getBanList(1, sortBy, filters)
            .then(response => {
                const { data } = response;
                this.setState({
                    bans: data.data,
                    servers: data.relations.servers,
                    aliases: data.relations.aliases,
                    viewState: constants.STATE_READY,
                    totalBans: data.meta.count,
                    page: 1,
                });
            })
            .catch(error => {
                console.log(error);
                this.setState({ viewState: constants.STATE_FETCH_FAILED });
            });
    }

    /**
     * Fetches the next page of the ban list, reusing any currently set filters
     */
    handlePaginateFetch() {
        api.getBanList(this.state.page + 1)
            .then(response => {
                const { data } = response;
                this.setState({
                    bans: this.state.bans.concat(data.data),
                    servers: Object.assign({}, this.state.servers, data.relations.servers),
                    aliases: Object.assign({}, this.state.aliases, data.relations.aliases),
                    viewState: constants.STATE_READY,
                    page: this.state.page + 1,
                });
            })<commit_msg>Fix ban list page fetch not respecting sort order<commit_after>import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import Loader from 'halogen/ScaleLoader';

import * as api from './api';
import * as constants from './constants';

export default class BanList extends Component {
    constructor(props) {
        super(props);

        this.state = {
            bans: [],
            servers: [],
            aliases: [],
            viewState: constants.STATE_INIT,
            totalBans: 0,
            page: 1,
            sort: { 
                field: 'created_at',
                direction: 'DESC',
            },
        };

        this.renderRow = this.renderRow.bind(this);
        this.handleScroll = this.handleScroll.bind(this);
        this.handleFetch = this.handleFetch.bind(this);
        this.handlePaginateFetch = this.handlePaginateFetch.bind(this);
    }

    componentDidMount() {
        window.addEventListener('scroll', this.handleScroll);
        this.handleFetch();
    }

    componentWillUnmount() {
        window.removeEventListener('scroll', this.handleScroll);
    }

    /**
     * Fetches fresh data from the ban list (and resets back to the first page)
     * 
     * @param object filters 
     */
    handleFetch(sortBy = this.state.sort, filters = {}) {
        this.setState({ viewState: constants.STATE_FETCHING });

        api.getBanList(1, sortBy, filters)
            .then(response => {
                const { data } = response;
                this.setState({
                    bans: data.data,
                    servers: data.relations.servers,
                    aliases: data.relations.aliases,
                    viewState: constants.STATE_READY,
                    totalBans: data.meta.count,
                    page: 1,
                });
            })
            .catch(error => {
                console.log(error);
                this.setState({ viewState: constants.STATE_FETCH_FAILED });
            });
    }

    /**
     * Fetches the next page of the ban list, reusing any currently set filters
     */
    handlePaginateFetch() {
        api.getBanList(this.state.page + 1, this.state.sort)
            .then(response => {
                const { data } = response;
                this.setState({
                    bans: this.state.bans.concat(data.data),
                    servers: Object.assign({}, this.state.servers, data.relations.servers),
                    aliases: Object.assign({}, this.state.aliases, data.relations.aliases),
                    viewState: constants.STATE_READY,
                    page: this.state.page + 1,
                });
            })
{'fraction_non_alphanumeric': 0.11198062232159493, 'fraction_numerical': 0.0022358859698155395, 'mean_word_length': 1.6313725490196078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5321698', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1396, 'n_words': 307}