<commit_before>import _ from 'lodash'
import React, {PropTypes} from 'react'
import path from 'path'
import URL from 'url'
import qs from 'querystring'
import {remote} from 'electron'

const appPath = remote.app.getAppPath()
const buildUrl = (filepath, query) => {
    return URL.format({
        protocol: 'file',
        host: '',
        pathname: `${path.join(appPath, '/renderer/', filepath)}`,
        query: query ? {query: JSON.stringify(query)} : null,
    })
}

export default class WindowComponent extends React.Component
{
    static propTypes = {
        // children: PropTypes.element.isRequired,
        show: PropTypes.bool.isRequired,
        url: PropTypes.string.isRequired,
        width: PropTypes.number,
        height: PropTypes.number,
        query: PropTypes.object,
        onHide: PropTypes.func,
        onResposnse: PropTypes.func,
    }

    static defaultProps = {
        show: false,
        url: 'about:blank',
    }

    constructor(...args)
    {
        super(...args)

        this.window = new remote.BrowserWindow({
            parent: remote.getCurrentWindow(),
            modal: true,
            show: this.props.show,
            frame: true,
            // minimizable: false,
            // maximizable: false,
            resizable: false,
            // useContentSize: true,
            width: this.props.width,
            height: this.props.height,
        })

        this.state = {
            previousQuery: this.props.query,
        }

        this.window.on('hide', e => {
            this.props.onHide()
        })

        this.window.webContents.on('will-navigate', (e, url) => {
            const res = qs.parse(URL.parse(url).query)
            this.props.onResponse && this.props.onResponse(res)
            e.preventDefault()
        })

        this.window.loadURL(buildUrl(this.props.url, this.props.query))
    }

    componentDidMount()
    {
    }

    shouldComponentUpdate(nextProps, nextState)
    {
        if (this.props.url !== nextProps.url || this.props.query !== nextProps.query) return true
        return false<commit_msg>fix modal-window can't open<commit_after>import _ from 'lodash'
import React, {PropTypes} from 'react'
import path from 'path'
import URL from 'url'
import qs from 'querystring'
import {remote} from 'electron'

const appPath = remote.app.getAppPath()
const buildUrl = (filepath, query) => {
    return URL.format({
        protocol: 'file',
        host: '',
        pathname: `${path.join(appPath, '/renderer/', filepath)}`,
        query: query ? {query: JSON.stringify(query)} : null,
    })
}

export default class WindowComponent extends React.Component
{
    static propTypes = {
        // children: PropTypes.element.isRequired,
        show: PropTypes.bool.isRequired,
        url: PropTypes.string.isRequired,
        width: PropTypes.number,
        height: PropTypes.number,
        query: PropTypes.object,
        onHide: PropTypes.func,
        onResposnse: PropTypes.func,
    }

    static defaultProps = {
        show: false,
        url: 'about:blank',
    }

    constructor(...args)
    {
        super(...args)

        this.window = new remote.BrowserWindow({
            parent: remote.getCurrentWindow(),
            modal: true,
            show: this.props.show,
            frame: true,
            // minimizable: false,
            // maximizable: false,
            resizable: false,
            // useContentSize: true,
            width: this.props.width,
            height: this.props.height,
        })

        this.state = {
            previousQuery: this.props.query,
        }

        this.window.on('hide', e => {
            this.props.onHide()
        })

        this.window.webContents.on('will-navigate', (e, url) => {
            const res = qs.parse(URL.parse(url).query)
            this.props.onResponse && this.props.onResponse(res)
            e.preventDefault()
        })

        this.window.loadURL(buildUrl(this.props.url, this.props.query))
    }

    componentDidMount()
    {
    }

    shouldComponentUpdate(nextProps, nextState)
    {
        return this.props.url !== nextProps.url
            || this.props.query !== nextProps.query
            || this.props.show !== nextProps.show
    }

    componentWillUpdate(nextProps, nextState)
    {
        if (this.props.show !== nextProps.show) {
            nextProps.show ? this.window.show() : this.window.hide()
        }
{'fraction_non_alphanumeric': 0.12609772573744651, 'fraction_numerical': 0.0, 'mean_word_length': 1.9932614555256065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3744666', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1276, 'n_words': 266}