{"size": 741, "ext": "js", "max_stars_repo_path": "frontend/js/redux/theme.js", "max_stars_repo_name": "sophiakhan/sump-thing-frontend", "max_stars_repo_stars_event_min_datetime": "2019-05-13T20:07:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-13T20:07:41.000Z", "max_issues_repo_path": "frontend/js/redux/theme.js", "max_issues_repo_name": "sophiakhan/sump-thing-frontend", "max_issues_repo_issues_event_min_datetime": "2019-05-12T03:21:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T10:44:43.000Z", "max_forks_repo_path": "frontend/js/redux/theme.js", "max_forks_repo_name": "sophiakhan/sump-thing-frontend", "max_forks_repo_forks_event_min_datetime": "2019-10-15T18:06:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-15T18:06:16.000Z"}
{"max_stars_count": 1, "max_issues_count": 31, "max_forks_count": 1, "avg_line_length": 19.5, "max_line_length": 63, "alphanum_fraction": 0.5775978408}
export const CHANGE_THEME = 'sumpthing/theme/change';

const initialState = { current: 'light' };

export default function reducer(state = initialState, action) {
  switch (action.type) {
    case CHANGE_THEME:
      return { ...state, current: action.theme };
    default:
      return state;
  }
}

export function toggleTheme(override) {
  return (dispatch, getState) => {
    const { current } = getState().theme;

    if (override) {
      return dispatch({
        type: CHANGE_THEME,
        theme: override,
      });
    }

    if (current === 'light') {
      return dispatch({
        type: CHANGE_THEME,
        theme: 'dark',
      });
    }

    return dispatch({
      type: CHANGE_THEME,
      theme: 'light',
    });
  };
}
