Skip to content

Commit

Permalink
fix: ensure layer loads when dateBefore set early, then moved back late
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Jacombs committed Mar 13, 2023
1 parent 72603b8 commit fa938cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions packages/landing/src/components/daterange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export interface DateRangeState {
export class DateRange extends Component {
state: DateRangeState = { after: minDate, before: maxDate };

private _scheduled: number | NodeJS.Timeout | undefined;
private _raf = 0;

get yearAfter(): string | undefined {
return this.state.after?.slice(0, 4);
}
Expand All @@ -23,19 +20,6 @@ export class DateRange extends Component {
return this.state.before?.slice(0, 4);
}

private scheduleUpdateConfig(): void {
if (this._scheduled != null || this._raf !== 0) return;
this._scheduled = setTimeout(() => {
this._scheduled = undefined;
this._raf = requestAnimationFrame(this.updateConfig);
}, 200);
}

updateConfig = (): void => {
this._raf = 0;
Config.map.setFilterDateRange(this.state.after, this.state.before);
};

handleChange = (event: React.ChangeEvent<HTMLInputElement>, id: 'before' | 'after'): void => {
switch (id) {
case 'after':
Expand All @@ -45,7 +29,9 @@ export class DateRange extends Component {
this.setState({ before: `${event.target.value}-12-31T23:59:59.999Z` });
break;
}
this.scheduleUpdateConfig();
Config.map.dateRange.dateAfter = this.state.dateAfter;
Config.map.dateRange.dateBefore = this.state.dateBefore;
Config.map.emit('dateRange', this.state);
};

render(): ReactNode {
Expand Down
2 changes: 1 addition & 1 deletion packages/landing/src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Basemaps extends Component<unknown, { isLayerSwitcherEnabled: boole
};

updateVisibleLayers = (newLayers: string): void => {
if (!Config.map.visibleLayers) Config.map.visibleLayers = newLayers;
if (Config.map.visibleLayers === undefined) Config.map.visibleLayers = newLayers;
if (newLayers !== Config.map.visibleLayers) {
Config.map.visibleLayers = newLayers;
const newStyleId =
Expand Down

0 comments on commit fa938cf

Please sign in to comment.