@@ -37,24 +37,27 @@ class App extends Component {
3737 email : null ,
3838 snackBarMessages : [ ] ,
3939 }
40- history . listen ( ( { location, action } ) => this . onHistory ( { location, action } ) )
41- }
42-
43- onHistory ( { location, action } ) {
44- if ( action === Action . Pop ) {
45- const reportUuid = reportUuidFromPath ( location . pathname )
46- this . setState ( { reportUuid : reportUuid , loading : true } , ( ) => this . reload ( ) )
47- }
4840 }
4941
5042 componentDidMount ( ) {
43+ this . unlistenHistory = history . listen ( ( { location, action } ) => {
44+ if ( action !== Action . Pop ) return
45+ this . setState ( { reportUuid : reportUuidFromPath ( location . pathname ) , loading : true } )
46+ } )
5147 this . loginForwardAuth ( )
5248 this . initUserSession ( )
5349 this . connectToNrMeasurementsEventSource ( )
54- this . reload ( )
50+ this . fetchReports ( )
51+ }
52+
53+ componentDidUpdate ( _prevProps , prevState ) {
54+ if ( prevState . reportUuid !== this . state . reportUuid || prevState . reportDate !== this . state . reportDate ) {
55+ this . fetchReports ( )
56+ }
5557 }
5658
5759 componentWillUnmount ( ) {
60+ this . unlistenHistory ( )
5861 this . source . close ( )
5962 }
6063
@@ -72,18 +75,16 @@ class App extends Component {
7275 } ) )
7376 }
7477
75- reload ( json ) {
76- if ( json ) {
77- showURLAvailabilityMessages ( json . availability , ( message ) => this . showMessage ( message ) )
78- this . fieldsWithUrlAvailabilityErrors = json . availability
79- ? json . availability . filter ( ( urlKey ) => urlKey . status_code !== 200 )
80- : null
81- this . checkSession ( json )
82- }
83- this . loadAndSetState ( )
78+ processResponseJSON ( json ) {
79+ showURLAvailabilityMessages ( json . availability , ( message ) => this . showMessage ( message ) )
80+ this . fieldsWithUrlAvailabilityErrors = json . availability
81+ ? json . availability . filter ( ( urlKey ) => urlKey . status_code !== 200 )
82+ : null
83+ this . checkSession ( json )
84+ this . fetchReports ( )
8485 }
8586
86- loadAndSetState ( ) {
87+ fetchReports ( ) {
8788 const reportUuid = this . state . reportUuid
8889 const reportDate = this . state . reportDate
8990 const showErrorMessage = ( error ) =>
@@ -148,19 +149,19 @@ class App extends Component {
148149 date = null
149150 }
150151 history . replace ( { search : toSearchString ( parsed ) } )
151- this . setState ( { reportDate : date , loading : true } , ( ) => this . reload ( ) )
152+ this . setState ( { reportDate : date , loading : true } )
152153 }
153154
154155 openReportsOverview ( ) {
155156 if ( history . location . pathname !== "/" ) {
156157 this . historyPush ( "/" )
157- this . setState ( { reportUuid : "" , loading : true } , ( ) => this . reload ( ) )
158+ this . setState ( { reportUuid : "" , loading : true } )
158159 }
159160 }
160161
161162 openReport ( reportUuid ) {
162163 this . historyPush ( encodeURI ( reportUuid ) )
163- this . setState ( { reportUuid : reportUuid , loading : true } , ( ) => this . reload ( ) )
164+ this . setState ( { reportUuid : reportUuid , loading : true } )
164165 }
165166
166167 historyPush ( target ) {
@@ -179,13 +180,13 @@ class App extends Component {
179180 description : "Successfully reconnected to server" ,
180181 } )
181182 this . setState ( { nrMeasurements : newNrMeasurements , nrMeasurementsStreamConnected : true } , ( ) =>
182- this . reload ( ) ,
183+ this . fetchReports ( ) ,
183184 )
184185 }
185186 } ,
186187 onDelta : ( newNrMeasurements ) => {
187188 if ( newNrMeasurements !== this . state . nrMeasurements ) {
188- this . setState ( { nrMeasurements : newNrMeasurements } , ( ) => this . reload ( ) )
189+ this . setState ( { nrMeasurements : newNrMeasurements } , ( ) => this . fetchReports ( ) )
189190 }
190191 } ,
191192 onError : ( ) => {
@@ -278,7 +279,7 @@ class App extends Component {
278279 nrMeasurements = { this . state . nrMeasurements }
279280 openReport = { ( reportUuid ) => this . openReport ( reportUuid ) }
280281 openReportsOverview = { ( ) => this . openReportsOverview ( ) }
281- reload = { ( json ) => this . reload ( json ) }
282+ reload = { ( json ) => this . processResponseJSON ( json ) }
282283 reportDate = { this . state . reportDate }
283284 reportUuid = { this . state . reportUuid }
284285 reports = { this . state . reports }
0 commit comments