This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateTodoMutation (state, todo) { | |
let index = state.todos.findIndex(element => element.id === todo.id) | |
state.todos[index] = todo | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async updateTodo (todo) { | |
const updatedTodoHash = { is_completed: todo.is_completed } | |
const response = await axios.put('todos/' + todo.id, updatedTodoHash) | |
return response.data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateTodoAction ({ commit }, todo) { | |
return new Promise((resolve, reject) => { | |
ApiHelper.updateTodo(todo) | |
.then(response => { | |
commit('updateTodoMutation', response) | |
resolve(response) | |
}) | |
.catch(error => { | |
reject(error) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateTodo(todo) { | |
this.updateTodoAction(todo) | |
.then(() => SweetAlert.successfulLogin()) | |
.catch(() => SweetAlert.failureLogin()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<v-checkbox | |
v-model="task.is_completed" | |
color="info darken-3" | |
@change="updateTodo(task)" | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saveTodoMutation (state, todo) { | |
state.todos = [...state.todos, todo] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saveTodoAction ({ commit }, todoData) { | |
return new Promise((resolve, reject) => { | |
ApiHelper.todo(todoData) | |
.then(response => { | |
commit('saveTodoMutation', response) | |
resolve(response) | |
}) | |
.catch(error => { | |
reject(error) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createTodo () { | |
const todoData = { 'title': this.task } | |
this.saveTodoAction(todoData) | |
.then(() => { | |
this.task = '' | |
SweetAlert.successfulLogin() | |
}) | |
.catch(() => { | |
SweetAlert.failureLogin() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async todo (todoData) { | |
const response = await axios.post('todos', todoData) | |
return response.data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions: { | |
fetchAllTodoAction ({ commit }) { | |
return new Promise((resolve, reject) => { | |
ApiHelper.todos() | |
.then(response => { | |
commit('fetchAllTodoMutation', response) | |
resolve(response) | |
}) | |
.catch(error => { | |
commit('failureTodoMutation') |