<commit_before>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import {_, pgettext, interpolate, cc_to_country_name, sorted_locale_countries} from "translate";
import {Link} from "react-router-dom";
import {openModal} from 'Modal';
import {NotesModal} from 'NotesModal';
import {post, get, put, del, patch} from "requests";
import * as data from "data";
import * as moment from "moment";
import {Card} from 'material';
import {PlayerIcon} from 'PlayerIcon';
import {GameList} from "GameList";
import {Player} from "Player";
import {updateDup, alertModerator, getGameResultText, ignore} from "misc";
import {longRankString, rankString, getUserRating} from "rank_utils";
import {durationString} from "TimeControl";
import {openModerateUserModal} from "ModerateUser";
import {openSupporterAdminModal} from "SupporterAdmin";
import {PaginatedTable} from "PaginatedTable";
import {challenge} from "ChallengeModal";
import {errorAlerter} from "misc";
import * as player_cache from "player_cache";
import {getPrivateChat} from "PrivateChat";
import {PlayerAutocomplete} from "PlayerAutocomplete";
import * as Dropzone from "react-dropzone";
import {image_resizer} from "image_resizer";
import {Flag} from "Flag";
import {Markdown} from "Markdown";
import {RatingsChart} from 'RatingsChart';


declare let swal;

interface UserProperties {
    match: {
        params: any
    };
    // id?: any,
    // user?: any,
    // callback?: ()=>any,
}

let UserRating = (props: {rating: number}) => {
    let wholeRating = Math.floor(props.rating);
    return <span className="UserRating">{wholeRating}</span>;
};

let rating_percentage = (rating: number) => {
    rating %= 100;
    rating = rating >= 0 ? rating : rating + 100;
    return rating;
};

let Rank = (props: {ranking: number, pro?: boolean}) => (<span>{rankString(props)}</span>);

let center = {textAlign: "center"};
let right = {textAlign: "right"};
let inlineBlock = {display: "inline-block"};
let marginRight0 = {marginRight: "0"};
let marginBottom0 = {marginBottom: "0"};
let nowrapAlignTop = {whiteSpace: "nowrap", verticalAlign: "top"};

export class User extends React.PureComponent<UserProperties, any> {
    refs: {
        moderator_notes;
        vacation_left;
        bot_ai;
        game_table;
        review_table;
    };
    user_id: number;
    vacation_left: string;
    original_username: string;
    vacation_update_interval: any;

    constructor(props) {
        super(props);
        this.state = {
            user: null,
            vs: {},
            ratings: {},
            ip: null,
            vacation_left: null,
            vacation_left_text: "",
            ranks: [],
            syncRating: null,
            host_ip_settings: null,
            new_icon: null,
            bot_apikey: null,
            bot_ai: null,
            editing: /edit/.test(window.location.hash),
            selected_speed: 'overall',
            selected_size: 0,
            resolved: false,
        };
    }

    componentDidMount() {
        let interval_start = Date.now();
        this.vacation_update_interval = setInterval(() => {
            if (this.state.user) {
                if (this.state.user.on_vacation) {
                    let time_diff = Math.round(((Date.now()) - interval_start) / 1000);
                    let vacation_time_left = this.state.user.vacation_left - time_diff;
                    this.setState({
                        vacation_left_text: vacation_time_left > 0 ? durationString(vacation_time_left) : ("0 " + _("Seconds").toLowerCase())
                    });
                }
            }
        }, 1000);
        this.resolve(this.props);
    }
    componentWillUnmount() {
        clearInterval(this.vacation_update_interval);
    }

