acammies
2018-04-04 1f415e2892158066c2fd16c6698383427f1a203c
commit | author | age
82de6c 1 import axios from "axios";
D 2 import config from "@/config";
3
4 export default {
5   loadTodos({ commit }) {
6     axios
7       .get(config.todoEndpoint)
8       .then(r => r.data)
9       .then(todos => {
10         commit("SET_TODOS", todos);
11         commit("SET_LOADING", false);
12       });
13   },
14   addTodo({ commit, state }) {
15     if (!state.newTodo) {
16       // do not add empty todos
17       return;
18     }
1f415e 19     debugger
82de6c 20     const todo = {
D 21       title: state.newTodo,
0f0a91 22       completed: false,
A 23       important: false
82de6c 24     };
D 25     axios.post(config.todoEndpoint, todo).then(mongoTodo => {
3f23cc 26       commit("ADD_TODO", mongoTodo.data);
82de6c 27     });
D 28   },
530b0a 29   setNewTodo ({ commit }, todo) {
D 30     commit('SET_NEW_TODO', todo)
31   },
1f415e 32   updateTodo({ commit,state }, todo) {
A 33     // const todo = state.newTodo
34     debugger
35     const foundIndex = state.todos.findIndex(obj => obj.id === todo.id);
36     state.todos[foundIndex] = todo;
37     const newUpdatedArray = state.todos
38     commit("UPDATE_TODO", newUpdatedArray)
39   },
82de6c 40   clearNewTodo({ commit }) {
D 41     commit("CLEAR_NEW_TODO");
fbee7b 42   },
A 43   clearAllTodos({ commit }) {
44     commit("CLEAR_ALL_TODOS")
08cb74 45   },
A 46   clearAllDoneTodos({ commit }) {
47     commit("CLEAR_ALL_DONE_TODOS")
48   },
82de6c 49 };