@tap-payments/os-micro-frontend-shared 0.0.285-test.1 → 0.0.285-test.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,34 +10,55 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
13
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
14
14
|
import Stack from '@mui/material/Stack';
|
|
15
15
|
const OFFSET = 50;
|
|
16
|
+
const isNearBottom = (el, offset = OFFSET) => {
|
|
17
|
+
const scrollBottom = el.scrollTop + el.clientHeight;
|
|
18
|
+
const scrollHeight = el.scrollHeight;
|
|
19
|
+
return scrollHeight - scrollBottom <= offset;
|
|
20
|
+
};
|
|
16
21
|
const ScrollLoader = (props) => {
|
|
17
22
|
const { component = Stack, loadMoreItems, hasMore, loading, children } = props, rootProps = __rest(props, ["component", "loadMoreItems", "hasMore", "loading", "children"]);
|
|
23
|
+
const [initialChecked, setInitialChecked] = useState(false);
|
|
18
24
|
const loadMoreItemsRef = useRef(loadMoreItems);
|
|
25
|
+
const containerRef = useRef(null);
|
|
19
26
|
loadMoreItemsRef.current = loadMoreItems;
|
|
20
27
|
const Component = component;
|
|
21
|
-
const containerRef = useRef(null);
|
|
22
28
|
const handleScroll = useCallback(() => {
|
|
23
29
|
const el = containerRef.current;
|
|
24
30
|
if (!el || loading || !hasMore)
|
|
25
31
|
return;
|
|
26
|
-
const isBottom = el
|
|
32
|
+
const isBottom = isNearBottom(el);
|
|
27
33
|
if (isBottom)
|
|
28
34
|
loadMoreItemsRef.current();
|
|
29
35
|
}, [loading, hasMore]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const el = containerRef.current;
|
|
38
|
+
if (!el)
|
|
39
|
+
return;
|
|
40
|
+
el.addEventListener('scroll', handleScroll);
|
|
41
|
+
return () => el.removeEventListener('scroll', handleScroll);
|
|
42
|
+
}, [handleScroll]);
|
|
30
43
|
useEffect(() => {
|
|
31
44
|
const el = containerRef.current;
|
|
32
45
|
if (!el || loading)
|
|
33
46
|
return;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
const timeout = setTimeout(() => {
|
|
48
|
+
const isBottom = isNearBottom(el);
|
|
49
|
+
if (isBottom && !initialChecked) {
|
|
50
|
+
loadMoreItemsRef.current();
|
|
51
|
+
setInitialChecked(true);
|
|
52
|
+
}
|
|
53
|
+
}, 2000);
|
|
54
|
+
return () => {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
};
|
|
57
|
+
}, [loading, initialChecked]);
|
|
58
|
+
return (_jsx(Component, Object.assign({ overflow: "auto", ref: containerRef, style: {
|
|
39
59
|
overflow: 'auto',
|
|
40
60
|
height: '100%',
|
|
61
|
+
maxHeight: '100%',
|
|
41
62
|
} }, rootProps, { children: children })));
|
|
42
63
|
};
|
|
43
64
|
export default ScrollLoader;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.0.285-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.0.285-test.2",
|
|
5
|
+
"testVersion": 2,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|