@@ -52,11 +52,19 @@ function reportToServer(data) {
5252 return fetch ( url , { method : 'POST' , body : JSON . stringify ( data ) } )
5353}
5454
55+ const messages = {
56+ 'init' : 'Report' ,
57+ 'collecting' : 'Collecting data…' ,
58+ 'reporting' : 'Reporting data…' ,
59+ 'done' : 'Thanks!' ,
60+ 'error' : 'Try again?' ,
61+ }
62+
5563type Props = { }
5664
5765type State = {
5866 error : ?string ,
59- status : 'init' | 'collecting' | 'reporting' | 'done' | 'error' ,
67+ status : $Keys < typeof messages > ,
6068}
6169
6270export class ReportWifiProblemView extends React . Component < Props , State > {
@@ -84,24 +92,10 @@ export class ReportWifiProblemView extends React.Component<Props, State> {
8492 }
8593
8694 render ( ) {
95+ const buttonMessage = messages [ this . state . status ] || 'Error'
8796 const buttonEnabled =
8897 this . state . status === 'init' || this . state . status === 'error'
8998
90- let buttonMessage = 'Error'
91- if ( this . state . status === 'init' ) {
92- buttonMessage = 'Report'
93- } else if ( this . state . status === 'collecting' ) {
94- buttonMessage = 'Collecting data…'
95- } else if ( this . state . status === 'reporting' ) {
96- buttonMessage = 'Reporting data…'
97- } else if ( this . state . status === 'done' ) {
98- buttonMessage = 'Thanks!'
99- } else if ( this . state . status === 'error' ) {
100- buttonMessage = 'Try again?'
101- } else {
102- ; ( this . state . status : empty )
103- }
104-
10599 return (
106100 < Card style = { styles . card } >
107101 < Title selectable = { true } > Report a Wi-Fi Problem</ Title >
0 commit comments