<commit_before>'use strict'

let r = require('r-dom')
let React = require('react')
let PropTypes = React.PropTypes
let Component = require('./component')
let mori = require('mori')

let AppActions = require('../actions/app-actions')

let InputRow = require('./forms').InputRow
let misc = require('./misc')

class LoginPage extends Component {
  render () {
    let state = this.props.state

    return (
      r.div({className: 'login_page'}, [
        r.div({className: 'login_form'}, [
          r.img({className: 'logo', src: 'static/images/bench-itch.png'}),
          r.div({className: 'login_box'}, [
            r(LoginForm, {
              page: mori.get(state, 'page'),
              login_state: mori.get(state, 'login'),
              setup_state: mori.get(state, 'setup')
            })
          ])
        ])
      ])
    )
  }
}

LoginPage.propTypes = {
  state: PropTypes.any
}

class LoginForm extends Component {
  constructor () {
    super()
    this.handle_submit = this.handle_submit.bind(this)
  }

  render () {
    let page = this.props.page
    let login_state = this.props.login_state
    let setup_state = this.props.setup_state

    // FIXME wouldn't all that imperative logic be very well suited
    // for a refactoring? why yes, yes it would. — A
    let loading = (
      page === 'login'
      ? mori.get(login_state, 'loading')
      : true
    )
    let errors = mori.get((
      page === 'login'
      ? login_state
      : setup_state
    ), 'errors')

    let icon = (
      page === 'login'
      ? 'heart-filled'
      : mori.get(setup_state, 'icon')
    )

    let message = (
      page === 'login'
      ? 'Contacting dovecote'
      : mori.get(setup_state, 'message')
    )

    return (
      r.form({classSet: {form: true, has_error: (icon === 'error')}, onSubmit: this.handle_submit}, [
        r(misc.ErrorList, {errors, before: r(misc.Icon, {icon: 'neutral'})}),

        r(InputRow, {name: 'username', type: 'text', ref: 'username', autofocus: true, disabled: loading}),
        r(InputRow, {name: 'password', type: 'password', ref: 'password', disabled: loading}),

        r.div({className: 'buttons'}, [
          (loading
          ? r.span({className: 'login_status'}, [r.span({className: `icon icon-${icon} small_throbber_loader`}), message])
          : r.button({className: 'button'}, 'Up, up, and away!')),
          r.div({className: 'login_links'}, [
            r.a({href: 'https://itch.io/register', target: '_blank'}, 'register'),
            r.span(' · '),
            r.a({href: 'https://itch.io/user/forgot-password', target: '_blank'}, 'forgot password')
          ])
        ])
      ])
    )
  }

  handle_submit (event) {
    event.preventDefault()

    let username = this.refs.username
    let password = this.refs.password
    AppActions.login_with_password(username.value(), password.value())
  }
}

LoginForm.propTypes = {
  state: PropTypes.any
}

module.exports = {LoginPage, LoginForm}<commit_msg>And so humor dies, not with a pull request, but with a commit. Closes #213<commit_after>'use strict'

let r = require('r-dom')
let React = require('react')
let PropTypes = React.PropTypes
let Component = require('./component')
let mori = require('mori')

let AppActions = require('../actions/app-actions')

let InputRow = require('./forms').InputRow
let misc = require('./misc')

class LoginPage extends Component {
  render () {
    let state = this.props.state

    return (
      r.div({className: 'login_page'}, [
        r.div({className: 'login_form'}, [
          r.img({className: 'logo', src: 'static/images/bench-itch.png'}),
          r.div({className: 'login_box'}, [
            r(LoginForm, {
              page: mori.get(state, 'page'),
              login_state: mori.get(state, 'login'),
              setup_state: mori.get(state, 'setup')
            })
          ])
        ])
      ])
    )
  }
}

LoginPage.propTypes = {
  state: PropTypes.any
}

class LoginForm extends Component {
  constructor () {
    super()
    this.handle_submit = this.handle_submit.bind(this)
  }

  render () {
    let page = this.props.page
    let login_state = this.props.login_state
    let setup_state = this.props.setup_state

    // FIXME wouldn't all that imperative logic be very well suited
    // for a refactoring? why yes, yes it would. — A
    let loading = (
      page === 'login'
      ? mori.get(login_state, 'loading')
      : true
    )
    let errors = mori.get((
      page === 'login'
      ? login_state
      : setup_state
    ), 'errors')

    let icon = (
      page === 'login'
      ? 'heart-filled'
      : mori.get(setup_state, 'icon')
    )

    let message = (
      page === 'login'
      ? 'Contacting dovecote'
      : mori.get(setup_state, 'message')
    )

    return (
      r.form({classSet: {form: true, has_error: (icon === 'error')}, onSubmit: this.handle_submit}, [
        r(misc.ErrorList, {errors, before: r(misc.Icon, {icon: 'neutral'})}),

        r(InputRow, {name: 'username', type: 'text', ref: 'username', autofocus: true, disabled: loading}),
        r(InputRow, {name: 'password', type: 'password', ref: 'password', disabled: loading}),

        r.div({className: 'buttons'}, [
          (loading
          ? r.span({className: 'login_status'}, [r.span({className: `icon icon-${icon} small_throbber_loader`}), message])
          : r.button({className: 'button'}, 'Log in')),
          r.div({className: 'login_links'}, [
            r.a({href: 'https://itch.io/register', target: '_blank'}, 'register'),
            r.span(' · '),
            r.a({href: 'https://itch.io/user/forgot-password', target: '_blank'}, 'forgot password')
          ])
        ])
      ])
    )
  }

  handle_submit (event) {
    event.preventDefault()

    let username = this.refs.username
    let password = this.refs.password
    AppActions.login_with_password(username.value(), password.value())
  }
}

LoginForm.propTypes = {
  state: PropTypes.any
}

module.exports = {LoginPage, LoginForm}
{'fraction_non_alphanumeric': 0.16272485009993337, 'fraction_numerical': 0.0004996668887408394, 'mean_word_length': 2.5365135453474674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2846753', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1881, 'n_words': 429}