Interactive interface for browsing global, full-resolution satellite imagery
working save scroll position to state
Jason Kent58f89d458bac
diff --git a/web/js/components/layer/product-picker/product-picker.js b/web/js/components/layer/product-picker/product-picker.jsindex 7bddfa4e2..eda336448 100644--- a/web/js/components/layer/product-picker/product-picker.js+++ b/web/js/components/layer/product-picker/product-picker.js@@ -32,7 +32,10 @@ import {NavItem,NavLink} from 'reactstrap';-import { updateProductPicker } from '../../../modules/product-picker/actions';+import {+ updateProductPicker,+ updateListScrollTop+} from '../../../modules/product-picker/actions';/** A scrollable list of layers@@ -44,7 +47,8 @@ class ProductPicker extends React.Component {super(props);this.state = {- modalElement: null+ modalElement: null,+ listScrollRef: React.createRef()};this.runSearch = lodashDebounce(this.runSearch, 300);}@@ -285,9 +289,16 @@ class ProductPicker extends React.Component {categoryType,category,selectedMeasurement,- selectedLayer+ selectedLayer,+ listScrollTop,+ updateScrollPosition} = this.props;+ const { listScrollRef } = this.state;+ const debouncedUpdateScroll = lodashDebounce(() => {+ const { scrollTop } = listScrollRef.current.contentWrapperEl;+ updateScrollPosition(scrollTop);+ }, 500);const isSearching = listType === 'search';const listHeight = isMobile && isSearching? selectedLayer@@ -303,6 +314,8 @@ class ProductPicker extends React.Component {? 'layer-list-container browse mobile': 'layer-list-container browse';+ console.log('ahhhhh rendeirng!');+return filteredRows.length || !isSearching ? (<>{ isSearching &&@@ -316,7 +329,11 @@ class ProductPicker extends React.Component {}<div className={containerClass}><div className={listContainerClass}>- <Scrollbars style={{ maxHeight: listHeight - 2 + 'px' }}>+ <Scrollbars+ style={{ maxHeight: listHeight - 2 + 'px' }}+ scrollRef={listScrollRef}+ scrollBarVerticalTop={listScrollTop}+ onScroll={debouncedUpdateScroll}><div className="product-outter-list-case"><LayerListisMobile={isMobile}@@ -505,25 +522,34 @@ ProductPicker.propTypes = {categories: PropTypes.array,category: PropTypes.object,categoryConfig: PropTypes.object,+ categoryType: PropTypes.string,currentMeasureSource: PropTypes.func,drawMeasurements: PropTypes.func,- filterByDate: PropTypes.func,+ filterByAvailable: PropTypes.bool,filteredRows: PropTypes.array,filterProjections: PropTypes.func,filterSearch: PropTypes.func,hasMeasurementSetting: PropTypes.func,hasMeasurementSource: PropTypes.func,height: PropTypes.number,+ inputValue: PropTypes.string,isMobile: PropTypes.bool,layerConfig: PropTypes.object,+ listScrollTop: PropTypes.number,listType: PropTypes.string,measurementConfig: PropTypes.object,measurements: PropTypes.object,+ measurementSourceIndex: PropTypes.number,modalView: PropTypes.string,+ numRowsFilteredOut: PropTypes.number,onToggle: PropTypes.func,removeLayer: PropTypes.func,+ searchResultRows: PropTypes.array,selectedDate: PropTypes.object,+ selectedLayer: PropTypes.object,+ selectedMeasurement: PropTypes.string,selectedProjection: PropTypes.string,+ updateScrollPosition: PropTypes.func,width: PropTypes.number};@@ -543,8 +569,11 @@ const mapDispatchToProps = dispatch => ({onToggle: () => {dispatch(onToggle());},- update: (state) => {- dispatch(updateProductPicker(state));+ updateScrollPosition: (scrollTop) => {+ dispatch(updateListScrollTop(scrollTop));+ },+ update: (partialState) => {+ dispatch(updateProductPicker(partialState));}});@@ -579,6 +608,7 @@ function mapStateToProps(state, ownProps) {activeLayers,selectedProjection: proj.id,listType: productPicker.listType,+ listScrollTop: productPicker.listScrollTop,category: productPicker.category,categoryType: productPicker.categoryType,selectedLayer: productPicker.selectedLayer,diff --git a/web/js/components/util/scrollbar.js b/web/js/components/util/scrollbar.jsindex aad3035b4..cd3b72b38 100644--- a/web/js/components/util/scrollbar.js+++ b/web/js/components/util/scrollbar.js@@ -7,7 +7,7 @@ import SimpleBarReact from 'simplebar-react';* @param {number} props.scrollBarVerticalTop - location to scroll to*/export default function Scrollbars(props) {- const ref = useRef();+ const ref = props.scrollRef || useRef();/*** Add/remove the scrollbar-visible class if content is overflowing@@ -40,14 +40,22 @@ export default function Scrollbars(props) {if (!ref || !ref.current) {return;}+ const { contentWrapperEl } = ref.current;+ if (props.onScroll) {+ contentWrapperEl.addEventListener('scroll', props.onScroll);+ }setTimeout(() => { toggleVisibleClass(ref.current); }, 50);setScrollTop(ref.current);+ return function cleanUp() {+ contentWrapperEl.removeEventListener('scroll', props.onScroll);+ };});return (<SimpleBarReactautoHide={false}style={props.style}+ className={props.className}ref={ref}>{props.children}@@ -57,6 +65,8 @@ export default function Scrollbars(props) {Scrollbars.propTypes = {children: PropTypes.node,+ className: PropTypes.string,+ onScroll: PropTypes.func,scrollBarVerticalTop: PropTypes.number,style: PropTypes.object};diff --git a/web/js/modules/product-picker/actions.js b/web/js/modules/product-picker/actions.jsindex c045e3436..269a9f522 100644--- a/web/js/modules/product-picker/actions.js+++ b/web/js/modules/product-picker/actions.js@@ -1,5 +1,6 @@import {- UPDATE_PRODUCT_PICKER+ UPDATE_PRODUCT_PICKER,+ UPDATE_LIST_SCROLL_TOP} from './constants';export function updateProductPicker(value) {@@ -8,3 +9,10 @@ export function updateProductPicker(value) {value};}++export function updateListScrollTop(value) {+ return {+ type: UPDATE_LIST_SCROLL_TOP,+ value+ };+}diff --git a/web/js/modules/product-picker/constants.js b/web/js/modules/product-picker/constants.jsindex eb4a9ab99..e6fa31da7 100644--- a/web/js/modules/product-picker/constants.js+++ b/web/js/modules/product-picker/constants.js@@ -1 +1,2 @@export const UPDATE_PRODUCT_PICKER = 'PRODUCT_PICKER/UPDATE';+export const UPDATE_LIST_SCROLL_TOP = 'PRODUCT_PICKER/UPDATE_LIST_SCROLL_TOP';diff --git a/web/js/modules/product-picker/reducers.js b/web/js/modules/product-picker/reducers.jsindex 09424ea39..cd225e687 100644--- a/web/js/modules/product-picker/reducers.js+++ b/web/js/modules/product-picker/reducers.js@@ -1,5 +1,6 @@import {- UPDATE_PRODUCT_PICKER+ UPDATE_PRODUCT_PICKER,+ UPDATE_LIST_SCROLL_TOP} from './constants';import { assign as lodashAssign } from 'lodash';@@ -14,7 +15,8 @@ export const productPickerState = {searchResultRows: undefined,numRowsFilteredOut: undefined,inputValue: '',- filterByAvailable: true+ filterByAvailable: true,+ listScrollTop: 0};export function getInitialState(config) {@@ -27,6 +29,10 @@ export function productPickerReducer(state = productPickerState, action) {switch (action.type) {case UPDATE_PRODUCT_PICKER:return lodashAssign({}, state, action.value);+ case UPDATE_LIST_SCROLL_TOP:+ return lodashAssign({}, state, {+ listScrollTop: action.value+ });default:return state;}