<commit_before>import { createAction } from 'redux-actions'
import keyMirror from 'keymirror'
import { browserHistory } from 'react-router'
import { createUrl, metaGenerator } from 'utils'
import { GET, PATCH } from 'utils/api'

const actions = keyMirror({
    REQUEST_OWN_PLAYER: null,
    RECEIVE_OWN_PLAYER: null,
    REQUEST_SUBMIT_PROFILE: null,
    RECEIVE_SUBMIT_PROFILE: null,
    DISMISS_CHANGES_SAVED: null
})
export default actions

export const requestOwnPlayer = () => (dispatch, getState) => {
    dispatch(createAction(actions.REQUEST_OWN_PLAYER)())
    return GET(createUrl('/api/players/me/'), getState().auth.authToken).then(
        response => response.json().then(json => {
            const payload = response.ok ? json : new Error('Error retrieving own player.')
            return dispatch(createAction(actions.RECEIVE_OWN_PLAYER, null, metaGenerator)(payload))
        })
    )
}

export const requestOwnPlayerIfNeeded = () => (dispatch, getState) => {
    const { isLoading, lastUpdated } = getState().player
    if (!isLoading && !lastUpdated) {
        return dispatch(requestOwnPlayer())
    }
}

export const submitProfile = data => (dispatch, getState) => {
    dispatch(createAction(actions.REQUEST_SUBMIT_PROFILE)())
    const { auth: { authToken }, player: { player: { id } } } = getState()
    if (id && authToken) {
        return PATCH(createUrl(`/api/players/${id}/`), authToken, data).then(
            response => response.json().then(json => {
                const payload = response.ok ? json : new Error('Error submitting profile.')
                dispatch(createAction(actions.RECEIVE_SUBMIT_PROFILE, null, metaGenerator)(payload))
                return ({ response, json })
            })
        )
    }
}

export const dismissChangesSaved = createAction(actions.DISMISS_CHANGES_SAVED)<commit_msg>Reload player from server after submitting profile<commit_after>import { createAction } from 'redux-actions'
import keyMirror from 'keymirror'
import { browserHistory } from 'react-router'
import { createUrl, metaGenerator } from 'utils'
import { GET, PATCH } from 'utils/api'

const actions = keyMirror({
    REQUEST_OWN_PLAYER: null,
    RECEIVE_OWN_PLAYER: null,
    REQUEST_SUBMIT_PROFILE: null,
    RECEIVE_SUBMIT_PROFILE: null,
    DISMISS_CHANGES_SAVED: null
})
export default actions

export const requestOwnPlayer = () => (dispatch, getState) => {
    dispatch(createAction(actions.REQUEST_OWN_PLAYER)())
    return GET(createUrl('/api/players/me/'), getState().auth.authToken).then(
        response => response.json().then(json => {
            const payload = response.ok ? json : new Error('Error retrieving own player.')
            return dispatch(createAction(actions.RECEIVE_OWN_PLAYER, null, metaGenerator)(payload))
        })
    )
}

export const requestOwnPlayerIfNeeded = () => (dispatch, getState) => {
    const { isLoading, lastUpdated } = getState().player
    if (!isLoading && !lastUpdated) {
        return dispatch(requestOwnPlayer())
    }
}

export const submitProfile = data => (dispatch, getState) => {
    dispatch(createAction(actions.REQUEST_SUBMIT_PROFILE)())
    const { auth: { authToken }, player: { player: { id } } } = getState()
    if (id && authToken) {
        return PATCH(createUrl(`/api/players/${id}/`), authToken, data).then(
            response => response.json().then(json => {
                const payload = response.ok ? json : new Error('Error submitting profile.')
                if (response.ok) {
                    dispatch(requestOwnPlayer())
                }
                dispatch(createAction(actions.RECEIVE_SUBMIT_PROFILE, null, metaGenerator)(payload))
                return ({ response, json })
            })
        )
    }
}

export const dismissChangesSaved = createAction(actions.DISMISS_CHANGES_SAVED)
{'fraction_non_alphanumeric': 0.12398851474810754, 'fraction_numerical': 0.0, 'mean_word_length': 3.3299435028248587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6483796', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1106, 'n_words': 242}