Skip to content

Commit

Permalink
fix: #2391 Add default threshold for apps infinite scroll (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Nguyen authored Aug 20, 2020
1 parent 0cd3f3d commit f84a2ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`Client should match a snapshot when LOADING false 1`] = `
hasMore={false}
loader={<Unknown />}
next={[Function]}
scrollThreshold="0px"
scrollThreshold={0.5}
scrollableTarget="app-root-container"
>
<div
Expand Down Expand Up @@ -442,7 +442,7 @@ exports[`Client should match a snapshot when LOADING false 2`] = `
hasMore={false}
loader={<Unknown />}
next={[Function]}
scrollThreshold="0px"
scrollThreshold={0.5}
scrollableTarget="app-root-container"
>
<div
Expand Down
6 changes: 5 additions & 1 deletion packages/marketplace/src/components/pages/apps/apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { getNumberOfItems } from '@/utils/browse-app'
import ComingSoonApps from './coming-soon'
import styles from '@/styles/pages/apps.scss?mod'

const DEFAULT_SCROLL_THRESHOLD = 0.5

export const handleAfterClose = ({ setVisible }) => () => setVisible(false)
export const handleOnChange = history => (page: number) => {
history.push(addQuery({ page }))
Expand Down Expand Up @@ -100,7 +102,9 @@ export const Apps: React.FunctionComponent = () => {
next={handleLoadMore({ dispatch, preview, loading, numOfItemsPerPage, pageNumber })}
hasMore={hasMore}
loader={<Loader key="infiniteScrollLoader" />}
scrollThreshold={`${comingSoonAppSectionHeight}px`}
scrollThreshold={
comingSoonAppSectionHeight > 0 ? `${comingSoonAppSectionHeight}px` : DEFAULT_SCROLL_THRESHOLD
}
// We disable the scrolling in the app list container and allow the app root container to scroll
// so the scrollableTarget must be set as app-root-container
scrollableTarget="app-root-container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ const comingSoonImagesList = [
]

export const handleSetComingSoonAppSectionHeight = (
containerHeight: number,
setComingSoonAppSectionHeight: React.Dispatch<React.SetStateAction<number>> | undefined,
containerHeight?: number,
setComingSoonAppSectionHeight?: React.Dispatch<React.SetStateAction<number>> | undefined,
) => {
return () => {
if (setComingSoonAppSectionHeight) {
if (containerHeight && setComingSoonAppSectionHeight) {
setComingSoonAppSectionHeight(containerHeight)
}
}
}

const ComingSoonApps: React.FC<ComingSoonAppsProps> = ({ setComingSoonAppSectionHeight }) => {
const containerRef = React.useRef<HTMLDivElement>(null)
const containerHeight = containerRef.current?.clientHeight || 0
const containerHeight = containerRef.current?.clientHeight

React.useEffect(handleSetComingSoonAppSectionHeight(containerHeight, setComingSoonAppSectionHeight), [
containerHeight,
Expand Down

0 comments on commit f84a2ff

Please sign in to comment.