<commit_before>import { centerItem } from '../modules/centerItem'

export const createLoginModule = (m, pubsub, connect, settings) => {
    const connecting = m.prop(false)
    const show = m.prop(true)
    const errorMsg = m.prop('')
    const loginInfo = {
        password: m.prop(''),
    }
    let conn

    const selectConn = c => {
        conn = c
    }

    const clone = obj => {
        return Object.keys(obj).reduce((newObj, key) => {
            newObj[key] = obj[key]
            return newObj
        }, {})
    }

    const login = () => {
        m.startComputation()
        errorMsg('')
        connecting(true)
        m.endComputation()
        const config: any = clone(conn.properties || {})
        config.host = conn.host
        config.user = conn.user
        config.password = <PASSWORD>()

        // Connect
        connect(config, conn)
            .then(connection => {
                m.startComputation()
                pubsub.emit('connected', connection)
                show(false)
                m.endComputation()
                pubsub.once('disconnect', () => {
                    connection.close()
                    show(true)
                    resetConn()
                })
            })
            .fail(err => {
                console.log('connection failure')
                m.startComputation()
                errorMsg(err.message)
                m.endComputation()
            })
            .then(() => {
                m.startComputation()
                connecting(false)
                m.endComputation()
            })
    }

    pubsub.on('data-error', err => {
        if (err.message.indexOf('The connection does not exist') > 0) {
            pubsub.emit('reconnecting')
            login()
        }
    })

    pubsub.on('login', () => show(true))

    pubsub.on('connected', () => show(false))

    const resetConn = () => {
        conn = undefined
        document.body.style.setProperty('--login-pos', '0px')
        const el = document.querySelector('.login-item') as HTMLElement
        if (el) {
            setTimeout(() => el.focus(), 1)
        }
    }

    const loginOnEnter = e => {
        if (e.keyCode === 13) {
            login()
        } else if (e.keyCode === 27) {
            resetConn()
        }
    }

    return {
        controller() {
            // controller
        },
        view() {
            return m(
                'div',
                {<commit_msg>clear password on login success<commit_after>import { centerItem } from '../modules/centerItem'

export const createLoginModule = (m, pubsub, connect, settings) => {
    const connecting = m.prop(false)
    const show = m.prop(true)
    const errorMsg = m.prop('')
    const loginInfo = {
        password: m.prop(''),
    }
    let conn

    const selectConn = c => {
        conn = c
    }

    const clone = obj => {
        return Object.keys(obj).reduce((newObj, key) => {
            newObj[key] = obj[key]
            return newObj
        }, {})
    }

    const login = () => {
        m.startComputation()
        errorMsg('')
        connecting(true)
        m.endComputation()
        const config: any = clone(conn.properties || {})
        config.host = conn.host
        config.user = conn.user
        config.password = loginInfo.password()

        // Connect
        connect(config, conn)
            .then(connection => {
                m.startComputation()
                pubsub.emit('connected', connection)
                show(false)
                loginInfo.password('')
                m.endComputation()
                pubsub.once('disconnect', () => {
                    connection.close()
                    show(true)
                    resetConn()
                })
            })
            .fail(err => {
                console.log('connection failure')
                m.startComputation()
                errorMsg(err.message)
                m.endComputation()
            })
            .then(() => {
                m.startComputation()
                connecting(false)
                m.endComputation()
            })
    }

    pubsub.on('data-error', err => {
        if (err.message.indexOf('The connection does not exist') > 0) {
            pubsub.emit('reconnecting')
            login()
        }
    })

    pubsub.on('login', () => show(true))

    pubsub.on('connected', () => show(false))

    const resetConn = () => {
        conn = undefined
        loginInfo.password('')
        document.body.style.setProperty('--login-pos', '0px')
        const el = document.querySelector('.login-item') as HTMLElement
        if (el) {
            setTimeout(() => el.focus(), 1)
        }
    }

    const loginOnEnter = e => {
        if (e.keyCode === 13) {
            login()
        } else if (e.keyCode === 27) {
            resetConn()
        }
    }

    return {
        controller() {
            // controller
        },
        view() {
            return m(
                'div',
                {
{'fraction_non_alphanumeric': 0.1352263701350278, 'fraction_numerical': 0.0027799841143764893, 'mean_word_length': 1.3362708719851577, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 36, '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': '4780015', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1345, 'n_words': 266}