1- import { _converse , api , converse , parsers } from '@converse/headless' ;
1+ import { default as Collapse } from 'bootstrap/js/src/collapse.js' ;
2+ import { _converse , api , converse , parsers , u } from '@converse/headless' ;
23import BaseModal from 'plugins/modal/modal.js' ;
3- import tplAddTodo from './templates/add-todo-modal.js' ;
44import { __ } from 'i18n' ;
5+ import tplAddTodo from './templates/add-todo-modal.js' ;
56
67const { Strophe } = converse . env ;
78
89export default class AddTodoModal extends BaseModal {
10+ static get properties ( ) {
11+ return {
12+ ...super . properties ,
13+ _manual_jid : { state : true , type : Boolean } ,
14+ _entities : { state : true , type : Array } ,
15+ } ;
16+ }
17+
918 initialize ( ) {
1019 super . initialize ( ) ;
1120 this . requestUpdate ( ) ;
@@ -18,6 +27,14 @@ export default class AddTodoModal extends BaseModal {
1827 ) ;
1928 }
2029
30+ /**
31+ * @param {import('lit').PropertyValues } changed
32+ */
33+ firstUpdated ( changed ) {
34+ super . firstUpdated ( changed ) ;
35+ this . collapse = new Collapse ( /** @type {HTMLElement } */ ( this ) ) ;
36+ }
37+
2138 renderModal ( ) {
2239 return tplAddTodo ( this ) ;
2340 }
@@ -36,19 +53,21 @@ export default class AddTodoModal extends BaseModal {
3653 const name = data . get ( 'name' ) ;
3754 const jid = data . get ( 'jid' ) ?? _converse . state . session . get ( 'domain' ) ;
3855
39- const service_jids = await api . disco . entities . find ( Strophe . NS . PUBSUB , jid ) ;
40- if ( service_jids . length === 0 ) {
56+ const entities = await api . disco . entities . find ( Strophe . NS . PUBSUB , jid ) ;
57+ if ( entities . length === 0 ) {
4158 this . alert ( __ ( 'Could not find a PubSub service to host your todo list' ) , 'danger' ) ;
42- this . state . set ( { manual_jid : true } ) ;
59+ this . _manual_jid = true ;
4360 return ;
44- } else if ( service_jids . length > 1 ) {
61+ } else if ( entities . length > 1 ) {
4562 this . alert ( __ ( 'Found multiple possible PubSub services to host your todo list, please choose one.' ) ) ;
46- this . state . set ( { services : service_jids , manual_jid : true } ) ;
63+
64+ this . _entities = entities ;
65+ this . _manual_jid = true ;
4766 return ;
4867 }
4968
5069 try {
51- await api . pubsub . create ( service_jids [ 0 ] . get ( 'jid' ) , name ) ;
70+ await api . pubsub . create ( entities [ 0 ] . get ( 'jid' ) , u . getUniqueId ( ) , { title : name } ) ;
5271 } catch ( e ) {
5372 const err = await parsers . parseErrorStanza ( e ) ;
5473 this . alert ( __ ( 'Sorry, an error occurred: %s' , err . message ) , 'danger' ) ;
0 commit comments