From 117ed6cfdc745eaf68788a901cd912faeabf3d07 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Sat, 1 Aug 2020 16:27:09 +0200 Subject: [PATCH] fix checked input status after move --- resources/js/views/ToDoLists/ToDo.vue | 28 +++++++++++-------- resources/js/views/ToDoLists/ToDoListShow.vue | 8 ++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/resources/js/views/ToDoLists/ToDo.vue b/resources/js/views/ToDoLists/ToDo.vue index eae126f..d4c309e 100644 --- a/resources/js/views/ToDoLists/ToDo.vue +++ b/resources/js/views/ToDoLists/ToDo.vue @@ -42,6 +42,7 @@ export default { }, data () { return { + id: this.toDo.data.to_do_id, edit: false, checked: !!(this.toDo.data.attributes.data.checked_at), } @@ -52,7 +53,6 @@ export default { axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.toDo.data.to_do_id, {name: this.toDo.data.attributes.data.name }) .then(() => { this.edit = false - //this.toDoList.data.attributes.data.name = this.listName }) .catch(errorRes => { console.log('Internal Error, Unable to delete list.' + errorRes) @@ -61,16 +61,22 @@ export default { }, watch: { checked: function () { - // eslint-disable-next-line no-undef - axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.toDo.data.to_do_id + '/check') - .then(res => { - // this.toDoList.data.attributes.data.to_dos.data[position].data.attributes.data.checked_at = res.data.data.attributes.data.checked_at - this.toDo.data.attributes.data.checked_at = res.data.data.attributes.data.checked_at - this.checked = !!(res.data.data.attributes.data.checked_at) - }) - .catch(errorRes => { - console.log('Internal Error, Unable to delete contact.' + errorRes) - }) + if(event && event.type === 'click') { + // eslint-disable-next-line no-undef + axios.patch('/api/to-do-lists/' + this.idList + '/to-do/' + this.toDo.data.to_do_id + '/check') + .then(res => { + this.toDo.data.attributes.data.checked_at = res.data.data.attributes.data.checked_at + this.checked = !!(res.data.data.attributes.data.checked_at) + }) + .catch(errorRes => { + console.log('Internal Error, Unable to delete contact.' + errorRes) + }) + } + }, + toDo: function () { + if(this.checked !== !!(this.toDo.data.attributes.data.checked_at)) { + this.checked = !!(this.toDo.data.attributes.data.checked_at) + } } } } diff --git a/resources/js/views/ToDoLists/ToDoListShow.vue b/resources/js/views/ToDoLists/ToDoListShow.vue index 164c1ef..c3d3b6d 100644 --- a/resources/js/views/ToDoLists/ToDoListShow.vue +++ b/resources/js/views/ToDoLists/ToDoListShow.vue @@ -43,6 +43,7 @@ @@ -87,7 +88,7 @@ export default { this.toDoList = res.data this.loading = false this.listName = res.data.data.attributes.data.name - this.reorderList() + this.sortList() }) .catch(errorRes => { this.loading = false @@ -120,11 +121,14 @@ export default { console.log('Internal Error, Unable to delete contact.' + errorRes) }) }, - reorderList() { + sortList() { this.toDoList.data.attributes.data.to_dos.data.sort(function(a, b) { return a.data.attributes.data.order - b.data.attributes.data.order }) }, + reorderList() { + this.sortList() + }, addToDo: function () { if(this.toDoName.length >= 3) { // eslint-disable-next-line no-undef