Fix new task order + fix notes order.

This commit is contained in:
John Livingston 2024-07-30 16:04:12 +02:00
parent fbc9a39485
commit 1c749f68bc
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
4 changed files with 14 additions and 5 deletions

View File

@ -15,6 +15,7 @@
* New translation: Albanian.
* Translation updates: Crotian, Japanese.
* Updated mod_muc_moderation to upstream.
* Fix new task ordering.
## 10.3.3

View File

@ -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)
}
}

View File

@ -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)))
)

View File

@ -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)))
)