<commit_before>import classNames from 'classnames';
import i18next from 'i18next';
import isEqual from 'lodash/isEqual';
import React, { Component } from 'react';
import shallowCompare from 'react-addons-shallow-compare';
import api from '../../api';
import settings from '../../config/settings';
import Anchor from '../../components/Anchor';
import Breadcrumb from '../../components/Breadcrumb';
import confirm from '../../lib/confirm';
import i18n from '../../lib/i18n';
import store from '../../store';
import General from './General';
import About from './About';
import styles from './index.styl';

class Settings extends Component {
    actions = {
        // General
        general: {
            handleRestoreDefaults: (event) => {
                confirm({
                    title: i18n._('Restore Defaults'),
                    body: i18n._('Are you sure you want to restore the default settings?')
                }).then(() => {
                    store.clear();
                    window.location = '/';
                });
            },
            handleCancel: (event) => {
                const defaultState = this.getDefaultState();
                this.setState({ general: defaultState.general });
            },
            handleSave: (event) => {
                const { lang = 'en' } = this.state.general;

                i18next.changeLanguage(lang, (err, t) => {
                    window.location = '/';
                });
            },
            changeLanguage: (lang) => {
                this.setState({
                    general: {
                        ...this.state.general,
                        lang: lang
                    }
                });
            }
        },
        // About
        about: {
            checkLatestVersion: () => {
                this.setState({
                    about: {
                        ...this.state.about,
                        version: {
                            ...this.state.about.version,
                            checking: true
                        }
                    }
                });

                api.getLatestVersion()
                    .then((res) => {
                        const { version, time } = res.body;
                        this.setState({
                            about: {
                                ...this.state.about,
                                version: {
                                    ...this.state.about.version,
                                    checking: false,
                                    latest: version,
                                    lastUpdate: time
                                }
                            }
                        });
                    })
                    .catch((err) => {
                        // Ignore error
                    });
            }
        }
    };
    sections = [
        {
            key: 'general',
            title: i18n._('General'),
            component: (props) => <General {...props} />
        },
        {
            key: 'about',
            title: i18n._('About'),
            component: (props) => <About {...props} />
        }
    ];

    constructor() {
        super();
        this.state = this.getDefaultState();
    }
    shouldComponentUpdate(nextProps, nextState) {
        return shallowCompare(this, nextProps, nextState);
    }
    getDefaultState() {<commit_msg>[i18n] "My Account"<commit_after>import classNames from 'classnames';
import i18next from 'i18next';
import isEqual from 'lodash/isEqual';
import React, { Component } from 'react';
import shallowCompare from 'react-addons-shallow-compare';
import api from '../../api';
import settings from '../../config/settings';
import Anchor from '../../components/Anchor';
import Breadcrumb from '../../components/Breadcrumb';
import confirm from '../../lib/confirm';
import i18n from '../../lib/i18n';
import store from '../../store';
import General from './General';
import About from './About';
import styles from './index.styl';

class Settings extends Component {
    actions = {
        // General
        general: {
            handleRestoreDefaults: (event) => {
                confirm({
                    title: i18n._('Restore Defaults'),
                    body: i18n._('Are you sure you want to restore the default settings?')
                }).then(() => {
                    store.clear();
                    window.location = '/';
                });
            },
            handleCancel: (event) => {
                const defaultState = this.getDefaultState();
                this.setState({ general: defaultState.general });
            },
            handleSave: (event) => {
                const { lang = 'en' } = this.state.general;

                i18next.changeLanguage(lang, (err, t) => {
                    window.location = '/';
                });
            },
            changeLanguage: (lang) => {
                this.setState({
                    general: {
                        ...this.state.general,
                        lang: lang
                    }
                });
            }
        },
        // About
        about: {
            checkLatestVersion: () => {
                this.setState({
                    about: {
                        ...this.state.about,
                        version: {
                            ...this.state.about.version,
                            checking: true
                        }
                    }
                });

                api.getLatestVersion()
                    .then((res) => {
                        const { version, time } = res.body;
                        this.setState({
                            about: {
                                ...this.state.about,
                                version: {
                                    ...this.state.about.version,
                                    checking: false,
                                    latest: version,
                                    lastUpdate: time
                                }
                            }
                        });
                    })
                    .catch((err) => {
                        // Ignore error
                    });
            }
        }
    };
    sections = [
        {
            key: 'general',
            title: i18n._('General'),
            component: (props) => <General {...props} />
        },
        /*
        {
            key: 'account',
            title: i18n._('My Account'),
            component: (props) => <Account {...props} />
        },
        */
        {
            key: 'about',
            title: i18n._('About'),
            component: (props) => <About {...props} />
        }
    ];

    constructor() {
        super();
        this.state = this.getDefaultState();
    }
    shouldComponentUpdate(nextProps, nextState) {
        return shallowCompare(this, nextProps, nextState);
    }
    getDefaultState() {
{'fraction_non_alphanumeric': 0.12590489709013486, 'fraction_numerical': 0.0056777856635912, 'mean_word_length': 0.9610353465070971, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3819620', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1581, 'n_words': 353}