{"size": 4363, "ext": "js", "max_stars_repo_path": "src/modules/reducer.js", "max_stars_repo_name": "juanrules/workoutteim", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modules/reducer.js", "max_issues_repo_name": "juanrules/workoutteim", "max_issues_repo_issues_event_min_datetime": "2020-04-22T08:54:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:25:44.000Z", "max_forks_repo_path": "src/modules/reducer.js", "max_forks_repo_name": "juanrules/workoutteim", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 22.2602040816, "max_line_length": 79, "alphanum_fraction": 0.4895713958}
import actionTypes from "../constants/actionTypes";
import * as constants from "../constants/main";
export default (state, action) => {
  switch (action.type) {
    case actionTypes.START_TIME:
      return {
        ...state,
        isRunning: true,
      };

    case actionTypes.END_TIME:
      return {
        ...state,
        isRunning: false,
        timesUp: true,
        timers: [...state.timers.map((e) => ({ ...e, isActive: false }))],
      };

    case actionTypes.PAUSE_TIME:
      return {
        ...state,
        isRunning: false,
        timers: [...state.timers.map((e) => ({ ...e, isActive: false }))],
      };

    case actionTypes.SET_TIME:
      return {
        ...state,
        timers: [
          ...state.timers.map((e, i) =>
            i === action.index
              ? { ...e, time: action.time, isActive: true }
              : { ...e }
          ),
        ],
      };

    case actionTypes.DELETE_TIMERS:
      return {
        ...state,
        timers: [],
      };

    case actionTypes.RESET_TIME:
      return {
        ...state,
        placeholder: [],
        timesUp: false,
        isRunning: false,
        timers: state.snapshot,
        snapshot: [],
      };

    case actionTypes.SET_WORKOUT:
      return {
        ...state,
        timers: action.workout,
      };

    case actionTypes.ADD_NEW_TIMER:
      const newTimer = state.restIntervalsToggle
        ? [constants.DEFAULT_REST_INTERVAL, action.timer]
        : [action.timer];

      return {
        ...state,
        timers: [...state.timers, ...newTimer],
        snapshot: [],
      };

    case actionTypes.TOGGLE_REST_INTERVALS:
      return {
        ...state,
        restIntervalsToggle: action.toggle,
      };

    case actionTypes.ADD_REST_INTERVALS:
      const timersPlusIntervals = [
        ...state.timers.reduce((acc, e) => acc.concat(e, action.timer), []),
      ];

      timersPlusIntervals.pop();

      return {
        ...state,
        timers: timersPlusIntervals,
        restIntervalsToggle: true,
        snapshot: [],
      };

    case actionTypes.REMOVE_REST_INTERVALS:
      return {
        ...state,
        timers: [...state.timers.filter((e, i) => !e.isRestInvertal)],
        restIntervalsToggle: false,
        snapshot: [],
      };

    case actionTypes.DELETE_TIMER:
      const filteredTimers = [
        ...state.timers.filter(
          (e, i) =>
            i !== action.index && !(i === action.index + 1 && e.isRestInvertal)
        ),
      ];

      return {
        ...state,
        timers: filteredTimers,
        snapshot: [],
      };

    case actionTypes.SET_TIMER_TITLE:
      const newTitleTimers = [
        ...state.timers.map((e, i) =>
          i === action.index ? { ...e, title: action.title } : { ...e }
        ),
      ];

      return {
        ...state,
        timers: newTitleTimers,
        snapshot: [],
      };

    case actionTypes.ADD_TIME:
      const addedTimeTimers = [
        ...state.timers.map((e, i) =>
          i === action.index
            ? { ...e, time: e.time + constants.TIME_INCREMENT }
            : { ...e }
        ),
      ];

      return {
        ...state,
        timers: addedTimeTimers,
        snapshot: [],
      };

    case actionTypes.REDUCE_TIME:
      const reducedTimeTimers = [
        ...state.timers.map((e, i) =>
          i === action.index
            ? {
                ...e,
                time:
                  e.time - constants.TIME_INCREMENT < 0
                    ? 1
                    : e.time - constants.TIME_INCREMENT,
              }
            : { ...e }
        ),
      ];

      return {
        ...state,
        timers: reducedTimeTimers,
        snapshot: [],
      };

    case actionTypes.TAKE_SNAPSHOT:
      return {
        ...state,
        snapshot: action.snapshot,
      };

    case actionTypes.SHOW_CREDITS:
      return {
        ...state,
        showCredits: !state.showCredits,
      };

    case actionTypes.SHOW_HELP:
      return {
        ...state,
        showHelp: !state.showHelp,
      };

    case actionTypes.SHOW_SHARE_MODAL:
      return {
        ...state,
        showShareModal: !state.showShareModal,
      };

    case actionTypes.SET_WORKOUT_SHORT_URL:
      return {
        ...state,
        workoutShortUrl: action.url,
      };

    default:
      return null;
  }
};
