<commit_before>const { normalize, arrayOf } = require('normalizr')
const budgetItem = require('js/redux/schemas/budgetItem')

const { setListedItemIds } = require('js/redux/ducks/explore')
const { mergeBudgetItems } = require('js/redux/ducks/budgetItems')
const { getLocale } = require('js/redux/ducks/locale')
const { addError } = require('js/redux/ducks/errors')

const { getSelectedBudgetItemType } = require('js/redux/ducks/filters')

const georgianBudgetAPI = require('js/services/georgianBudgetAPI')

const fetchListedBudgetItems = () => (dispatch, getState) => {
  const state = getState()

  const locale = getLocale(state)
  const budgetItemType = getSelectedBudgetItemType(state)

  const requiredState = [locale, budgetItemType]

  for (let i = 0; i < requiredState.length; i++) {
    if (requiredState[i].length === 0) return
  }

  dispatch(setListedItemIds([]))

  georgianBudgetAPI.get(locale, 'v1', {
    params: {
      budgetItemFields: 'id,name',

      filters: {
        budgetItemType: budgetItemType
      }
    }
  }).then((response) => {
    if (!response || !response.data || typeof response.data !== 'object') return

    response.data.errors.forEach((error) => {
      dispatch(addError(error.text))
    })

    const normalized = normalize(response.data, {
      budgetItems: arrayOf(budgetItem)
    })

    const { budgetItems } = normalized.entities

    dispatch(mergeBudgetItems(budgetItems))
    dispatch(setListedItemIds(Object.keys(budgetItems)))
  })
}

module.exports = fetchListedBudgetItems<commit_msg>Marking budget item types as loaded in list when fetch is finished.<commit_after>const { normalize, arrayOf } = require('normalizr')
const budgetItem = require('js/redux/schemas/budgetItem')

const { setListedItemIds, markListLoaded } = require('js/redux/ducks/explore')
const { mergeBudgetItems } = require('js/redux/ducks/budgetItems')
const { getLocale } = require('js/redux/ducks/locale')
const { addError } = require('js/redux/ducks/errors')

const { getSelectedBudgetItemType } = require('js/redux/ducks/filters')

const georgianBudgetAPI = require('js/services/georgianBudgetAPI')

const fetchListedBudgetItems = () => (dispatch, getState) => {
  const state = getState()

  const locale = getLocale(state)
  const budgetItemType = getSelectedBudgetItemType(state)

  const requiredState = [locale, budgetItemType]

  for (let i = 0; i < requiredState.length; i++) {
    if (requiredState[i].length === 0) return
  }

  dispatch(setListedItemIds([]))

  georgianBudgetAPI.get(locale, 'v1', {
    params: {
      budgetItemFields: 'id,name,type',

      filters: {
        budgetItemType: budgetItemType
      }
    }
  }).then((response) => {
    if (!response || !response.data || typeof response.data !== 'object') return

    response.data.errors.forEach((error) => {
      dispatch(addError(error.text))
    })

    const normalized = normalize(response.data, {
      budgetItems: arrayOf(budgetItem)
    })

    const { budgetItems } = normalized.entities

    dispatch(mergeBudgetItems(budgetItems))
    dispatch(setListedItemIds(Object.keys(budgetItems)))
    dispatch(markListLoaded(budgetItemType))
  })
}

module.exports = fetchListedBudgetItems
{'fraction_non_alphanumeric': 0.13576779026217228, 'fraction_numerical': 0.0018726591760299626, 'mean_word_length': 4.350584307178631, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7048441', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1005, 'n_words': 180}