@@ -13,7 +13,7 @@ type GroupOption = {
1313 type : "group" ;
1414 label : string ;
1515 value : string ;
16- }
16+ } ;
1717
1818const groupOption = ( d : Group ) : GroupOption => {
1919 const id = d . id ;
@@ -31,14 +31,14 @@ type MemberOption = {
3131 type : "member" ;
3232 label : string ;
3333 value : string ;
34- }
34+ } ;
3535
3636type CombinedOption = {
37- type : "combined" ,
38- label : string ,
39- value : string ,
40- inner : ( MemberOption | GroupOption ) [ ] ,
41- }
37+ type : "combined" ;
38+ label : string ;
39+ value : string ;
40+ inner : ( MemberOption | GroupOption ) [ ] ;
41+ } ;
4242
4343const memberOption = ( d : Member ) : MemberOption => {
4444 const id = d . member_id ;
@@ -52,9 +52,19 @@ const memberOption = (d: Member): MemberOption => {
5252 } ;
5353} ;
5454
55- const MessageForm = ( { message, onSave, recipientSelect } : { message : Message , onSave : ( ) => void , recipientSelect : boolean } ) => {
55+ const MessageForm = ( {
56+ message,
57+ onSave,
58+ recipientSelect,
59+ } : {
60+ message : Message ;
61+ onSave : ( ) => void ;
62+ recipientSelect : boolean ;
63+ } ) => {
5664 const [ sendDisabled , setSendDisabled ] = useState ( true ) ;
57- const [ recipients , setRecipients ] = useState < ( MemberOption | GroupOption ) [ ] > ( [ ] ) ;
65+ const [ recipients , setRecipients ] = useState <
66+ ( MemberOption | GroupOption ) [ ]
67+ > ( [ ] ) ;
5868 const [ bodyLength , setBodyLength ] = useState ( message . body . length ) ;
5969 const memberCache = React . useRef ( new Map < number , Member > ( ) ) . current ;
6070
@@ -70,7 +80,9 @@ const MessageForm = ({ message, onSave, recipientSelect }: { message: Message, o
7080 useEffect ( ( ) => {
7181 const unsubscribe = message . subscribe ( ( ) => {
7282 setSendDisabled ( ! message . canSave ( ) ) ;
73- setRecipients ( message . recipients as any as ( MemberOption | GroupOption ) [ ] ) ;
83+ setRecipients (
84+ message . recipients as any as ( MemberOption | GroupOption ) [ ] ,
85+ ) ;
7486 setBodyLength ( message . body . length ) ;
7587 } ) ;
7688
@@ -79,20 +91,25 @@ const MessageForm = ({ message, onSave, recipientSelect }: { message: Message, o
7991 } ;
8092 } , [ message ] ) ;
8193
82- const loadOptions = ( inputValue : string , callback : ( options : ( MemberOption | GroupOption | CombinedOption ) [ ] ) => void ) => {
94+ const loadOptions = (
95+ inputValue : string ,
96+ callback : (
97+ options : ( MemberOption | GroupOption | CombinedOption ) [ ] ,
98+ ) => void ,
99+ ) => {
83100 const intListMatch = inputValue . match ( / ^ ( \d + [ \s , ] * ) + $ / ) ;
84101 if ( intListMatch ) {
85102 const ids = inputValue
86103 . split ( / [ \s , ] + / )
87104 . map ( ( v ) => parseInt ( v , 10 ) )
88105 . filter ( ( v ) => ! isNaN ( v ) ) ;
89106 if ( ids . length > 0 ) {
90- Promise . all ( ids . map ( getMember ) ) . then ( members => {
107+ Promise . all ( ids . map ( getMember ) ) . then ( ( members ) => {
91108 const options = members . map ( memberOption ) ;
92109 callback ( [
93110 {
94111 type : "combined" ,
95- label : `${ options . map ( o => o . label ) . join ( ", " ) } ` ,
112+ label : `${ options . map ( ( o ) => o . label ) . join ( ", " ) } ` ,
96113 value : "combined-" + ids . join ( "-" ) ,
97114 inner : options ,
98115 } ,
@@ -119,12 +136,18 @@ const MessageForm = ({ message, onSave, recipientSelect }: { message: Message, o
119136 sort_order : "asc" ,
120137 } ,
121138 } ) ,
122- ] ) . then ( ( [ { data : groups } , { data : members } ] : [ { data : Group [ ] } , { data : Member [ ] } ] ) =>
123- callback (
124- groups
125- . map ( ( d ) => groupOption ( d ) as GroupOption | MemberOption )
126- . concat ( members . map ( ( d ) => memberOption ( d ) ) ) ,
127- ) ,
139+ ] ) . then (
140+ ( [ { data : groups } , { data : members } ] : [
141+ { data : Group [ ] } ,
142+ { data : Member [ ] } ,
143+ ] ) =>
144+ callback (
145+ groups
146+ . map (
147+ ( d ) => groupOption ( d ) as GroupOption | MemberOption ,
148+ )
149+ . concat ( members . map ( ( d ) => memberOption ( d ) ) ) ,
150+ ) ,
128151 ) ;
129152 } ;
130153
@@ -141,7 +164,10 @@ const MessageForm = ({ message, onSave, recipientSelect }: { message: Message, o
141164 Mottagare
142165 </ label >
143166 < div className = "uk-form-controls" >
144- < Async < ( MemberOption | GroupOption | CombinedOption ) , true >
167+ < Async <
168+ MemberOption | GroupOption | CombinedOption ,
169+ true
170+ >
145171 name = "recipients"
146172 isMulti
147173 placeholder = "Type to search for member or group"
@@ -151,7 +177,7 @@ const MessageForm = ({ message, onSave, recipientSelect }: { message: Message, o
151177 value = { recipients }
152178 onChange = { ( values ) => {
153179 const flattened = values . flatMap ( ( v ) =>
154- v . type === "combined" ? v . inner : v
180+ v . type === "combined" ? v . inner : v ,
155181 ) ;
156182 message . recipients = flattened ;
157183 setRecipients ( flattened ) ;
0 commit comments