<commit_before>import React from "react";
import counterpart from "counterpart";
import IntlActions from "actions/IntlActions";
import Translate from "react-translate-component";
import cookies from "cookies-js";
import SettingsActions from "actions/SettingsActions";


class Settings extends React.Component {

    _onChangeLanguage(e) {
        e.preventDefault();
        let myLocale = counterpart.getLocale();
        if (e.target.value !== myLocale) {
            IntlActions.switchLocale(e.target.value);
            cookies.set("graphene_locale", e.target.value, { expires: Infinity });
            SettingsActions.changeSetting({setting: "locale", value: e.target.value });
        }
    }

    _onChangeSetting(setting, e) {
        e.preventDefault();
        let {currencies, orientation} = this.props.defaults;
        let value = null;
        switch (setting) {
            case "inverseMarket":
                value = orientation.indexOf(e.target.value) === 0; // USD/CORE is true, CORE/USD is false
                break;

            case "unit":
                value = currencies.indexOf(e.target.value);
                break;

            default:
                break;
        }

        if (value !== null) {
            SettingsActions.changeSetting({setting: setting, value: value });
        }

    }

    render() {
        let {currencies, locales, orientation} = this.props.defaults;
        let myLocale = counterpart.getLocale();

        var options = locales.map(function(locale) {
            var translationKey = "languages." + locale;
            return <Translate key={locale} value={locale} component="option" content={translationKey} />;
        }).sort((a, b) => {
            if (a.key === myLocale) {
                return -1;
            }
            if (b.key === myLocale) {
                return 1;
            }
            if (b.key < a.key) {
                return 1;
            } else if (b.key > a.key) {
                return -1;
            } else {
                return 0;
            }
        });


        let unitOptions = currencies.map((unit, index) => {
            return <option key={index}>{unit}</option>;
        });

        return (
            <div className="grid-block">
                <div className="grid-block small-offset-3 small-6">
                    <div className="grid-content">
                        <div className="grid-block"></div>
                        <section className="block-list">
                            <header><Translate component="span" content="languages.switch" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} onChange={this._onChangeLanguage}>
                                        {options}
                                    </select>
                                    </li>
                                </ul>
                        </section>
                        <section className="block-list">
                            <header><Translate component="span" content="settings.inversed" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} onChange={this._onChangeSetting.bind(this, "inverseMarket")}>
                                        <option>{orientation[0]}</option>
                                        <option>{orientation[1]}</option>
                                    </select>
                                    </li>
                                </ul>
                        </section>
                        <section className="block-list">
                            <header><Translate component="span" content="settings.unit" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} onChange={this._onChangeSetting.bind(this, "unit")}>
                                        {unitOptions}<commit_msg>Properly set stored settings<commit_after>import React from "react";
import counterpart from "counterpart";
import IntlActions from "actions/IntlActions";
import Translate from "react-translate-component";
import cookies from "cookies-js";
import SettingsActions from "actions/SettingsActions";


class Settings extends React.Component {

    _onChangeLanguage(e) {
        e.preventDefault();
        let myLocale = counterpart.getLocale();
        if (e.target.value !== myLocale) {
            IntlActions.switchLocale(e.target.value);
            cookies.set("graphene_locale", e.target.value, { expires: Infinity });
            SettingsActions.changeSetting({setting: "locale", value: e.target.value });
        }
    }

    _onChangeSetting(setting, e) {
        e.preventDefault();
        let {currencies, orientation} = this.props.defaults;
        let value = null;
        switch (setting) {
            case "inverseMarket":
                value = orientation.indexOf(e.target.value) === 0; // USD/CORE is true, CORE/USD is false
                break;

            case "unit":
                value = currencies.indexOf(e.target.value);
                break;

            default:
                break;
        }

        if (value !== null) {
            SettingsActions.changeSetting({setting: setting, value: value });
        }

    }

    render() {
        let {settings} = this.props;
        let {currencies, locales, orientation} = this.props.defaults;
        let myLocale = counterpart.getLocale();

        var options = locales.map(function(locale) {
            var translationKey = "languages." + locale;
            return <Translate key={locale} value={locale} component="option" content={translationKey} />;
        }).sort((a, b) => {
            if (a.key === myLocale) {
                return -1;
            }
            if (b.key === myLocale) {
                return 1;
            }
            if (b.key < a.key) {
                return 1;
            } else if (b.key > a.key) {
                return -1;
            } else {
                return 0;
            }
        });


        let unitOptions = currencies.map((unit, index) => {
            return <option key={index}>{unit}</option>;
        });

        let selectedOrientation = settings.get("inverseMarket") ? 0 : 1;

        return (
            <div className="grid-block">
                <div className="grid-block small-offset-3 small-6">
                    <div className="grid-content">
                        <div className="grid-block"></div>
                        <section className="block-list">
                            <header><Translate component="span" content="languages.switch" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} onChange={this._onChangeLanguage}>
                                        {options}
                                    </select>
                                    </li>
                                </ul>
                        </section>
                        <section className="block-list">
                            <header><Translate component="span" content="settings.inversed" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} value={orientation[selectedOrientation]} onChange={this._onChangeSetting.bind(this, "inverseMarket")}>
                                        <option>{orientation[0]}</option>
                                        <option>{orientation[1]}</option>
                                    </select>
                                    </li>
                                </ul>
                        </section>
                        <section className="block-list">
                            <header><Translate component="span" content="settings.unit" />:</header>
                                <ul>
                                    <li className="with-dropdown">
                                    <select style={{lineHeight: "1.2em"}} value={currencies[settings.get("unit")]} onChange={this._onChangeSetting.bind(this, "unit")}>
                                        {unitOptions}
{'fraction_non_alphanumeric': 0.11890315052508751, 'fraction_numerical': 0.0039673278879813305, 'mean_word_length': 1.2770988310308182, 'pattern_counts': {'":': 4, '<': 87, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '514121', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1948, 'n_words': 416}