From 3bd680802264ee3f6d8e8dede670efb4d8de9878 Mon Sep 17 00:00:00 2001 From: donal <donalspring@gmail.com> Date: Sun, 22 Apr 2018 13:50:55 +0200 Subject: [PATCH] FIX - linting errors for the build --- src/store/actions.js | 93 ++++++++++++++++++++++++++++++---------------- 1 files changed, 61 insertions(+), 32 deletions(-) diff --git a/src/store/actions.js b/src/store/actions.js index 8c7de9b..3c581cd 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -3,32 +3,36 @@ 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 => { commit("SET_TODOS", todos); commit("SET_LOADING", false); - }).catch(err => { + }) + .catch(err => { if (err) { - console.info("INFO - setting dummy data because of ", err) + console.info("INFO - setting dummy data because of ", err); commit("SET_TODOS", dummyData); commit("SET_LOADING", false); } @@ -42,42 +46,67 @@ // 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 commit("SET_NEW_TODO", todo); }, - updateTodo({ commit, state }, todo) { - // const todo = state.newTodo - // debugger; - const foundIndex = state.todos.findIndex(obj => obj.id === todo.id); - state.todos[foundIndex] = todo; - const newUpdatedArray = state.todos; - commit("UPDATE_TODO", newUpdatedArray); - }, clearNewTodo({ commit }) { commit("CLEAR_NEW_TODO"); }, - clearAllTodos({ commit }) { - commit("CLEAR_ALL_TODOS"); - }, - clearAllDoneTodos({ commit, state }) { + clearTodos({ commit, state }, all) { // 1 fire and forget or - state.todos.map(todo => { - // axios remove all done by the id - if (todo.completed){ - axios.delete(config.todoEndpoint + '/' + todo._id).then(data => { - console.info("INFO - item " + todo._id + " deleted", data); - }); - } - }); + const deleteStuff = id => { + axios.delete(config.todoEndpoint + "/" + id).then(data => { + console.info("INFO - item " + id + " deleted", data); + }); + }; + + if (all) { + state.todos.map(todo => { + deleteStuff(todo._id); + }); + commit("CLEAR_ALL_TODOS"); + } else { + state.todos.map(todo => { + // axios remove all done by the id + if (todo.completed) { + deleteStuff(todo._id); + } + }); + commit("CLEAR_ALL_DONE_TODOS"); + } // 2 return array of promises and resolve all - commit("CLEAR_ALL_DONE_TODOS"); + }, + /* eslint: ignore */ + updateTodo({ commit, state }, { id, important }) { + let i = state.todos.findIndex(todo => todo._id === id); + 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(() => { + console.info("INFO - item " + id + " updated"); + }); } }; -- Gitblit v1.9.3