Skip to content

Commit c9d9250

Browse files
committed
fix: Prevent expensive map effects from running on every render
1 parent c2db235 commit c9d9250

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

src/App.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class App extends React.Component {
6161
selectedRowIndexPerDataset: [-1, -1, -1, -1, -1],
6262
currentLogData: this.props.logData,
6363
dynamicMarkerLocations: {},
64+
visibleToggles: getVisibleToggles(this.props.logData.solutionType),
6465
};
6566
this.onSliderChangeDebounced = _.debounce((timeRange) => this.onSliderChange(timeRange), 25);
6667
this.setFeaturedObject = this.setFeaturedObject.bind(this);
@@ -696,20 +697,21 @@ class App extends React.Component {
696697
const data = await getUploadedData(index);
697698
if (data && data.rawLogs && Array.isArray(data.rawLogs) && data.rawLogs.length > 0) {
698699
const tripLogs = new TripLogs(data.rawLogs, data.solutionType);
700+
const newVisibleToggles = getVisibleToggles(data.solutionType);
701+
699702
this.setState(
700-
(prevState) => {
701-
return {
702-
activeDatasetIndex: index,
703-
timeRange: { minTime: tripLogs.minDate.getTime(), maxTime: tripLogs.maxDate.getTime() },
704-
initialMapBounds: data.bounds,
705-
currentLogData: {
706-
...prevState.currentLogData,
707-
tripLogs: tripLogs,
708-
solutionType: data.solutionType,
709-
},
710-
dynamicMarkerLocations: {}, // Clear markers when switching datasets
711-
};
712-
},
703+
(prevState) => ({
704+
activeDatasetIndex: index,
705+
timeRange: { minTime: tripLogs.minDate.getTime(), maxTime: tripLogs.maxDate.getTime() },
706+
initialMapBounds: data.bounds,
707+
currentLogData: {
708+
...prevState.currentLogData,
709+
tripLogs: tripLogs,
710+
solutionType: data.solutionType,
711+
},
712+
visibleToggles: newVisibleToggles,
713+
dynamicMarkerLocations: {}, // Clear markers when switching datasets
714+
}),
713715
() => {
714716
log(`Switched to dataset ${index}`);
715717
log(`New time range: ${tripLogs.minDate} - ${tripLogs.maxDate}`);
@@ -768,10 +770,16 @@ class App extends React.Component {
768770
}
769771

770772
render() {
771-
const { featuredObject, timeRange, currentLogData, toggleOptions, extraColumns, dynamicMarkerLocations } =
772-
this.state;
773+
const {
774+
featuredObject,
775+
timeRange,
776+
currentLogData,
777+
toggleOptions,
778+
extraColumns,
779+
dynamicMarkerLocations,
780+
visibleToggles,
781+
} = this.state;
773782
const selectedEventTime = featuredObject?.timestamp ? new Date(featuredObject.timestamp).getTime() : null;
774-
const visibleToggles = getVisibleToggles(currentLogData.solutionType);
775783

776784
return (
777785
<div className="app-container">

0 commit comments

Comments
 (0)