<commit_before>/**
 * BikeshedCreator
 * @flow
 */
import { CreateBikeshedMutation } from '@client/mutations/CreateBikeshedMutation'
import { createObjectURL, revokeObjectURL } from '@client/lib/URL'
import { Card, CardActions, CardBody } from '@components/Card'
import { getBikeshedViewerPath } from '@client/lib/RouteUtils'
import type { SyntheticEvent, ReactElement } from 'react'
import React, { Component, PropTypes } from 'react'
import { TextInput } from '@components/TextInput'
import { Icon, ICONS } from '@components/Icon'
import { Button } from '@components/Button'
import { Subhead } from '@components/Text'
import cn from './BikeshedCreator.css'
import Relay from 'react-relay'

const MAXIMUM_IMAGE_COUNT = 8

/**
 * BikeshedCreator page
 */
export class BikeshedCreator extends Component {
  constructor (props: Object) {
    super(props)
    this.state = {
      // Form
      description: '',
      files: [],

      // UI state
      saving: false
    }
    this._handleInput = this._handleInput.bind(this)
    this._handleFiles = this._handleFiles.bind(this)
    this._handleSubmit = this._handleSubmit.bind(this)
    this._addFileClick = this._addFileClick.bind(this)
    this._setSaving = this._setSaving.bind(this)
  }

  /**
   * Upload the files and create your bikeshed
   * If we're succesful we want to navigate to the new bikeshed
   * @TODO: Add toast message on failure
   */
  _handleSubmit () {
    const { _setSaving } = this
    const { viewer, history } = this.props
    const { description, files } = this.state

    _setSaving(true)
    Relay.Store.update(new CreateBikeshedMutation({ viewer, description, files }), {
      onFailure (transaction) {
        _setSaving(false)
        // console.log('transaction', transaction)
      },
      onSuccess ({ createBikeshed }) {
        _setSaving(false)

        // Navigate to the newly created bikeshed's page
        const bikeshedId = createBikeshed.bikeshedEdge.cursor
        history.pushState({}, getBikeshedViewerPath(bikeshedId))
      }
    })
  }

  _setSaving (saving: boolean) {
    this.setState({ saving })
  }

  _handleInput (e: SyntheticEvent) {
    const description = e.target.value
    this.setState({ description })
  }

  // @TODO: Consider adding a toast message for duplicate images
  _handleFiles (e: SyntheticEvent) {
    const { files } = this.state
    const remainingSpaces = MAXIMUM_IMAGE_COUNT - files.length<commit_msg>Revert to using node.id after creating bikeshed<commit_after>/**
 * BikeshedCreator
 * @flow
 */
import { CreateBikeshedMutation } from '@client/mutations/CreateBikeshedMutation'
import { createObjectURL, revokeObjectURL } from '@client/lib/URL'
import { Card, CardActions, CardBody } from '@components/Card'
import { getBikeshedViewerPath } from '@client/lib/RouteUtils'
import type { SyntheticEvent, ReactElement } from 'react'
import React, { Component, PropTypes } from 'react'
import { TextInput } from '@components/TextInput'
import { Icon, ICONS } from '@components/Icon'
import { Button } from '@components/Button'
import { Subhead } from '@components/Text'
import cn from './BikeshedCreator.css'
import Relay from 'react-relay'

const MAXIMUM_IMAGE_COUNT = 8

/**
 * BikeshedCreator page
 */
export class BikeshedCreator extends Component {
  constructor (props: Object) {
    super(props)
    this.state = {
      // Form
      description: '',
      files: [],

      // UI state
      saving: false
    }
    this._handleInput = this._handleInput.bind(this)
    this._handleFiles = this._handleFiles.bind(this)
    this._handleSubmit = this._handleSubmit.bind(this)
    this._addFileClick = this._addFileClick.bind(this)
    this._setSaving = this._setSaving.bind(this)
  }

  /**
   * Upload the files and create your bikeshed
   * If we're succesful we want to navigate to the new bikeshed
   * @TODO: Add toast message on failure
   */
  _handleSubmit () {
    const { _setSaving } = this
    const { viewer, history } = this.props
    const { description, files } = this.state

    _setSaving(true)
    Relay.Store.update(new CreateBikeshedMutation({ viewer, description, files }), {
      onFailure (transaction) {
        _setSaving(false)
        // console.log('transaction', transaction)
      },
      onSuccess ({ createBikeshed }) {
        _setSaving(false)

        // Navigate to the newly created bikeshed's page
        const bikeshedId = createBikeshed.bikeshedEdge.node.id
        history.pushState({}, getBikeshedViewerPath(bikeshedId))
      }
    })
  }

  _setSaving (saving: boolean) {
    this.setState({ saving })
  }

  _handleInput (e: SyntheticEvent) {
    const description = e.target.value
    this.setState({ description })
  }

  // @TODO: Consider adding a toast message for duplicate images
  _handleFiles (e: SyntheticEvent) {
    const { files } = this.state
    const remainingSpaces = MAXIMUM_IMAGE_COUNT - files.length
{'fraction_non_alphanumeric': 0.10846075433231396, 'fraction_numerical': 0.00040774719673802244, 'mean_word_length': 3.3686553873552985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4765090', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1475, 'n_words': 375}