Donal Spring
2018-06-03 71eec436bdcbb5c86c11929033b6053a986e857b
src/store/actions.js
@@ -3,16 +3,19 @@
const dummyData = [
  {
    _id: 0,
    title: "Learn awesome things about Labs ðŸ”¬",
    completed: false,
    important: false
  },
  {
    _id: 1,
    title: "Learn about my friend Jenkins ðŸŽ‰",
    completed: true,
    important: false
  },
  {
    _id: 2,
    title: "Drink Coffee â˜•ðŸ’©",
    completed: false,
    important: true
@@ -20,7 +23,7 @@
];
export default {
  loadTodos({ commit }) {
    axios
    return axios
      .get(config.todoEndpoint)
      .then(r => r.data)
      .then(todos => {
@@ -46,7 +49,8 @@
      completed: false,
      important: false
    };
    axios
    // console.info("TESTINT BLAH BLAH ", todo);
    return axios
      .post(config.todoEndpoint, todo)
      .then(mongoTodo => {
        commit("ADD_TODO", mongoTodo.data);
@@ -91,14 +95,20 @@
    }
    //  2 return array of promises and resolve all
  },
  markTodoCompleted({ commit, state }, id) {
  /* eslint: ignore */
  updateTodo({ commit, state }, { id, important }) {
    let i = state.todos.findIndex(todo => todo._id === id);
    // todo - add back end
    axios
    if (important) {
      // TODO - add commit imporant here!
      commit("MARK_TODO_IMPORTANT", i);
    } else {
      commit("MARK_TODO_COMPLETED", i);
    }
    // Fire and forget style backend update ;)
    return axios
      .put(config.todoEndpoint + "/" + state.todos[i]._id, state.todos[i])
      .then(data => {
        console.info("INFO - item " + id + " updated", data);
        console.log("INFO - item " + id + " updated");
      });
    commit("MARK_TODO_COMPLETED", i);
  }
};