Skip to content

Commit 8b6373a

Browse files
committed
Fix month selection
The CDX fetch should happen asynchronously when the month state has been updated.
1 parent 81748e2 commit 8b6373a

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/components/ymd-timestamp-header.jsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export default class YmdTimestampHeader extends React.Component {
4747

4848
this.timestampSelectLeft = React.createRef();
4949
this.timestampSelectRight = React.createRef();
50-
this.monthSelectLeft = React.createRef();
51-
this.monthSelectRight = React.createRef();
5250

5351
this.state = {
5452
timestampA,
@@ -128,7 +126,6 @@ export default class YmdTimestampHeader extends React.Component {
128126
{this.state.yearOptions}
129127
</select>
130128
<select className="form-control input-sm mr-sm-1 month-select month-select-left"
131-
ref={this.monthSelectLeft}
132129
onChange={this._handleMonthChange} title="Months and available captures"
133130
value={this.state.leftMonth}>
134131
<option value="" disabled>Month</option>
@@ -162,7 +159,6 @@ export default class YmdTimestampHeader extends React.Component {
162159
</select>
163160
}
164161
<select className="form-control input-sm mr-sm-1 month-select month-select-right"
165-
ref={this.monthSelectRight}
166162
onChange={this._handleMonthChange} title="Months and available captures"
167163
value={this.state.rightMonth}>
168164
<option value="" disabled>Month</option>
@@ -232,9 +228,9 @@ export default class YmdTimestampHeader extends React.Component {
232228
.catch(error => { this._errorHandled(error.message); });
233229
};
234230

235-
_getMonth = (currentMonth, monthSelectRef, timestamp) => {
236-
if (currentMonth !== '' && monthSelectRef.current) {
237-
return monthSelectRef.current.value;
231+
_getMonth = (currentMonth, timestamp) => {
232+
if (currentMonth !== '') {
233+
return currentMonth;
238234
} else if (timestamp) {
239235
return timestamp.substring(4, 6);
240236
}
@@ -246,10 +242,8 @@ export default class YmdTimestampHeader extends React.Component {
246242
* aren't rendered yet.
247243
*/
248244
_fetchCDXData = () => {
249-
const leftMonth = this._getMonth(this.state.leftMonth, this.monthSelectLeft, this.state.timestampA);
250-
const rightMonth = this._getMonth(this.state.rightMonth, this.monthSelectRight, this.state.timestampB);
251-
252-
this.setState({ leftMonth, rightMonth });
245+
const leftMonth = this._getMonth(this.state.leftMonth, this.state.timestampA);
246+
const rightMonth = this._getMonth(this.state.rightMonth, this.state.timestampB);
253247

254248
const leftFetchPromise = leftMonth !== '' ? this.fetchYearMonthCaptures(this.state.leftYear, leftMonth) : null;
255249
const rightFetchPromise = rightMonth !== '' ? this.fetchYearMonthCaptures(this.state.rightYear, rightMonth) : null;
@@ -303,11 +297,9 @@ export default class YmdTimestampHeader extends React.Component {
303297
const { timestampA, timestampB, leftSnaps, rightSnaps } = this.state;
304298
if (!isEmpty(leftSnaps) && timestampA) {
305299
this.timestampSelectLeft.current.value = timestampA;
306-
this.monthSelectLeft.current.value = this.state.leftMonth;
307300
}
308301
if (!isEmpty(rightSnaps) && timestampB) {
309302
this.timestampSelectRight.current.value = timestampB;
310-
this.monthSelectRight.current.value = this.state.rightMonth;
311303
}
312304

313305
if (this.state.sparkline && !this.state.leftMonthOptions && !this.state.rightMonthOptions) {
@@ -376,16 +368,19 @@ export default class YmdTimestampHeader extends React.Component {
376368
_handleMonthChange = (e) => {
377369
if (e.target.className.includes('left')) {
378370
this.setState({
379-
timestampA: null,
371+
leftMonth: e.target.value,
380372
leftSnaps: null
373+
}, () => {
374+
this._fetchCDXData();
381375
});
382376
} else {
383377
this.setState({
384-
timestampB: null,
378+
rightMonth: e.target.value,
385379
rightSnaps: null
380+
}, () => {
381+
this._fetchCDXData();
386382
});
387383
}
388-
this._fetchCDXData();
389384
};
390385

391386
_handleYearChange = (e) => {

0 commit comments

Comments
 (0)