diff --git a/components/simple-transfer/src/options-container.js b/components/simple-transfer/src/options-container.js index 8986e4ef8..5bb5b569f 100644 --- a/components/simple-transfer/src/options-container.js +++ b/components/simple-transfer/src/options-container.js @@ -1,11 +1,13 @@ +import { spacers } from '@dhis2/ui-constants' import { CircularLoader } from '@dhis2-ui/loader' import PropTypes from 'prop-types' -import React, { Fragment, useRef } from 'react' +import React, { Fragment, useEffect, useRef } from 'react' import { SimpleTransferOption } from './simple-transfer-option.js' export const OptionsContainer = ({ dataTest, emptyComponent, + onEndReached, highlightedOptions, loading, maxSelections, @@ -14,8 +16,37 @@ export const OptionsContainer = ({ selectionHandler, setHighlightedOptions, }) => { - const optionsRef = useRef(null) + const selectRef = useRef(null) const wrapperRef = useRef(null) + // const resizeCounter = useResizeCounter(wrapperRef.current) + const lastOptionRef = useRef(null) + + useEffect(() => { + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + onEndReached && onEndReached() + } + }) + }, + { + root: wrapperRef.current, + threshold: 1.0, + } + ) + + if (lastOptionRef.current) { + observer.observe(lastOptionRef.current) + } + + return () => { + if (lastOptionRef.current) { + observer.unobserve(lastOptionRef.current) + } + observer.disconnect() + } + }, [options]) return (