<commit_before>
import {handleActions} from 'redux-actions'
import {map, reject, omit, object, pick, indexBy} from 'underline'
import invariant from 'invariant'
import uuid from 'node-uuid'

import SearchExamples from '../../constants/search-examples'
import staticTabData from '../../constants/static-tab-data'

import {filter} from 'underline'

const perish = process.env.PERISH === '1' ? console.log.bind(console) : () => 0

const baseTabs = ['featured', 'library', 'collections']

const initialState = {
  page: 'gate',
  tabs: {
    constant: baseTabs,
    transient: []
  },
  filters: {},
  binaryFilters: {
    onlyCompatible: true
  },
  tabData: staticTabData::pick(...baseTabs)::indexBy('id'),
  id: 'featured',
  shortcutsShown: false
}

export default handleActions({
  BINARY_FILTER_CHANGED: (state, action) => {
    const {field, value} = action.payload
    const oldBinaryFilters = state.binaryFilters
    return {...state, binaryFilters: {
      ...oldBinaryFilters,
      [field]: value
    }}
  },

  DOWNLOAD_STARTED: (state, action) => {
    const {tabs, tabData} = state
    const {transient} = tabs

    const has = transient.indexOf('downloads') > 0
    if (has) {
      return state
    }

    return {
      ...state,
      tabs: {
        ...tabs,
        transient: [ ...transient, 'downloads' ]
      },
      tabData: {
        ...tabData,
        downloads: {
          ...staticTabData['downloads'],
          path: 'downloads'
        }
      }
    }
  },

  FILTER_CHANGED: (state, action) => {<commit_msg>don't open download tab twice<commit_after>
import {handleActions} from 'redux-actions'
import {map, reject, omit, object, pick, indexBy} from 'underline'
import invariant from 'invariant'
import uuid from 'node-uuid'

import SearchExamples from '../../constants/search-examples'
import staticTabData from '../../constants/static-tab-data'

import {filter} from 'underline'

const perish = process.env.PERISH === '1' ? console.log.bind(console) : () => 0

const baseTabs = ['featured', 'library', 'collections']

const initialState = {
  page: 'gate',
  tabs: {
    constant: baseTabs,
    transient: []
  },
  filters: {},
  binaryFilters: {
    onlyCompatible: true
  },
  tabData: staticTabData::pick(...baseTabs)::indexBy('id'),
  id: 'featured',
  shortcutsShown: false
}

export default handleActions({
  BINARY_FILTER_CHANGED: (state, action) => {
    const {field, value} = action.payload
    const oldBinaryFilters = state.binaryFilters
    return {...state, binaryFilters: {
      ...oldBinaryFilters,
      [field]: value
    }}
  },

  DOWNLOAD_STARTED: (state, action) => {
    const {tabs, tabData} = state
    const {transient} = tabs

    const has = transient.indexOf('downloads') >= 0
    if (has) {
      return state
    }

    return {
      ...state,
      tabs: {
        ...tabs,
        transient: [ ...transient, 'downloads' ]
      },
      tabData: {
        ...tabData,
        downloads: {
          ...staticTabData['downloads'],
          path: 'downloads'
        }
      }
    }
  },

  FILTER_CHANGED: (state, action) => {
{'fraction_non_alphanumeric': 0.1511139812721989, 'fraction_numerical': 0.0019373587342589602, 'mean_word_length': 2.7460701330108828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7375001', 'n_tokens_mistral': 1005, 'n_tokens_neox': 985, 'n_words': 236}