Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

clean up and document implementation

Jason Kent4115e4903803
diff --git a/web/js/components/util/scrollbar.js b/web/js/components/util/scrollbar.js
index 14403cdf4..d2c59a440 100644
--- a/web/js/components/util/scrollbar.js
+++ b/web/js/components/util/scrollbar.js
@@ -2,31 +2,44 @@ import React, { useRef, useLayoutEffect } from 'react';
import PropTypes from 'prop-types';
import SimpleBarReact from 'simplebar-react';
+/**
+ * Wrapper component for SimpleBar
+ * @param {number} props.scrollBarVerticalTop - location to scroll to
+ */
export default function Scrollbars(props) {
const ref = useRef();
- let scrollbarVisible;
- useLayoutEffect(() => {
- if (!ref || !ref.current) {
- return;
+ /**
+ * Add/remove the scrollbar-visible class if content is overflowing
+ * @param {*} simpleBar
+ */
+ const toggleVisibleClass = (simpleBar) => {
+ const { contentEl, contentWrapperEl } = simpleBar;
+ if (contentEl.offsetHeight > contentWrapperEl.offsetHeight) {
+ contentEl.classList.add('scrollbar-visible');
+ } else {
+ contentEl.classList.remove('scrollbar-visible');
}
- // if (ref.current.recalculate) {
- // // TODO do we need to recalculate??
- // ref.current.recalculate();
- // }
+ };
- const { contentEl, contentWrapperEl } = ref.current;
- if (contentEl) {
+ /**
+ * Set the scrollTop position based on props.scrollBarVerticalTop
+ * @param {*} simpleBar
+ */
+ const setScrollTop = (simpleBar) => {
+ const { contentWrapperEl } = simpleBar;
+ if (contentWrapperEl) {
const verticalTop = Math.floor(props.scrollBarVerticalTop);
- scrollbarVisible = contentEl.offsetHeight > contentWrapperEl.offsetHeight;
contentWrapperEl.scrollTop = verticalTop !== 0 ? verticalTop : 0;
+ }
+ };
- if (scrollbarVisible) {
- contentEl.classList.add('scrollbar-visible');
- } else {
- contentEl.classList.remove('scrollbar-visible');
- }
+ useLayoutEffect(() => {
+ if (!ref || !ref.current) {
+ return;
}
+ toggleVisibleClass(ref.current);
+ setScrollTop(ref.current);
});
return (