| | |
| | | |
| | | const dummyData = [ |
| | | { |
| | | title: "Learn awesome things about Labs", |
| | | _id: 0, |
| | | title: "Learn awesome things about Labs 🔬", |
| | | completed: false, |
| | | important: false |
| | | }, |
| | | { |
| | | title: "Learn about my friend Jenkins", |
| | | _id: 1, |
| | | title: "Learn about my friend Jenkins 🎉", |
| | | completed: true, |
| | | important: false |
| | | }, |
| | | { |
| | | title: "Have a poop", |
| | | _id: 2, |
| | | title: "Drink Coffee ☕💩", |
| | | completed: false, |
| | | important: true |
| | | } |
| | | ]; |
| | | export default { |
| | | loadTodos({ commit }) { |
| | | axios |
| | | return axios |
| | | .get(config.todoEndpoint) |
| | | .then(r => r.data) |
| | | .then(todos => { |
| | |
| | | // debugger |
| | | const todo = { |
| | | title: state.newTodo, |
| | | completed: false, |
| | | important: false |
| | | completed: false |
| | | }; |
| | | axios.post(config.todoEndpoint, todo).then(mongoTodo => { |
| | | commit("ADD_TODO", mongoTodo.data); |
| | | }); |
| | | // console.info("TESTINT BLAH BLAH ", todo); |
| | | return axios |
| | | .post(config.todoEndpoint, todo) |
| | | .then(mongoTodo => { |
| | | commit("ADD_TODO", mongoTodo.data); |
| | | }) |
| | | .catch(err => { |
| | | if (err) { |
| | | console.info("INFO - Adding dummy todo because of ", err); |
| | | let mongoTodo = todo; |
| | | mongoTodo._id = "fake-todo-item-" + Math.random(); |
| | | commit("ADD_TODO", mongoTodo); |
| | | } |
| | | }); |
| | | }, |
| | | setNewTodo({ commit }, todo) { |
| | | // debugger |
| | |
| | | } |
| | | // 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! |
| | | } 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); |
| | | } |
| | | }; |