From 3f297e6293e33f19c62e22b6be29e392bd2607d8 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 9 May 2024 15:05:15 +0200 Subject: [PATCH] Task lists WIP: * partial fix for task edit form disapperaing when task are sorted --- .../custom/plugins/tasks/muc-task-view.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/conversejs/custom/plugins/tasks/muc-task-view.js b/conversejs/custom/plugins/tasks/muc-task-view.js index 1b466d82..05867184 100644 --- a/conversejs/custom/plugins/tasks/muc-task-view.js +++ b/conversejs/custom/plugins/tasks/muc-task-view.js @@ -26,6 +26,22 @@ export default class MUCTaskView extends CustomElement { return tplMucTask(this, this.model) } + shouldUpdate (changedProperties) { + if (!super.shouldUpdate(...arguments)) { return false } + // When a task is currently edited, and another users change the order, + // it could refresh losing the current form. + // To avoid this, we cancel update here. + // Note: of course, if 'edit' is part of the edited properties, we must update anyway + // (it means we just leaved the form) + if (this.edit && !changedProperties.has('edit')) { + console.info('Canceling an update on task, because it is currently edited', this) + return false + } + // FIXME: in some case this is not enough. Can't understand exactly why for now. + // probably because of some of the requestUpdate on the task-list or task-lists. + return true + } + async saveTask (ev) { ev?.preventDefault?.() @@ -45,6 +61,7 @@ export default class MUCTaskView extends CustomElement { await task.saveItem() this.edit = false + this.requestUpdate() // In case we cancel another update in shouldUpdate } catch (err) { console.error(err) } finally {