<commit_before>import { createActions, handleActions } from 'redux-actions';
import { all, put, select, call, takeEvery } from 'redux-saga/effects';
import { createSelector } from 'reselect';
import filter from 'lodash/filter';
import find from 'lodash/find';

import { load, save } from 'lib/api';
import { DEFAULT_ACCENT } from 'style/theme';
import { updateItem } from 'utils/array';

import OPTIONS, { SECTIONS } from 'options';
import { actions as toastActions } from 'modules/toast';

// state
const defaultState = {
  data: [],
  menuVisible: false,
};

// selectors
export const selectors = {
  options: state => state.options.data.filter(o => !o.static),
  allOptions: state => state.options.data,
};

selectors.accentColor = createSelector([selectors.options], options => {
  const accentOption = find(options, { id: 'accent' });
  return accentOption ? find(accentOption.values, { id: accentOption.value }) : { value: DEFAULT_ACCENT };
});

selectors.enabled = createSelector([selectors.options], options => {
  const enabledOption = find(options, { id: 'enabled' });
  return enabledOption ? enabledOption.value : false;
});

selectors.version = createSelector([selectors.allOptions], options => {
  const versionOption = find(options, { id: 'version' });
  return versionOption ? versionOption.value : undefined;
});

selectors.versionPrevious = createSelector([selectors.allOptions], options => {
  const versionOption = find(options, { id: 'lastRun' });
  return versionOption ? versionOption.value : undefined;
});

selectors.visibleMenus = createSelector([selectors.options], options => {
  return filter(options, { section: 'visibleMenus' });
});

selectors.visiblePlaylists = createSelector([selectors.options], options => {
  return filter(options, { section: 'visiblePlaylists' });
});

selectors.sortedOptions = createSelector([selectors.options], options =>
  SECTIONS.map(section => {
    const sectionOptions = filter(options, o => {
      const oSection = o.section || 'default';
      return section.id === oSection;
    });

    return {
      ...section,
      options: sectionOptions || [],
    };
  })
);

// actions
export const actions = createActions(
  'CHECK_UPDATE',
  'FETCH_OPTIONS',
  'FETCH_OPTIONS_RESPONSE',
  'SAVE_OPTIONS',
  'SAVE_OPTIONS_RESPONSE',
  'TOGGLE_MENU',
  'UPDATE_OPTION',
  'UPDATE_SAVE_OPTION',
);

const toObject = (options = []) =>
  options.reduce((obj, option) => {
    if (option.type === 'string') return obj;

    const updated = {
      ...obj,
      [option.id]: option.value !== undefined ? option.value : option.defaultValue,
    };

    return !option.plural
      ? updated<commit_msg>Added enabledAccents selector, updated accentColor selector to return default accent when neither "enables" are enabled<commit_after>import { createActions, handleActions } from 'redux-actions';
import { all, put, select, call, takeEvery } from 'redux-saga/effects';
import { createSelector } from 'reselect';
import filter from 'lodash/filter';
import find from 'lodash/find';

import { load, save } from 'lib/api';
import { DEFAULT_ACCENT } from 'style/theme';
import { updateItem } from 'utils/array';

import OPTIONS, { SECTIONS } from 'options';
import { actions as toastActions } from 'modules/toast';

// state
const defaultState = {
  data: [],
  menuVisible: false,
};

// selectors
export const selectors = {
  options: state => state.options.data.filter(o => !o.static),
  allOptions: state => state.options.data,
};

selectors.enabled = createSelector([selectors.options], options => {
  const enabledOption = find(options, { id: 'enabled' });
  return enabledOption ? enabledOption.value : false;
});

selectors.enabledAccents = createSelector([selectors.options], options => {
  const enabledOption = find(options, { id: 'accentsOnly' });
  return enabledOption ? enabledOption.value : false;
});

selectors.accentColor = createSelector(
  [selectors.enabled, selectors.enabledAccents, selectors.options],
  (enabled, enabledAccents, options) => {
    const isEnabled = enabled || enabledAccents;
    const accentOption = find(options, { id: 'accent' });
    return isEnabled && accentOption
      ? find(accentOption.values, { id: accentOption.value })
      : { value: DEFAULT_ACCENT };
  }
);

selectors.version = createSelector([selectors.allOptions], options => {
  const versionOption = find(options, { id: 'version' });
  return versionOption ? versionOption.value : undefined;
});

selectors.versionPrevious = createSelector([selectors.allOptions], options => {
  const versionOption = find(options, { id: 'lastRun' });
  return versionOption ? versionOption.value : undefined;
});

selectors.visibleMenus = createSelector([selectors.options], options => {
  return filter(options, { section: 'visibleMenus' });
});

selectors.visiblePlaylists = createSelector([selectors.options], options => {
  return filter(options, { section: 'visiblePlaylists' });
});

selectors.sortedOptions = createSelector([selectors.options], options =>
  SECTIONS.map(section => {
    const sectionOptions = filter(options, o => {
      const oSection = o.section || 'default';
      return section.id === oSection;
    });

    return {
      ...section,
      options: sectionOptions || [],
    };
  })
);

// actions
export const actions = createActions(
  'CHECK_UPDATE',
  'FETCH_OPTIONS',
  'FETCH_OPTIONS_RESPONSE',
  'SAVE_OPTIONS',
  'SAVE_OPTIONS_RESPONSE',
  'TOGGLE_MENU',
  'UPDATE_OPTION',
  'UPDATE_SAVE_OPTION'
);

const toObject = (options = []) =>
  options.reduce((obj, option) => {
    if (option.type === 'string') return obj;

    const updated = {
      ...obj,
      [option.id]: option.value !== undefined ? option.value : option.defaultValue,
    };

    return !option.plural
      ? updated
{'fraction_non_alphanumeric': 0.1441675320179993, 'fraction_numerical': 0.0, 'mean_word_length': 4.3908582089552235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '1422841', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1712, 'n_words': 403}