    componentWillReceiveProps(nextProps) {
        if (nextProps.params.user_id !== this.props.match.params.user_id) {
            this.setState({"user": null, resolved: false});<commit_msg>Fixed ability to switch between profile pages<commit_after>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import {_, pgettext, interpolate, cc_to_country_name, sorted_locale_countries} from "translate";
import {Link} from "react-router-dom";
import {openModal} from 'Modal';
import {NotesModal} from 'NotesModal';
import {post, get, put, del, patch} from "requests";
import * as data from "data";
import * as moment from "moment";
import {Card} from 'material';
import {PlayerIcon} from 'PlayerIcon';
import {GameList} from "GameList";
import {Player} from "Player";
import {updateDup, alertModerator, getGameResultText, ignore} from "misc";
import {longRankString, rankString, getUserRating} from "rank_utils";
import {durationString} from "TimeControl";
import {openModerateUserModal} from "ModerateUser";
import {openSupporterAdminModal} from "SupporterAdmin";
import {PaginatedTable} from "PaginatedTable";
import {challenge} from "ChallengeModal";
import {errorAlerter} from "misc";
import * as player_cache from "player_cache";
import {getPrivateChat} from "PrivateChat";
import {PlayerAutocomplete} from "PlayerAutocomplete";
import * as Dropzone from "react-dropzone";
import {image_resizer} from "image_resizer";
import {Flag} from "Flag";
import {Markdown} from "Markdown";
import {RatingsChart} from 'RatingsChart';


declare let swal;

interface UserProperties {
    match: {
        params: any
    };
    // id?: any,
    // user?: any,
    // callback?: ()=>any,
}

let UserRating = (props: {rating: number}) => {
    let wholeRating = Math.floor(props.rating);
    return <span className="UserRating">{wholeRating}</span>;
};

let rating_percentage = (rating: number) => {
    rating %= 100;
    rating = rating >= 0 ? rating : rating + 100;
    return rating;
};

let Rank = (props: {ranking: number, pro?: boolean}) => (<span>{rankString(props)}</span>);

let center = {textAlign: "center"};
let right = {textAlign: "right"};
let inlineBlock = {display: "inline-block"};
let marginRight0 = {marginRight: "0"};
let marginBottom0 = {marginBottom: "0"};
let nowrapAlignTop = {whiteSpace: "nowrap", verticalAlign: "top"};

export class User extends React.PureComponent<UserProperties, any> {
    refs: {
        moderator_notes;
        vacation_left;
        bot_ai;
        game_table;
        review_table;
    };
    user_id: number;
    vacation_left: string;
    original_username: string;
    vacation_update_interval: any;

    constructor(props) {
        super(props);
        this.state = {
            user: null,
            vs: {},
            ratings: {},
            ip: null,
            vacation_left: null,
            vacation_left_text: "",
            ranks: [],
            syncRating: null,
            host_ip_settings: null,
            new_icon: null,
            bot_apikey: null,
            bot_ai: null,
            editing: /edit/.test(window.location.hash),
            selected_speed: 'overall',
            selected_size: 0,
            resolved: false,
        };
    }

    componentDidMount() {
        let interval_start = Date.now();
        this.vacation_update_interval = setInterval(() => {
            if (this.state.user) {
                if (this.state.user.on_vacation) {
                    let time_diff = Math.round(((Date.now()) - interval_start) / 1000);
                    let vacation_time_left = this.state.user.vacation_left - time_diff;
                    this.setState({
                        vacation_left_text: vacation_time_left > 0 ? durationString(vacation_time_left) : ("0 " + _("Seconds").toLowerCase())
                    });
                }
            }
        }, 1000);
        this.resolve(this.props);
    }
    componentWillUnmount() {
        clearInterval(this.vacation_update_interval);
    }

    componentWillReceiveProps(nextProps) {
        if (nextProps.match.params.user_id !== this.props.match.params.user_id) {
            this.setState({"user": null, resolved: false});
{'fraction_non_alphanumeric': 0.11743886743886744, 'fraction_numerical': 0.006649506649506649, 'mean_word_length': 3.0124784853700515, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1968327', 'n_tokens_mistral': 2763, 'n_tokens_neox': 2648, 'n_words': 801}