<commit_before>import React, { Component } from 'react'
import { Redirect } from 'react-router-dom'
import generateRandomKeys from 'peerpad-core/src/backend/keys/generate'
import generateRandomName from 'peerpad-core/src/backend/keys/generate-random-name'

/*
 * "Children as fn" style container, to create and redirect to a new docuement.
 * Used by `CreateDocument` and `StartButton`
 */
export default class CreateDocumentContainer extends Component {
  constructor (props) {
    super(props)
    this.state = {
      type: 'markdown',
      name: ''
    }
    this.onNameChange = this.onNameChange.bind(this)
    this.onTypeChange = this.onTypeChange.bind(this)
    this.onCreateDocument = this.onCreateDocument.bind(this)
  }

  render () {
    if (this.state.redirect) {
      const redir = this.state.redirect
      this.setState({ redirect: null })
      return (<Redirect to={redir} push />)
    }

    return this.props.children({
      ...this.state,
      onNameChange: this.onNameChange,
      onTypeChange: this.onTypeChange,
      onCreateDocument: this.onCreateDocument
    })
  }

  onNameChange (name) {
    this.setState({name})
  }

  onTypeChange (type) {
    this.setState({type})
  }

  async onCreateDocument () {
    const type = encodeURIComponent(this.state.type || 'markdown')
    const name = encodeURIComponent(this.state.name || generateRandomName())
    const keys = await generateRandomKeys()
    const url = '/w/' + type + '/' + name + '/' + keys.read + '/' + keys.write
    this.setState({redirect: url})
  }
}<commit_msg>homepage create buttons: some dependencies only load on demand<commit_after>import React, { Component } from 'react'
import { Redirect } from 'react-router-dom'

/*
 * "Children as fn" style container, to create and redirect to a new docuement.
 * Used by `CreateDocument` and `StartButton`
 */
export default class CreateDocumentContainer extends Component {
  constructor (props) {
    super(props)
    this.state = {
      type: 'markdown',
      name: ''
    }
    this.onNameChange = this.onNameChange.bind(this)
    this.onTypeChange = this.onTypeChange.bind(this)
    this.onCreateDocument = this.onCreateDocument.bind(this)
  }

  render () {
    if (this.state.redirect) {
      const redir = this.state.redirect
      this.setState({ redirect: null })
      return (<Redirect to={redir} push />)
    }

    return this.props.children({
      ...this.state,
      onNameChange: this.onNameChange,
      onTypeChange: this.onTypeChange,
      onCreateDocument: this.onCreateDocument
    })
  }

  onNameChange (name) {
    this.setState({name})
  }

  onTypeChange (type) {
    this.setState({type})
  }

  async onCreateDocument () {
    const generateRandomKeys = await import('peerpad-core/src/backend/keys/generate')
    const generateRandomName = await import('peerpad-core/src/backend/keys/generate-random-name')
    const type = encodeURIComponent(this.state.type || 'markdown')
    const name = encodeURIComponent(this.state.name || generateRandomName())
    const keys = await generateRandomKeys()
    const url = '/w/' + type + '/' + name + '/' + keys.read + '/' + keys.write
    this.setState({redirect: url})
  }
}
{'fraction_non_alphanumeric': 0.12691946098401755, 'fraction_numerical': 0.0, 'mean_word_length': 3.2960969044414536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '817106', 'n_tokens_mistral': 965, 'n_tokens_neox': 961, 'n_words': 218}