Task lists WIP:

* pubsub manager
* some refactoring
* various fixes
This commit is contained in:
John Livingston
2024-05-03 19:28:26 +02:00
parent e8e8af855d
commit df788473cd
7 changed files with 294 additions and 142 deletions

View File

@ -2,7 +2,6 @@ import { Collection } from '@converse/skeletor/src/collection.js'
import { ChatRoomTaskList } from './task-list'
import { XMLNS_TASKLIST } from './constants'
import { initStorage } from '@converse/headless/utils/storage.js'
import { getUniqueId } from '@converse/headless/utils/core.js'
import { converse, api } from '@converse/headless/core'
const { $build } = converse.env
@ -24,8 +23,6 @@ class ChatRoomTaskLists extends Collection {
initStorage(this, id, 'session')
this.on('change:name', () => this.sort())
this.fetchTasksLists().catch(console.error)
}
comparator (tasklist1, tasklist2) {
@ -35,50 +32,6 @@ class ChatRoomTaskLists extends Collection {
return name1 < name2 ? -1 : name1 > name2 ? 1 : 0
}
create (attrs, options) {
if (attrs instanceof ChatRoomTaskList) {
return super.create(attrs, options)
}
attrs.id ??= getUniqueId()
return super.create(attrs, options)
}
/**
* Requires Task lists from the server.
*/
async fetchTasksLists () {
// TODO: remove these test lines, and subscribe to pubsub.
const taskListsData = [
{
id: 'task-list-1',
name: 'Task List 1'
},
{
id: 'task-list-2',
name: 'Task List 2'
}
]
for (const item of taskListsData) {
let id = item.id
const tasklist = id ? this.get(id) : undefined
if (tasklist) {
tasklist.save({
name: item.name
})
return
}
id ??= getUniqueId()
this.create({
id,
name: item.name
})
}
}
async createTaskList (data) {
const name = data?.name
if (!name) { throw new Error('Missing name') }