mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-08-18 09:27:02 +00:00
Merge pull request #1353 from Stremio/fix/discover-pagination
fix: stop repeated Discover auto-pagination
This commit is contained in:
commit
dc02d8ea2a
1 changed files with 11 additions and 2 deletions
|
|
@ -38,21 +38,30 @@ const Discover = () => {
|
|||
|
||||
const metasContainerRef = React.useRef();
|
||||
const metaPreviewRef = React.useRef();
|
||||
const previousCatalogSizeRef = React.useRef(0);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (discover.catalog?.content.type === 'Loading') {
|
||||
metasContainerRef.current.scrollTop = 0;
|
||||
previousCatalogSizeRef.current = 0;
|
||||
}
|
||||
}, [discover.catalog]);
|
||||
React.useEffect(() => {
|
||||
if (hasNextPage && metasContainerRef.current) {
|
||||
if (discover.catalog?.content.type === 'Ready') {
|
||||
const catalogSize = discover.catalog.content.content.length;
|
||||
const hasNewItems = catalogSize > previousCatalogSizeRef.current;
|
||||
previousCatalogSizeRef.current = catalogSize;
|
||||
if (!hasNextPage || !hasNewItems || !metasContainerRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const containerHeight = metasContainerRef.current.scrollHeight;
|
||||
const viewportHeight = metasContainerRef.current.clientHeight;
|
||||
if (containerHeight <= viewportHeight + SCROLL_TO_BOTTOM_THRESHOLD) {
|
||||
loadNextPage();
|
||||
}
|
||||
}
|
||||
}, [hasNextPage, loadNextPage]);
|
||||
}, [discover.catalog, hasNextPage, loadNextPage]);
|
||||
const addToLibrary = React.useCallback(() => {
|
||||
if (selectedMetaItem === null) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue