summaryrefslogtreecommitdiff
path: root/client/reducers/tasks.js
blob: 904c3687b2ac53fc9892caf4af613273adbd51fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import client from '../client'

const tasks = (state = [], action) => {
  let updated_tasks;
  
  switch (action.type) {
    case 'LOAD_TASKS':
      return action.tasks

    case 'ADD_TASK':
      return [action.task].concat(state)

    case 'UPDATE_TASK':
      updated_tasks = state.map(task => {
        if (task.id === action.task.id) {
          return action.task
        }
        return task
      })
      return updated_tasks
    
    case 'CANCEL_TASK':
      client.task.destroy(action.task)
      return state.filter(task => task !== action.task)

    default:
      return state
  }
}

export default tasks