From 1c749f68bc62dfcf462d675f183851c66113b7b0 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 30 Jul 2024 16:04:12 +0200 Subject: [PATCH] Fix new task order + fix notes order. --- CHANGELOG.md | 1 + .../custom/plugins/notes/components/muc-notes-view.js | 6 ++++-- conversejs/custom/plugins/notes/notes.js | 10 ++++++++-- conversejs/custom/plugins/tasks/task-list.js | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9196ae73..017e1625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * New translation: Albanian. * Translation updates: Crotian, Japanese. * Updated mod_muc_moderation to upstream. +* Fix new task ordering. ## 10.3.3 diff --git a/conversejs/custom/plugins/notes/components/muc-notes-view.js b/conversejs/custom/plugins/notes/components/muc-notes-view.js index f7e82a92..ef5c9900 100644 --- a/conversejs/custom/plugins/notes/components/muc-notes-view.js +++ b/conversejs/custom/plugins/notes/components/muc-notes-view.js @@ -107,9 +107,11 @@ export default class MUCNotesView extends DraggablesCustomElement { } let newOrder = targetNote.get('order') ?? 0 - if (!onTopHalf) { newOrder = Math.max(0, newOrder + 1) } + if (onTopHalf) { newOrder = Math.max(0, newOrder + 1) } // reverse order! - this._saveOrders(this.model, note, newOrder) + // Warning: the order of the collection is reversed! + // _saveOrders needs it in ascending order! + this._saveOrders(Array.from(this.model).reverse(), note, newOrder) } } diff --git a/conversejs/custom/plugins/notes/notes.js b/conversejs/custom/plugins/notes/notes.js index e83b2ad9..f957fd36 100644 --- a/conversejs/custom/plugins/notes/notes.js +++ b/conversejs/custom/plugins/notes/notes.js @@ -14,7 +14,6 @@ import { initStorage } from '@converse/headless/utils/storage.js' */ class ChatRoomNotes extends Collection { model = ChatRoomNote - comparator = 'order' initialize (models, options) { this.model = ChatRoomNote // don't know why, must do it again here @@ -27,11 +26,18 @@ class ChatRoomNotes extends Collection { this.on('change:order', () => this.sort()) } + comparator (n1, n2) { + // must reverse order + const o1 = n1.get('order') ?? 0 + const o2 = n2.get('order') ?? 0 + return o1 < o2 ? 1 : o1 > o2 ? -1 : 0 + } + async createNote (data) { data = Object.assign({}, data) if (!data.order) { - data.order = 0 + Math.max( + data.order = 1 + Math.max( 0, ...(this.map(n => n.get('order') ?? 0).filter(o => !isNaN(o))) ) diff --git a/conversejs/custom/plugins/tasks/task-list.js b/conversejs/custom/plugins/tasks/task-list.js index 23a00a0a..09564263 100644 --- a/conversejs/custom/plugins/tasks/task-list.js +++ b/conversejs/custom/plugins/tasks/task-list.js @@ -40,7 +40,7 @@ class ChatRoomTaskList extends Model { data.list = this.get('id') if (!data.order) { - data.order = 0 + Math.max( + data.order = 1 + Math.max( 0, ...(this.getTasks().map(t => t.get('order') ?? 0).filter(o => !isNaN(o))) )