<commit_before>import React from 'react';
import PropTypes from 'prop-types';

export default class AutoRefreshTimer extends React.Component {
    static propTypes = {
        fontSizeScale: PropTypes.number,
        fontColor: PropTypes.string,
        textAlign: PropTypes.string,
        getState: PropTypes.func,
        onDoubleClick: PropTypes.func,
    };

    static getTimerStyles(fontSizeScale, fontColor) {
        let timeFontSize = 64;
        let fractionFontSize = 36;
        if (fontSizeScale && !fontSizeScale.isNaN && fontSizeScale > 0) {
            timeFontSize *= fontSizeScale;
            fractionFontSize *= fontSizeScale;
        }
        const color = `#${fontColor || 'ea7500'}`;
        const timeStyle = { fontSize: `${timeFontSize}pt`, color };
        const fractionStyle = { fontSize: `${fractionFontSize}pt`, color };
        return { timeStyle, fractionStyle }
    }

    constructor(props) {
        super(props);

        let justifyContent = 'center';
        if (this.props.textAlign === 'left') {
            justifyContent = 'flex-start';
        } else if (this.props.textAlign === 'right') {
            justifyContent = 'flex-end';
        }

        this.state = {
            timerTime: '',
            timerFraction: '',
            ...AutoRefreshTimer.getTimerStyles(
                this.props.fontSizeScale, this.props.fontColor),
            justifyContent,
        };

        this.runUpdate = this.runUpdate.bind(this);
    }

    componentWillReceiveProps(nextProps) {
        this.setState({
            ...AutoRefreshTimer.getTimerStyles(
                nextProps.fontSizeScale, nextProps.fontColor),
        })
    }

    componentWillMount() {
        this.runUpdate();
    }

    updateTimer() {
        const timerState = this.props.getState();
        this.setState({
            timerTime: timerState.time,
            timerFraction: timerState.fraction,
        });
    }

    runUpdate() {
        this.updateTimer();
        requestAnimationFrame(this.runUpdate);
    }

    render() {
        const { timeStyle, timerTime, fractionStyle, timerFraction, justifyContent } = this.state;
        return (
            <div className="container-timer" style={{ justifyContent }} onDoubleClick={this.props.onDoubleClick}>
                <div>
                    <span className="timer-time" style={timeStyle}>{timerTime}</span>
                    <span className="timer-fraction" style={fractionStyle}>{timerFraction}</span>
                </div>
            </div>
        );
    }
}<commit_msg>Fix textAlign on other browsers<commit_after>import React from 'react';
import PropTypes from 'prop-types';

export default class AutoRefreshTimer extends React.Component {
    static propTypes = {
        fontSizeScale: PropTypes.number,
        fontColor: PropTypes.string,
        textAlign: PropTypes.string,
        getState: PropTypes.func,
        onDoubleClick: PropTypes.func,
    };

    static getTimerStyles(fontSizeScale, fontColor) {
        let timeFontSize = 64;
        let fractionFontSize = 36;
        if (fontSizeScale && !fontSizeScale.isNaN && fontSizeScale > 0) {
            timeFontSize *= fontSizeScale;
            fractionFontSize *= fontSizeScale;
        }
        const color = `#${fontColor || 'ea7500'}`;
        const timeStyle = { fontSize: `${timeFontSize}pt`, color };
        const fractionStyle = { fontSize: `${fractionFontSize}pt`, color };
        return { timeStyle, fractionStyle }
    }

    constructor(props) {
        super(props);

        this.state = {
            timerTime: '',
            timerFraction: '',
            ...AutoRefreshTimer.getTimerStyles(
                this.props.fontSizeScale, this.props.fontColor),
            timerContainerStyle: this.timerContainerStyle,
        };

        this.runUpdate = this.runUpdate.bind(this);
    }

    componentWillReceiveProps(nextProps) {
        this.setState({
            ...AutoRefreshTimer.getTimerStyles(
                nextProps.fontSizeScale, nextProps.fontColor),
        })
    }

    componentWillMount() {
        this.runUpdate();
    }

    get timerContainerStyle() {
        let justifyContent = 'center';
        if (this.props.textAlign === 'left') {
            justifyContent = 'flex-start';
        } else if (this.props.textAlign === 'right') {
            justifyContent = 'flex-end';
        }
        const margin = justifyContent === 'center' ? 'auto' : 0;
        return { justifyContent, marginLeft: margin, marginRight: margin };
    }

    updateTimer() {
        const timerState = this.props.getState();
        this.setState({
            timerTime: timerState.time,
            timerFraction: timerState.fraction,
        });
    }

    runUpdate() {
        this.updateTimer();
        requestAnimationFrame(this.runUpdate);
    }

    render() {
        const { timeStyle, timerTime, fractionStyle, timerFraction, timerContainerStyle } = this.state;
        return (
            <div
                className="container-timer"
                style={timerContainerStyle}
                onDoubleClick={this.props.onDoubleClick}>
                <div>
                    <span className="timer-time" style={timeStyle}>{timerTime}</span>
                    <span className="timer-fraction" style={fractionStyle}>{timerFraction}</span>
                </div>
            </div>
        );
    }
}
{'fraction_non_alphanumeric': 0.115099925980755, 'fraction_numerical': 0.003515914137675796, 'mean_word_length': 2.0692788188529243, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '6239086', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1427, 'n_words': 274}