<commit_before>import _ from 'lodash' // eslint-disable-line
import {fromJS} from 'immutable'
import {TYPES} from './actions'

const defaultState = fromJS({
  pagesBySlug: {},
  staticPageLinks: {},
  settings: {},
})

export default function reducer(state=defaultState, action={}) {

  switch (action.type) {
    case TYPES.APP_SETTINGS_LOAD + '_START':
    case TYPES.STATIC_PAGE_LOAD + '_START':
      return state.merge({loading: true, errors: null})

    case TYPES.APP_SETTINGS_LOAD + '_ERROR':
    case TYPES.STATIC_PAGE_LOAD + '_ERROR':
      return state.merge({loading: false, error: action.error || action.res.body.error})

    case TYPES.APP_SETTINGS_LOAD +'_SUCCESS':
      return state.merge({
        loading: false,
        loaded: true,
        errors: null,
        staticPageLinks: action.res.staticPageLinks,
        settings: _.omit(action.res, 'staticPageLinks'),
      })

    case TYPES.STATIC_PAGE_LOAD + '_SUCCESS':
      return state.mergeDeep({
        loading: false,
        errors: null,
        pagesBySlug: {[action.res.slug]: action.res},
      })

    default:
      return state
  }
}<commit_msg>handle app settings missing<commit_after>import _ from 'lodash' // eslint-disable-line
import {fromJS} from 'immutable'
import {TYPES} from './actions'

const defaultState = fromJS({
  pagesBySlug: {},
  staticPageLinks: {},
  settings: {},
})

export default function reducer(state=defaultState, action={}) {

  switch (action.type) {
    case TYPES.APP_SETTINGS_LOAD + '_START':
    case TYPES.STATIC_PAGE_LOAD + '_START':
      return state.merge({loading: true, errors: {}})

    case TYPES.APP_SETTINGS_LOAD + '_ERROR':
    case TYPES.STATIC_PAGE_LOAD + '_ERROR':
      return state.merge({loading: false, errors: {load: action.error || action.res.body.error}})

    case TYPES.APP_SETTINGS_LOAD +'_SUCCESS':
      let toMerge = {}
      if (action.model) {
        const {staticPageLinks, ...rest} = action.model
        toMerge = {
          staticPageLinks,
          settings: rest,
          errors: {},
        }
      }
      else {
        toMerge = {errors: {load: 'No app settings model was found'}}
      }
      return state.merge({
        loading: false,
        loaded: true,
        ...toMerge,
      })

    case TYPES.STATIC_PAGE_LOAD + '_SUCCESS':
      return state.mergeDeep({
        loading: false,
        errors: {},
        pagesBySlug: {[action.res.slug]: action.res},
      })

    default:
      return state
  }
}
{'fraction_non_alphanumeric': 0.1310483870967742, 'fraction_numerical': 0.0, 'mean_word_length': 2.725225225225225, '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': '3491199', 'n_tokens_mistral': 774, 'n_tokens_neox': 777, 'n_words': 177}