<commit_before>import {
  FETCH_NEARBY_CAMPAIGNS_REQUEST,
  FETCH_NEARBY_CAMPAIGNS_SUCCESS,
  FETCH_NEARBY_CAMPAIGNS_FAILURE,
  VALIDATE_ADDRESS_SUCCESS,
  VALIDATE_ADDRESS_FAILURE,
  CLEAR_SEARCH_RESULTS,
  SET_CAMPAIGN_INFORMATION,
  SELECT_ADDRESS,
  APARTMENTS_REQUEST,
  APARTMENTS_SUCCESS,
  APARTMENTS_FAILURE
} from '../constants/initialSearch';

const defaultState = {
  loading: false,
  loaded: false,
  searchedAddress: null,
  error: null,
  nearbyCampaigns: null
};

export default function (state = defaultState, action) {
  const { response, error, type } = action;
  switch (type) {
    case FETCH_NEARBY_CAMPAIGNS_REQUEST:
      return {
        ...state,
        loading: true,
        loaded: false
      };
    case VALIDATE_ADDRESS_SUCCESS:
      return {
        ...state,
        searchedAddress: response[0]
      };
    case VALIDATE_ADDRESS_FAILURE:
      return {
        error: {
          userMessage: "Sorry, we couldn't locate that address. Try selecting one of the auto-suggested addresses for better accuracy.",
          searchError: error
        }
      };
    case FETCH_NEARBY_CAMPAIGNS_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        nearbyCampaigns: response,
        selectedAddress: response[0]
      };
    case FETCH_NEARBY_CAMPAIGNS_FAILURE:
      return {
        ...state,
        loading: false,
        loaded: false,
        error: {
          userMessage: 'Sorry, but something went wrong.',
          dbResponse: error
        }
      };
    case SELECT_ADDRESS:
      {
        const selectedAddress = state.nearbyCampaigns.find(c => c.street_address === action.value) || 'none';
        return {
          ...state,
          selectedAddress
        };
      }
    case 'STASH_ADDRESS':
      return {
        ...state,
        searchedAddress: action.address
      };
    case 'STASH_LAT_LNG':
      return {
        ...state,
        latLng: action.latLng
      };
    case CLEAR_SEARCH_RESULTS:
      return {
        ...state,
        ...defaultState
      };
    case SET_CAMPAIGN_INFORMATION:
      return {
        ...state,
        campaignInfo: action.campaignInfo
      };
    case APARTMENTS_REQUEST:
      return {
        ...state,
        loading: true,
        loaded: false
      };
    case APARTMENTS_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        apartments: response
      };
    case APARTMENTS_FAILURE:
      return {
        ...state,
        loading: false,
        loaded: false,
        error
      };
    default:
      return state;
  }<commit_msg>WIP sign in request<commit_after>import {
  FETCH_NEARBY_CAMPAIGNS_REQUEST,
  FETCH_NEARBY_CAMPAIGNS_SUCCESS,
  FETCH_NEARBY_CAMPAIGNS_FAILURE,
  VALIDATE_ADDRESS_SUCCESS,
  VALIDATE_ADDRESS_FAILURE,
  CLEAR_SEARCH_RESULTS,
  SET_CAMPAIGN_INFORMATION,
  SELECT_ADDRESS,
  APARTMENTS_REQUEST,
  APARTMENTS_SUCCESS,
  APARTMENTS_FAILURE
} from '../constants/initialSearch';

const defaultState = {
  loading: false,
  loaded: false,
  searchedAddress: null,
  error: null,
  nearbyCampaigns: null
};

export default function (state = defaultState, action) {
  const { response, error, type } = action;
  switch (type) {
    case FETCH_NEARBY_CAMPAIGNS_REQUEST:
      return {
        ...state,
        loading: true,
        loaded: false
      };
    case VALIDATE_ADDRESS_SUCCESS:
      return {
        ...state,
        searchedAddress: response[0]
      };
    case VALIDATE_ADDRESS_FAILURE:
      return {
        error: {
          userMessage: "Sorry, we couldn't locate that address. Try selecting one of the auto-suggested addresses for better accuracy.",
          searchError: error
        }
      };
    case FETCH_NEARBY_CAMPAIGNS_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        nearbyCampaigns: response,
        selectedAddress: response[0]
      };
    case FETCH_NEARBY_CAMPAIGNS_FAILURE:
      return {
        ...state,
        loading: false,
        loaded: false,
        error: {
          userMessage: 'Sorry, but something went wrong.',
          dbResponse: error
        }
      };
    case SELECT_ADDRESS:
      {
        const selectedAddress = state.nearbyCampaigns.find(c => c.street_address === action.value) || 'none';
        return {
          ...state,
          selectedAddress
        };
      }
    case 'STASH_ADDRESS':
      return {
        ...state,
        searchedAddress: action.address
      };
    case 'STASH_LAT_LNG':
      return {
        ...state,
        latLng: action.latLng
      };
    case CLEAR_SEARCH_RESULTS:
      return {
        ...state,
        ...defaultState
      };
    case SET_CAMPAIGN_INFORMATION:
      return {
        ...state,
        campaignInfo: action.campaignInfo
      };
    case APARTMENTS_REQUEST:
      return {
        ...state,
        loading: true,
        loaded: false
      };
    case APARTMENTS_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        apartments: response
      };
    case APARTMENTS_FAILURE:
      return {
        ...state,
        loading: false,
        loaded: false,
        error
      };
    case 'OAUTH_SIGN_IN_COMPLETE':
      console.log('reducers connected!');
      return state;
    default:
      return state;
  }
{'fraction_non_alphanumeric': 0.09087516327673073, 'fraction_numerical': 0.0007464079119238664, 'mean_word_length': 1.9337712096332786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5000364', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1625, 'n_words': 347}