donal
2018-04-16 78a403c450425ea86fad7df5737a4a53ed4c6714
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 => {
@@ -43,10 +46,10 @@
    // debugger
    const todo = {
      title: state.newTodo,
      completed: false,
      important: false
      completed: false
    };
    axios
    // console.info("TESTINT BLAH BLAH ", todo);
    return axios
      .post(config.todoEndpoint, todo)
      .then(mongoTodo => {
        commit("ADD_TODO", mongoTodo.data);
@@ -91,17 +94,19 @@
    }
    //  2 return array of promises and resolve all
  },
  updateTodo({ commit, state }, {id, important}) {
  /* eslint: ignore */
  updateTodo({ commit, state }, { id, important }) {
    let i = state.todos.findIndex(todo => todo._id === id);
    axios
      .put(config.todoEndpoint + "/" + state.todos[i]._id, state.todos[i])
      .then(data => {
        console.info("INFO - item " + id + " updated", data);
      });
    if (important) {
      commit("MARK_TODO_IMPORTANT", i);
      // TODO - add commit imporant here!
    } 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.log("INFO - item " + id + " updated");
      });
  }
};