@@ -11,11 +11,28 @@ export default class Autocomplete extends React.Component {
1111 }
1212
1313 componentWillReceiveProps ( props , state ) {
14- getCompletions ( props . query ) [ 0 ] . then ( completions => {
15- console . log ( completions ) ;
16- this . setState ( {
17- completions
18- } ) ;
14+ getCompletions ( props . query ) . map ( completionResult => {
15+ try {
16+ completionResult . completions . then ( completions => {
17+ let i = this . state . completions . findIndex (
18+ completion => completion . provider === completionResult . provider
19+ ) ;
20+
21+ i = i == - 1 ? this . state . completions . length : i ;
22+ console . log ( completionResult ) ;
23+ let newCompletions = Object . assign ( [ ] , this . state . completions ) ;
24+ completionResult . completions = completions ;
25+ newCompletions [ i ] = completionResult ;
26+ console . log ( newCompletions ) ;
27+ this . setState ( {
28+ completions : newCompletions
29+ } ) ;
30+ } , err => {
31+
32+ } ) ;
33+ } catch ( e ) {
34+ // An error in one provider shouldn't mess up the rest.
35+ }
1936 } ) ;
2037 }
2138
@@ -33,18 +50,28 @@ export default class Autocomplete extends React.Component {
3350 } ;
3451
3552 this . props . pinTo . forEach ( direction => {
36- console . log ( `${ direction } = ${ position [ direction ] } ` ) ;
3753 style [ direction ] = position [ direction ] ;
3854 } ) ;
3955
40- const renderedCompletions = this . state . completions . map ( ( completion , i ) => {
41- return (
42- < div key = { i } class = "mx_Autocomplete_Completion" >
43- < strong > { completion . title } </ strong >
44- < em > { completion . subtitle } </ em >
45- < span style = { { color : 'gray' , float : 'right' } } > { completion . description } </ span >
56+ const renderedCompletions = this . state . completions . map ( ( completionResult , i ) => {
57+ console . log ( completionResult ) ;
58+ let completions = completionResult . completions . map ( ( completion , i ) => {
59+ return (
60+ < div key = { i } class = "mx_Autocomplete_Completion" >
61+ < strong > { completion . title } </ strong >
62+ < em > { completion . subtitle } </ em >
63+ < span style = { { color : 'gray' , float : 'right' } } > { completion . description } </ span >
64+ </ div >
65+ ) ;
66+ } ) ;
67+
68+
69+ return completions . length > 0 ? (
70+ < div key = { i } class = "mx_Autocomplete_ProviderSection" >
71+ < strong > { completionResult . provider . getName ( ) } </ strong >
72+ { completions }
4673 </ div >
47- ) ;
74+ ) : null ;
4875 } ) ;
4976
5077 return (
0 commit comments