donal
2018-04-01 530b0a2578d8a80a4d53c6245a451b2e1077178b
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
32
33
import axios from "axios";
import config from "@/config";
 
export default {
  loadTodos({ commit }) {
    axios
      .get(config.todoEndpoint)
      .then(r => r.data)
      .then(todos => {
        commit("SET_TODOS", todos);
        commit("SET_LOADING", false);
      });
  },
  addTodo({ commit, state }) {
    if (!state.newTodo) {
      // do not add empty todos
      return;
    }
    const todo = {
      title: state.newTodo,
      completed: false
    };
    axios.post(config.todoEndpoint, todo).then(mongoTodo => {
      commit("ADD_TODO", mongoTodo);
    });
  },
  setNewTodo ({ commit }, todo) {
    commit('SET_NEW_TODO', todo)
  },
  clearNewTodo({ commit }) {
    commit("CLEAR_NEW_TODO");
  }
};