<commit_before>/**
 * BikeshedBuilderActions
 * @flow
 */
import BikeshedBuilderConstants from '../constants/BikeshedBuilderConstants'
import { createBikeshed } from '../utils/BikeshedApiUtils'
import browserImageSize from 'browser-image-size'
const { FormData, FileList, File } = global

/**
 * Reset bikeshed builder
 */
export function reset () {
  return {
    type: BikeshedBuilderConstants.RESET
  }
}

/**
 * Update bikeshed builder input
 */
export function inputChange (input: { value: string; name: string; }) {
  const { value, name } = input
  return {
    type: BikeshedBuilderConstants.INPUT_CHANGE,
    payload: { value, name }
  }
}

/**
 * Submit bikeshed builder form
 */
export function submit () {
  return async ({ dispatch, getState, fetcher }) => {
    const { bikeshedBuilder } = getState()
    dispatch({ type: BikeshedBuilderConstants.SUBMIT_START })
    try {
      const body = getRequestBody(bikeshedBuilder)
      const response = await fetcher.executeRequest(createBikeshed, { body })
      if (response.ok) {
        const bikeshed = await response.json()
        dispatch({ type: BikeshedBuilderConstants.SUBMIT_SUCCESS, payload: { bikeshed } })
      } else {
        // @TODO: do something on failure
      }
    } finally {
      dispatch({ type: BikeshedBuilderConstants.SUBMIT_FINISH })
    }
  }

  function getRequestBody (bikeshedBuilder) {
    const images = bikeshedBuilder.get('images').toList()
    const form = images.reduce((form, image, idx) => {
      const { file, name } = image
      form.append(`file${idx}`, file, name)
      return form
    }, new FormData())

    const description = bikeshedBuilder.get('description')
    form.append('description', description)

    return form
  }
}

/**
 * Add images to bikeshed builder
 */
export function addImages (imageList: FileList) {

  return async ({ dispatch }) => {<commit_msg>Access bikeshed builder properties directly<commit_after>/**
 * BikeshedBuilderActions
 * @flow
 */
import BikeshedBuilderConstants from '../constants/BikeshedBuilderConstants'
import { createBikeshed } from '../utils/BikeshedApiUtils'
import browserImageSize from 'browser-image-size'
const { FormData, FileList, File } = global

/**
 * Reset bikeshed builder
 */
export function reset () {
  return {
    type: BikeshedBuilderConstants.RESET
  }
}

/**
 * Update bikeshed builder input
 */
export function inputChange (input: { value: string; name: string; }) {
  const { value, name } = input
  return {
    type: BikeshedBuilderConstants.INPUT_CHANGE,
    payload: { value, name }
  }
}

/**
 * Submit bikeshed builder form
 */
export function submit () {
  return async ({ dispatch, getState, fetcher }) => {
    const { bikeshedBuilder } = getState()
    dispatch({ type: BikeshedBuilderConstants.SUBMIT_START })
    try {
      const body = getRequestBody(bikeshedBuilder)
      const response = await fetcher.executeRequest(createBikeshed, { body })
      if (response.ok) {
        const bikeshed = await response.json()
        dispatch({ type: BikeshedBuilderConstants.SUBMIT_SUCCESS, payload: { bikeshed } })
      } else {
        // @TODO: do something on failure
      }
    } finally {
      dispatch({ type: BikeshedBuilderConstants.SUBMIT_FINISH })
    }
  }

  function getRequestBody (bikeshedBuilder) {
    const images = bikeshedBuilder.images.toList()
    const form = images.reduce((form, image, idx) => {
      const { file, name } = image
      form.append(`file${idx}`, file, name)
      return form
    }, new FormData())

    form.append('description', bikeshedBuilder.description)

    return form
  }
}

/**
 * Add images to bikeshed builder
 */
export function addImages (imageList: FileList) {

  return async ({ dispatch }) => {
{'fraction_non_alphanumeric': 0.11778846153846154, 'fraction_numerical': 0.0, 'mean_word_length': 3.359720605355064, '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': '4028595', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1074, 'n_words': 283}