{"size": 4018, "ext": "js", "max_stars_repo_path": "app/assets/scripts/redux/reducers.js", "max_stars_repo_name": "developmentseed/plasticwatch", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/assets/scripts/redux/reducers.js", "max_issues_repo_name": "developmentseed/plasticwatch", "max_issues_repo_issues_event_min_datetime": "2020-12-02T16:20:44.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-09T10:31:37.000Z", "max_forks_repo_path": "app/assets/scripts/redux/reducers.js", "max_forks_repo_name": "developmentseed/plasticwatch", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 18.4311926606, "max_line_length": 83, "alphanum_fraction": 0.675211548}
import { combineReducers } from 'redux';
import { baseAPIReducer } from './utils';

/**
 * AUTHENTICATED USER reducer
 */
const authenticatedUserReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: {
    loggedIn: false
  }
};

const authenticatedUserReducer = baseAPIReducer(
  'AUTHENTICATED_USER',
  authenticatedUserReducerInitialState
);

/**
 * USERS reducer
 */
const usersReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: []
};

const usersReducer = baseAPIReducer('USERS', usersReducerInitialState);

/**
 * USER reducer
 */
const userReducerInitialState = {
  // fetching: false,
  // fetched: false,
  // error: null,
  // data: []
};

const userReducer = baseAPIReducer('USER', userReducerInitialState);

/**
 * CAMPAIGNS reducer
 */
const campaignsReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: []
};

const campaignsReducer = baseAPIReducer('CAMPAIGNS', campaignsReducerInitialState);

/**
 * PLACES reducer
 */
const placesReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: []
};

const placesReducer = baseAPIReducer('PLACES', placesReducerInitialState);

/**
 * PLACES_TILES reducer
 */
const placesTilesReducerInitialState = {
  // fetching: false,
  // fetched: false,
  // error: null,
  // data: []
};

const placesTilesReducer = baseAPIReducer(
  'PLACES_TILE',
  placesTilesReducerInitialState
);

/**
 * PLACE reducer
 */
const placeReducerInitialState = {
  // fetching: false,
  // fetched: false,
  // error: null,
  // data: []
};

const placeReducer = baseAPIReducer('PLACE', placeReducerInitialState);

/**
 * SURVEY_META reducer
 */
const surveyMetaReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: null
};
const surveyMetaReducer = baseAPIReducer(
  'SURVEY_META',
  surveyMetaReducerInitialState
);

/**
 * SURVEY_ANSWERS reducer
 */
const surveyAnswersReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: null
};
const surveyAnswersReducer = baseAPIReducer(
  'SURVEY_ANSWERS',
  surveyAnswersReducerInitialState
);

/**
 * STATS reducer
 */
const statsReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: []
};

const statsReducer = baseAPIReducer('STATS', statsReducerInitialState);

/**
 * TOP_SURVEYORS reducer
 */
const topSurveyorsReducerInitialState = {
  fetching: false,
  fetched: false,
  error: null,
  data: []
};

const topSurveyorsReducer = baseAPIReducer(
  'TOP_SURVEYORS',
  topSurveyorsReducerInitialState
);

/**
 * EXPLORE VIEW reducer
 */
const exploreInitialState = {
  activeMobileTab: 'map',
  mapViewport: {},
  filters: {
    searchString: null,
    placeType: null
  }
};

const exploreReducer = (state = exploreInitialState, action) => {
  switch (action.type) {
    case 'UPDATE_FILTERS_AND_MAP_VIEWPORT':
      return {
        ...state,
        mapViewport: action.mapViewport || {},
        filters: action.filters || {}
      };
    case 'UPDATE_MAP_VIEWPORT':
      return {
        ...state,
        mapViewport: action.mapViewport
      };
    case 'UPDATE_FILTERS':
      return {
        ...state,
        filters: {
          ...state.filters,
          ...action.filters
        }
      };
    case 'UPDATE_ACTIVE_MOBILE_TAB':
      return {
        ...state,
        activeMobileTab: action.tabId
      };
  }
  return state;
};

/**
 * Export combined reducers
 */
export default combineReducers({
  authenticatedUser: authenticatedUserReducer,
  campaigns: campaignsReducer,
  users: combineReducers({
    list: usersReducer,
    individual: userReducer
  }),
  activeSurvey: combineReducers({
    meta: surveyMetaReducer,
    answers: surveyAnswersReducer
  }),
  places: combineReducers({
    tiles: placesTilesReducer,
    list: placesReducer,
    individual: placeReducer
  }),
  trends: combineReducers({
    stats: statsReducer,
    topSurveyors: topSurveyorsReducer
  }),
  explore: exploreReducer
});
