Skip to content

Commit

Permalink
Simplify Logic for Scrolling Up on Discover Filter Change
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Jul 7, 2023
1 parent 10e13f7 commit 949edb9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/routes/Discover/Discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const Discover = ({ urlParams, queryParams }) => {
const [inputsModalOpen, openInputsModal, closeInputsModal] = useBinaryState(false);
const [addonModalOpen, openAddonModal, closeAddonModal] = useBinaryState(false);
const [selectedMetaItemIndex, setSelectedMetaItemIndex] = React.useState(0);
const metasContainerRef = React.useRef(null);
const metasContainerRef = React.useRef();
React.useEffect(() => {
if (discover.catalog?.content.type === 'Loading') {
metasContainerRef.current.scrollTop = 0;
}
}, [discover.catalog]);
const selectedMetaItem = React.useMemo(() => {
return discover.catalog !== null &&
discover.catalog.content.type === 'Ready' &&
Expand Down Expand Up @@ -76,11 +81,6 @@ const Discover = ({ urlParams, queryParams }) => {
closeAddonModal();
setSelectedMetaItemIndex(0);
}, [discover.selected]);
const scrollUpOnChange = React.useCallback((onSelect, event) => {
if ((metasContainerRef || {}).current || {})
metasContainerRef.current.scrollTo(0, 0);
onSelect(event);
}, []);
return (
<MainNavBars className={styles['discover-container']} route={'discover'}>
<div className={styles['discover-content']}>
Expand All @@ -94,7 +94,7 @@ const Discover = ({ urlParams, queryParams }) => {
options={options}
selected={selected}
renderLabelText={renderLabelText}
onSelect={scrollUpOnChange.bind(null, onSelect)}
onSelect={onSelect}
/>
))}
<Button className={styles['filter-container']} title={'All filters'} onClick={openInputsModal}>
Expand Down Expand Up @@ -128,7 +128,7 @@ const Discover = ({ urlParams, queryParams }) => {
</div>
:
discover.catalog.content.type === 'Loading' ?
<div className={classnames(styles['meta-items-container'], 'animation-fade-in')}>
<div ref={metasContainerRef} className={classnames(styles['meta-items-container'], 'animation-fade-in')}>
{Array(CONSTANTS.CATALOG_PAGE_SIZE).fill(null).map((_, index) => (
<div key={index} className={styles['meta-item-placeholder']}>
<div className={styles['poster-container']} />
Expand All @@ -139,7 +139,7 @@ const Discover = ({ urlParams, queryParams }) => {
))}
</div>
:
<div className={classnames(styles['meta-items-container'], 'animation-fade-in')} ref={metasContainerRef} onScroll={onScroll} onFocusCapture={metaItemsOnFocusCapture}>
<div ref={metasContainerRef} className={classnames(styles['meta-items-container'], 'animation-fade-in')} onScroll={onScroll} onFocusCapture={metaItemsOnFocusCapture}>
{discover.catalog.content.content.map((metaItem, index) => (
<MetaItem
key={index}
Expand Down Expand Up @@ -192,7 +192,7 @@ const Discover = ({ urlParams, queryParams }) => {
options={options}
selected={selected}
renderLabelText={renderLabelText}
onSelect={scrollUpOnChange.bind(null, onSelect)}
onSelect={onSelect}
/>
))}
</ModalDialog>
Expand Down

0 comments on commit 949edb9

Please sign in to comment.