From 2c6ec6ec35977e065b4c6961c7948a4dc3b88ab6 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 3 Oct 2020 14:30:26 +0200 Subject: [PATCH] Fix due date changes not saved on mobile --- src/models/task.js | 9 +++++ src/views/tasks/TaskDetailView.vue | 61 +++++++++++++++++------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/models/task.js b/src/models/task.js index 8d65b334e..c8a07d197 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -142,6 +142,11 @@ export default class TaskModel extends AbstractModel { return } + if (typeof navigator.serviceWorker === 'undefined') { + console.debug('Service Worker not available') + return + } + const registration = await navigator.serviceWorker.getRegistration() if (typeof registration === 'undefined') { return @@ -157,6 +162,10 @@ export default class TaskModel extends AbstractModel { } async scheduleNotification(date) { + if (typeof navigator.serviceWorker === 'undefined') { + console.debug('Service Worker not available') + return + } if (date < new Date()) { console.debug('Date is in the past, not scheduling a notification. Date is ', date) diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index 59c12aeaf..14e22c395 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -9,8 +9,14 @@ {{ task.identifier }}
Done
-

{{ task.title }}

+

+ {{ task.title }} +

{{ parent.namespace.title }} > @@ -552,32 +558,35 @@ export default { return } - this.task.dueDate = this.dueDate - this.task.hexColor = this.taskColor + // We're doing the whole update in a nextTick because sometimes race conditions can occur when + // setting the due date on mobile which leads to no due date change being saved. + this.$nextTick(() => { + this.task.dueDate = this.dueDate + this.task.hexColor = this.taskColor - // If no end date is being set, but a start date and due date, - // use the due date as the end date - if (this.task.endDate === null && this.task.startDate !== null && this.task.dueDate !== null) { - this.task.endDate = this.task.dueDate - } + // If no end date is being set, but a start date and due date, + // use the due date as the end date + if (this.task.endDate === null && this.task.startDate !== null && this.task.dueDate !== null) { + this.task.endDate = this.task.dueDate + } - this.$store.dispatch('tasks/update', this.task) - .then(r => { - this.$set(this, 'task', r) - let actions = [] - if (undoCallback !== null) { - actions = [{ - title: 'Undo', - callback: undoCallback, - }] - this.success({message: 'The task was saved successfully.'}, this, actions) - } - this.dueDate = this.task.dueDate - this.setActiveFields() - }) - .catch(e => { - this.error(e, this) - }) + this.$store.dispatch('tasks/update', this.task) + .then(r => { + this.$set(this, 'task', r) + let actions = [] + if (undoCallback !== null) { + actions = [{ + title: 'Undo', + callback: undoCallback, + }] + this.success({message: 'The task was saved successfully.'}, this, actions) + } + this.setActiveFields() + }) + .catch(e => { + this.error(e, this) + }) + }) }, setFieldActive(fieldName) { this.activeFields[fieldName] = true