<commit_before>/**
 * This file is part of the MovieFinder package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

import * as React from 'react'
import * as Promise from 'bluebird'
import {connect, Dispatch} from "react-redux";
import * as electron from 'electron'
import * as cx from 'classnames'
import getMovies from "../actions/getMovies";

const Dialog = electron.remote.require('electron').dialog;

interface AnalyzeButtonProps {
    getMovies: (path: string) => Promise<any>
}

interface AnalyzeButtonState {
    loading: boolean
}

class AnalyzeButton extends React.Component<AnalyzeButtonProps, AnalyzeButtonState> {

    state = {
        loading: false
    };

    handleClick(e) {
        e.preventDefault();
        if (!this.state.loading) {
            const directory = Dialog.showOpenDialog({
                properties: ['openDirectory']
            });
            if (directory) {
                this.setState({loading: true});
                this.props.getMovies(directory[0]).then(() => {
                    console.log('ok');
                })
            }
        }
    }

    render() {
        return (
            <a href="" onClick={this.handleClick.bind(this)} className={cx({disabled: this.state.loading})}>
                {this.state.loading
                    ? (<span><i className="fa fa-spinner"/> Analyzovat složku</span>)
                    : (<span><i className="fa fa-folder-open" /> Analyzovat složku</span>)
                }
            </a>
        )
    }

}

const mapDispatchToProps = (dispatch: Dispatch<any>) => {
    return {
        getMovies: (path: string) => {
            return dispatch(getMovies(path))
        }
    }
};

export default connect(null, mapDispatchToProps)(AnalyzeButton)<commit_msg>Fixed loading<commit_after>/**
 * This file is part of the MovieFinder package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */

import * as React from 'react'
import * as Promise from 'bluebird'
import {connect, Dispatch} from "react-redux";
import * as electron from 'electron'
import * as cx from 'classnames'
import getMovies from "../actions/getMovies";

const Dialog = electron.remote.require('electron').dialog;

interface AnalyzeButtonProps {
    getMovies: (path: string) => Promise<any>
}

interface AnalyzeButtonState {
    loading: boolean
}

class AnalyzeButton extends React.Component<AnalyzeButtonProps, AnalyzeButtonState> {

    state = {
        loading: false
    };

    handleClick(e) {
        e.preventDefault();
        if (!this.state.loading) {
            const directory = Dialog.showOpenDialog({
                properties: ['openDirectory']
            });
            if (directory) {
                this.setState({loading: true});
                this.props.getMovies(directory[0]).finally(() => {
                    this.setState({loading: false});
                })
            }
        }
    }

    render() {
        return (
            <a href="" onClick={this.handleClick.bind(this)} className={cx({disabled: this.state.loading})}>
                {this.state.loading
                    ? (<span><i className="fa fa-spinner"/> Analyzovat složku</span>)
                    : (<span><i className="fa fa-folder-open" /> Analyzovat složku</span>)
                }
            </a>
        )
    }

}

const mapDispatchToProps = (dispatch: Dispatch<any>) => {
    return {
        getMovies: (path: string) => {
            return dispatch(getMovies(path))
        }
    }
};

export default connect(null, mapDispatchToProps)(AnalyzeButton)
{'fraction_non_alphanumeric': 0.12734974847762776, 'fraction_numerical': 0.0005295207836907599, 'mean_word_length': 2.265341400172861, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, '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': '6947426', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1040, 'n_words': 259}