{"size": 1220, "ext": "js", "max_stars_repo_path": "quizzer-client/src/actions/async/startRoundAction.js", "max_stars_repo_name": "ysbakker/Quizzer-WS", "max_stars_repo_stars_event_min_datetime": "2020-02-17T16:11:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-03T11:38:48.000Z", "max_issues_repo_path": "quizzer-client/src/actions/async/startRoundAction.js", "max_issues_repo_name": "ysbakker/Quizzer-WS", "max_issues_repo_issues_event_min_datetime": "2020-09-19T20:38:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-03T11:43:03.000Z", "max_forks_repo_path": "quizzer-client/src/actions/async/startRoundAction.js", "max_forks_repo_name": "ysbakker/Quizzer-WS", "max_forks_repo_forks_event_min_datetime": "2020-06-07T07:57:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-02T20:34:08.000Z"}
{"max_stars_count": 6, "max_issues_count": 8, "max_forks_count": 2, "avg_line_length": 39.3548387097, "max_line_length": 111, "alphanum_fraction": 0.6540983607}
import * as fetchState from '../fetchStateActions'
import * as quizState from '../quizStateActions'

import fetchCategories from './fetchCategoriesAction'
import defaultFetch from './defaultFetch'

import { history } from '../../containers/quizzer'

export default function startRoundAction() {
  return (dispatch, getState) => {
    dispatch(fetchState.updateFetchAction({ fetching: true, result: null, message: null }))

    defaultFetch(`/rooms/${getState().appState.currentRoomNumber}/round`, 'PUT')
      .then(r => {
        const { APIerr, data } = r
        if (APIerr) {
          const { error } = data
          dispatch(fetchState.updateFetchAction({ fetching: false, result: 'error', message: error }))
        } else {
          dispatch(fetchState.updateFetchAction({ fetching: false, result: 'success', message: data.success }))
          dispatch(quizState.setRoundAction(getState().quizState.round + 1))
          dispatch(quizState.setQuestionNrAction(0))
          dispatch(fetchCategories())
          history.push('/quizmaster/pickcategories')
        }
      })
      .catch(err => {
        dispatch(fetchState.updateFetchAction({ fetching: false, result: 'error', message: err }))
      })
  }
}