<commit_before>import update from 'immutability-helper';
import * as at from 'fm3/actionTypes';

const initialState = {
  start: null,
  midpoints: [],
  finish: null,
  transportType: null,
  effectiveTransportType: null,
  pickMode: 'start',
  itineraryIsVisible: false,
  alternatives: [],
  activeAlternativeIndex: 0,
  timestamp: null,
};

export default function routePlanner(state = initialState, action) {
  switch (action.type) {
    case at.SET_TOOL:
      return { ...state, pickMode: !state.start ? 'start' : !state.finish ? 'finish' : null };
    case at.CLEAR_MAP:
      return {
        ...initialState,
        transportType: state.transportType,
      };
    case at.ROUTE_PLANNER_SET_PARAMS:
      return {
        ...state,
        ...(action.payload.start === null || action.payload.finish === null ? {
          ...initialState,
          transportType: state.transportType,
        } : {}),
        start: action.payload.start,
        finish: action.payload.finish,
        midpoints: action.payload.transportType === 'imhd' ? [] : action.payload.midpoints,
        transportType: action.payload.transportType,
      };
    case at.ROUTE_PLANNER_SET_START:
      return { ...state, start: action.payload, pickMode: state.finish ? null : 'finish' };
    case at.ROUTE_PLANNER_SET_FINISH:
      return { ...state, finish: action.payload, pickMode: state.start ? null : 'finish' };
    case at.ROUTE_PLANNER_SWAP_ENDS:
      return { ...state, start: state.finish, finish: state.start };
    case at.ROUTE_PLANNER_ADD_MIDPOINT:
      return update(state, { midpoints: { $splice: [[action.payload.position, 0, action.payload.midpoint]] } });
    case at.ROUTE_PLANNER_SET_MIDPOINT:
      return update(state, { midpoints: { [action.payload.position]: { $set: action.payload.midpoint } } });
    case at.ROUTE_PLANNER_REMOVE_MIDPOINT:
      return update(state, { midpoints: { $splice: [[action.payload, 1]] } });
    case at.ROUTE_PLANNER_SET_TRANSPORT_TYPE:<commit_msg>made route planner swapping to reverse midpoints<commit_after>import update from 'immutability-helper';
import * as at from 'fm3/actionTypes';

const initialState = {
  start: null,
  midpoints: [],
  finish: null,
  transportType: null,
  effectiveTransportType: null,
  pickMode: 'start',
  itineraryIsVisible: false,
  alternatives: [],
  activeAlternativeIndex: 0,
  timestamp: null,
};

export default function routePlanner(state = initialState, action) {
  switch (action.type) {
    case at.SET_TOOL:
      return { ...state, pickMode: !state.start ? 'start' : !state.finish ? 'finish' : null };
    case at.CLEAR_MAP:
      return {
        ...initialState,
        transportType: state.transportType,
      };
    case at.ROUTE_PLANNER_SET_PARAMS:
      return {
        ...state,
        ...(action.payload.start === null || action.payload.finish === null ? {
          ...initialState,
          transportType: state.transportType,
        } : {}),
        start: action.payload.start,
        finish: action.payload.finish,
        midpoints: action.payload.transportType === 'imhd' ? [] : action.payload.midpoints,
        transportType: action.payload.transportType,
      };
    case at.ROUTE_PLANNER_SET_START:
      return { ...state, start: action.payload, pickMode: state.finish ? null : 'finish' };
    case at.ROUTE_PLANNER_SET_FINISH:
      return { ...state, finish: action.payload, pickMode: state.start ? null : 'finish' };
    case at.ROUTE_PLANNER_SWAP_ENDS:
      return { ...state, start: state.finish, finish: state.start, midpoint: [...state.midpoints].reverse() };
    case at.ROUTE_PLANNER_ADD_MIDPOINT:
      return update(state, { midpoints: { $splice: [[action.payload.position, 0, action.payload.midpoint]] } });
    case at.ROUTE_PLANNER_SET_MIDPOINT:
      return update(state, { midpoints: { [action.payload.position]: { $set: action.payload.midpoint } } });
    case at.ROUTE_PLANNER_REMOVE_MIDPOINT:
      return update(state, { midpoints: { $splice: [[action.payload, 1]] } });
    case at.ROUTE_PLANNER_SET_TRANSPORT_TYPE:
{'fraction_non_alphanumeric': 0.13489519112207152, 'fraction_numerical': 0.001972872996300863, 'mean_word_length': 3.20746887966805, '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': '1194681', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1294, 'n_words': 265}