@@ -16,7 +16,6 @@ limitations under the License.
1616
1717import React from 'react' ;
1818import sdk from 'matrix-react-sdk' ;
19- import submit_rageshake from '../../../vector/submit-rageshake' ;
2019import SdkConfig from 'matrix-react-sdk/lib/SdkConfig' ;
2120
2221export default class BugReportDialog extends React . Component {
@@ -27,11 +26,18 @@ export default class BugReportDialog extends React.Component {
2726 busy : false ,
2827 err : null ,
2928 text : "" ,
29+ progress : null ,
3030 } ;
31+ this . _unmounted = false ;
3132 this . _onSubmit = this . _onSubmit . bind ( this ) ;
3233 this . _onCancel = this . _onCancel . bind ( this ) ;
3334 this . _onTextChange = this . _onTextChange . bind ( this ) ;
3435 this . _onSendLogsChange = this . _onSendLogsChange . bind ( this ) ;
36+ this . _sendProgressCallback = this . _sendProgressCallback . bind ( this ) ;
37+ }
38+
39+ componentWillUnmount ( ) {
40+ this . _unmounted = true ;
3541 }
3642
3743 _onCancel ( ev ) {
@@ -47,15 +53,27 @@ export default class BugReportDialog extends React.Component {
4753 } ) ;
4854 return ;
4955 }
50- this . setState ( { busy : true , err : null } ) ;
51- submit_rageshake ( SdkConfig . get ( ) . bug_report_endpoint_url , {
52- userText : userText ,
53- sendLogs : sendLogs ,
54- } ) . then ( ( ) => {
55- this . setState ( { busy : false } ) ;
56- this . props . onFinished ( false ) ;
57- } , ( err ) => {
58- this . setState ( { busy : false , err : `Failed: ${ err . message } ` } ) ;
56+ this . setState ( { busy : true , progress : null , err : null } ) ;
57+ this . _sendProgressCallback ( "Loading bug report module" ) ;
58+
59+ require ( [ '../../../vector/submit-rageshake' ] , ( s ) => {
60+ s ( SdkConfig . get ( ) . bug_report_endpoint_url , {
61+ userText : userText ,
62+ sendLogs : sendLogs ,
63+ progressCallback : this . _sendProgressCallback ,
64+ } ) . then ( ( ) => {
65+ if ( ! this . _unmounted ) {
66+ this . setState ( { busy : false , progress : null } ) ;
67+ this . props . onFinished ( false ) ;
68+ }
69+ } , ( err ) => {
70+ if ( ! this . _unmounted ) {
71+ this . setState ( {
72+ busy : false , progress : null ,
73+ err : `Failed to send report: ${ err . message } ` ,
74+ } ) ;
75+ }
76+ } ) ;
5977 } ) ;
6078 }
6179
@@ -67,6 +85,13 @@ export default class BugReportDialog extends React.Component {
6785 this . setState ( { sendLogs : ev . target . checked } ) ;
6886 }
6987
88+ _sendProgressCallback ( progress ) {
89+ if ( this . _unmounted ) {
90+ return ;
91+ }
92+ this . setState ( { progress : progress } ) ;
93+ }
94+
7095 render ( ) {
7196 const Loader = sdk . getComponent ( "elements.Spinner" ) ;
7297
@@ -77,15 +102,23 @@ export default class BugReportDialog extends React.Component {
77102 </ div > ;
78103 }
79104
80- const okLabel = this . state . busy ? < Loader /> : 'Send' ;
81-
82105 let cancelButton = null ;
83106 if ( ! this . state . busy ) {
84107 cancelButton = < button onClick = { this . _onCancel } >
85108 Cancel
86109 </ button > ;
87110 }
88111
112+ let progress = null ;
113+ if ( this . state . busy ) {
114+ progress = (
115+ < div className = "progress" >
116+ < Loader />
117+ { this . state . progress } ...
118+ </ div >
119+ ) ;
120+ }
121+
89122 return (
90123 < div className = "mx_BugReportDialog" >
91124 < div className = "mx_Dialog_title" >
@@ -108,15 +141,17 @@ export default class BugReportDialog extends React.Component {
108141 < input type = "checkbox" checked = { this . state . sendLogs }
109142 onChange = { this . _onSendLogsChange } id = "mx_BugReportDialog_logs" />
110143 < label htmlFor = "mx_BugReportDialog_logs" > Send logs</ label >
144+ { progress }
111145 { error }
112146 </ div >
113147 < div className = "mx_Dialog_buttons" >
114148 < button
115149 className = "mx_Dialog_primary danger"
116150 onClick = { this . _onSubmit }
117151 autoFocus = { true }
152+ disabled = { this . state . busy }
118153 >
119- { okLabel }
154+ Send
120155 </ button >
121156
122157 { cancelButton }
0 commit comments