Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Debounce search #1458

Benjamin Kingf874b5e2686d
diff --git a/web/js/components/layer/header.js b/web/js/components/layer/header.js
index 09e65806a..413071cd6 100644
--- a/web/js/components/layer/header.js
+++ b/web/js/components/layer/header.js
@@ -1,7 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
-import util from '../../util/util';
-
import {
Breadcrumb,
BreadcrumbItem,
@@ -10,6 +8,8 @@ import {
Button
} from 'reactstrap';
+import util from '../../util/util';
+
/*
* A scrollable list of layers
* @class LayerList
@@ -30,15 +30,13 @@ class ProductPickerHeader extends React.Component {
this.props.updateListState('category');
this.setState({ inputValue: '' });
}
+ handleChange(e) {
+ this.props.runSearch(e.target.value);
+ this.setState({ inputValue: e.target.value });
+ }
render() {
const isAutoFocus = !util.browser.touchDevice;
- const {
- modalView,
- runSearch,
- selectedProjection,
- listType,
- category
- } = this.props;
+ const { modalView, selectedProjection, listType, category } = this.props;
const isBreadCrumb =
!modalView &&
selectedProjection === 'geographic' &&
@@ -83,10 +81,7 @@ class ProductPickerHeader extends React.Component {
)}
<Input
- onChange={e => {
- runSearch(e);
- this.setState({ inputValue: e.target.value });
- }}
+ onChange={this.handleChange.bind(this)}
id="layers-search-input"
value={this.state.inputValue}
placeholder="Search"
diff --git a/web/js/components/layer/product-picker.js b/web/js/components/layer/product-picker.js
index 8b2f58303..908b1d82e 100644
--- a/web/js/components/layer/product-picker.js
+++ b/web/js/components/layer/product-picker.js
@@ -6,6 +6,8 @@ import ProductPickerHeader from './header';
import lodashValues from 'lodash/values';
import Scrollbars from '../util/scrollbar';
import googleTagManager from 'googleTagManager';
+import lodashDebounce from 'lodash/debounce';
+
import {
Modal,
ModalBody,
@@ -37,6 +39,7 @@ class ProductPicker extends React.Component {
selectedProjection: props.selectedProjection,
inputValue: ''
};
+ this.runSearch = lodashDebounce(this.runSearch, 100);
}
/**
* Update modal visibility
@@ -55,10 +58,10 @@ class ProductPicker extends React.Component {
* @function runSearch
* @param e | onChange event object
*/
- runSearch(e) {
+ runSearch(value) {
const { filterProjections, filterSearch } = this.props;
const { allLayers } = this.props;
- let val = e.target.value.toLowerCase();
+ let val = value.toLowerCase();
if (val.length === 0) {
this.setState({
@@ -74,7 +77,7 @@ class ProductPicker extends React.Component {
this.setState({
filteredRows: filteredRows,
listType: 'search',
- inputValue: e.target.value
+ inputValue: value
});
}
}