<commit_before>'use strict';

import Icon from './icon.react';

var cx = React.addons.classSet;

export default React.createClass({
    displayName: 'CardFavoriteButton',
    propTypes: {
        cardApi: React.PropTypes.func.isRequired,
        cardId: React.PropTypes.number.isRequired
    },

    getInitialState: function() {
        return {
            favorite: false
        };
    },

    componentDidMount: function() {
        this.loadFavoriteStatus();
    },

    componentWillReceiveProps: function(newProps) {
        this.loadFavoriteStatus();
    },

    loadFavoriteStatus: function() {
        var component = this;

        // initialize the current favorite status
        this.props.cardApi.isfavorite({
            'cardId': component.props.cardId
        }, function(result) {
            var fav = false;
            if (result.favorite === true) {
                fav = true;
            }

            component.setState({
                favorite: fav
            });
        }, function(error) {
            console.log(error);
        });
    },

    toggleFavorite: function() {

        var component = this;
        if (this.state.favorite) {
            // already favorited, lets unfavorite
            this.props.cardApi.unfavorite({
                'cardId': component.props.cardId
            }, function(result) {
                component.setState({
                    favorite: false
                });
            }, function(error) {
                console.log(error);
            });
        } else {
            // currently not favorited, lets favorite
            this.props.cardApi.favorite({
                'cardId': component.props.cardId
            }, function(result) {
                component.setState({
                    favorite: true
                });
            }, function(error) {
                console.log(error);
            });
        }
    },

    render: function() {
        var fillColor = (this.state.favorite) ? 'text-gold' : 'text-grey-1';

        return (
            <a className="mx1 text-grey-4 text-gold-hover transition-color" href="#" onClick={this.toggleFavorite}>
                <Icon name="star" width="18px" height="18px"></Icon>
            </a>
        );
    }
});
<commit_msg>correctly color card favorite button on query builder.<commit_after>'use strict';

import Icon from './icon.react';

var cx = React.addons.classSet;

export default React.createClass({
    displayName: 'CardFavoriteButton',
    propTypes: {
        cardApi: React.PropTypes.func.isRequired,
        cardId: React.PropTypes.number.isRequired
    },

    getInitialState: function() {
        return {
            favorite: false
        };
    },

    componentDidMount: function() {
        this.loadFavoriteStatus();
    },

    componentWillReceiveProps: function(newProps) {
        this.loadFavoriteStatus();
    },

    loadFavoriteStatus: function() {
        var component = this;

        // initialize the current favorite status
        this.props.cardApi.isfavorite({
            'cardId': component.props.cardId
        }, function(result) {
            var fav = false;
            if (result.favorite === true) {
                fav = true;
            }

            component.setState({
                favorite: fav
            });
        }, function(error) {
            console.log(error);
        });
    },

    toggleFavorite: function() {

        var component = this;
        if (this.state.favorite) {
            // already favorited, lets unfavorite
            this.props.cardApi.unfavorite({
                'cardId': component.props.cardId
            }, function(result) {
                component.setState({
                    favorite: false
                });
            }, function(error) {
                console.log(error);
            });
        } else {
            // currently not favorited, lets favorite
            this.props.cardApi.favorite({
                'cardId': component.props.cardId
            }, function(result) {
                component.setState({
                    favorite: true
                });
            }, function(error) {
                console.log(error);
            });
        }
    },

    render: function() {
        var iconClasses = cx({
            'mx1': true,
            'transition-color': true,
            'text-grey-3': !this.state.favorite,
            'text-gold': this.state.favorite
        });

        return (
            <a className={iconClasses} href="#" onClick={this.toggleFavorite}>
                <Icon name="star" width="18px" height="18px"></Icon>
            </a>
        );
    }
});

{'fraction_non_alphanumeric': 0.11899166844691306, 'fraction_numerical': 0.0027771843623157445, 'mean_word_length': 1.4970666666666668, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2145593', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1198, 'n_words': 234}