<commit_before>import * as api from '../api';
import { createAction } from './utils';
import { clearSearch } from './search';

const WORLD_SELECTED = 'traveler-starmap/subsector/WORLD_SELECTED';
const NEW_SUBSECTOR_REQUEST = 'traveler-starmap/subsector/NEW_SUBSECTOR_REQUEST';
const NEW_SUBSECTOR_SUCCESS = 'traveler-starmap/subsector/NEW_SUBSECTOR_SUCCESS';
const NEW_SUBSECTOR_FAILURE = 'traveler-starmap/subsector/NEW_SUBSECTOR_FAILURE';

export const selectWorld = world => createAction(WORLD_SELECTED, world);

const fetchSubsector = (fn, world) => {
  return dispatch => {
    dispatch(selectWorld(null));
    dispatch(createAction(NEW_SUBSECTOR_REQUEST));
    fn()
    .then(payload => {
      dispatch(createAction(NEW_SUBSECTOR_SUCCESS, payload));
      if (world) {
        dispatch(selectWorld(world));
      }
    }, err => {
      dispatch(NEW_SUBSECTOR_FAILURE, err);
    });
  };
};

export function getRandomSubsector() {
  return fetchSubsector(() => api.get('random/'));
}

export function newSubsector() {
  return fetchSubsector(() => api.post(''));
}

export function jumpTo(searchResult) {
  return dispatch => {
    dispatch(clearSearch());
    const url = searchResult.subsector.id + '/';
    dispatch(fetchSubsector(() => api.get(url), searchResult.world));
  };
}

const initialState = {
  subsector: null,
  selected: null,
};

export default function (state = initialState, action) {
  switch (action.type) {
    case WORLD_SELECTED:
      return { ...state, selected: action.payload };
    case NEW_SUBSECTOR_REQUEST:
      return { ...state, subsector: null, selected: null };
    case NEW_SUBSECTOR_SUCCESS:
      return { ...state, subsector: action.payload };
    default:
      return state;

  }
}<commit_msg>Tidy up action<commit_after>import * as api from '../api';
import { createAction } from './utils';
import { clearSearch } from './search';

const WORLD_SELECTED = 'traveler-starmap/subsector/WORLD_SELECTED';
const NEW_SUBSECTOR_REQUEST = 'traveler-starmap/subsector/NEW_SUBSECTOR_REQUEST';
const NEW_SUBSECTOR_SUCCESS = 'traveler-starmap/subsector/NEW_SUBSECTOR_SUCCESS';
const NEW_SUBSECTOR_FAILURE = 'traveler-starmap/subsector/NEW_SUBSECTOR_FAILURE';

export const selectWorld = world => createAction(WORLD_SELECTED, world);

const fetchSubsector = (fn, world) => {
  return dispatch => {
    dispatch(createAction(NEW_SUBSECTOR_REQUEST));
    fn()
    .then(subsector => {
      dispatch(createAction(NEW_SUBSECTOR_SUCCESS, { subsector, selected: world }));
    }, err => {
      dispatch(NEW_SUBSECTOR_FAILURE, err);
    });
  };
};

export function getRandomSubsector() {
  return fetchSubsector(() => api.get('random/'));
}

export function newSubsector() {
  return fetchSubsector(() => api.post(''));
}

export function jumpTo(searchResult) {
  return dispatch => {
    dispatch(clearSearch());
    const url = searchResult.subsector.id + '/';
    dispatch(fetchSubsector(() => api.get(url), searchResult.world));
  };
}

const initialState = {
  subsector: null,
  selected: null,
};

export default function (state = initialState, action) {
  switch (action.type) {
    case WORLD_SELECTED:
      return { ...state, selected: action.payload };
    case NEW_SUBSECTOR_REQUEST:
      return { ...state, subsector: null, selected: null };
    case NEW_SUBSECTOR_SUCCESS:
      return { ...state, ...action.payload };
    default:
      return state;

  }
}
{'fraction_non_alphanumeric': 0.13732394366197184, 'fraction_numerical': 0.0, 'mean_word_length': 4.157337367624811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2862660', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1060, 'n_words': 219}