{"size": 1095, "ext": "js", "max_stars_repo_path": "todo-list/src/store/reducers.js", "max_stars_repo_name": "alex996/microapps", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "todo-list/src/store/reducers.js", "max_issues_repo_name": "alex996/microapps", "max_issues_repo_issues_event_min_datetime": "2019-10-30T22:36:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-25T23:39:21.000Z", "max_forks_repo_path": "todo-list/src/store/reducers.js", "max_forks_repo_name": "alex996/microapps", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 62, "max_forks_count": null, "avg_line_length": 20.2777777778, "max_line_length": 64, "alphanum_fraction": 0.4904109589}
import {
  TOGGLE_THEME, CHANGE_LOCALE, ADD_TODO,
  TOGGLE_COMPLETE, DELETE_TODO, LIGHT, DARK, EN
} from '.'

export const initialState = {
  theme: LIGHT,
  locale: EN,
  todos: []
}

export const app = (state = initialState, action = {}) => {
  switch (action.type) {
    case TOGGLE_THEME:
      return {
        ...state,
        theme: state.theme === LIGHT ? DARK : LIGHT
      }
    case CHANGE_LOCALE:
      return {
        ...state,
        locale: action.locale
      }
    case ADD_TODO:
      return {
        ...state,
        todos: [
          ...state.todos,
          {
            id: Date.now(),
            title: action.title,
            completed: false
          }
        ]
      }
    case TOGGLE_COMPLETE:
      return {
        ...state,
        todos: state.todos.map(todo =>
          todo.id === action.id
            ? { ...todo, completed: !todo.completed }
            : todo
        )
      }
    case DELETE_TODO:
      return {
        ...state,
        todos: state.todos.filter(todo => todo.id !== action.id)
      }
    default:
      return state
  }
}
