@vendorflow/components 2.0.33 → 2.0.37

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.
@@ -77,14 +77,21 @@ var DefaultLoader = (0, react_2.forwardRef)(function (_a, ref) {
77
77
  (0, react_1.jsx)(material_1.CircularProgress, { size: "1.5rem", disableShrink: true })));
78
78
  });
79
79
  function useInfiniteScroll(_a) {
80
+ var _b, _c;
80
81
  var scrollParent = _a.scrollParent, scrollBody = _a.scrollBody, isLoading = _a.isLoading, isFetching = _a.isFetching, isReverse = _a.isReverse, hasNextPage = _a.hasNextPage, fetchNextPage = _a.fetchNextPage;
81
82
  var prevPosition = (0, react_2.useRef)();
82
83
  var observer = (0, react_2.useRef)();
84
+ var hasScrollbar = (0, react_2.useMemo)(function () {
85
+ if (scrollParent.current && scrollBody.current) {
86
+ return scrollBody.current.clientHeight > scrollParent.current.clientHeight;
87
+ }
88
+ return false;
89
+ }, [(_b = scrollParent.current) === null || _b === void 0 ? void 0 : _b.clientHeight, (_c = scrollBody.current) === null || _c === void 0 ? void 0 : _c.clientHeight]);
83
90
  (0, react_2.useEffect)(function () {
84
- if (!isLoading) {
91
+ if (!isLoading && hasScrollbar) {
85
92
  scrollToStart();
86
93
  }
87
- }, [isLoading]);
94
+ }, [isLoading, hasScrollbar]);
88
95
  function scrollToStart() {
89
96
  var _a;
90
97
  var scrollHeight = (scrollBody.current || { scrollHeight: 0 }).scrollHeight;
@@ -93,7 +100,7 @@ function useInfiniteScroll(_a) {
93
100
  }
94
101
  // this callback is used and fired based on the state of the element it is attached to
95
102
  return (0, react_2.useCallback)(function (node) {
96
- if (isFetching) {
103
+ if (isLoading || isFetching) {
97
104
  return;
98
105
  }
99
106
  if (observer.current) {
@@ -120,6 +127,6 @@ function useInfiniteScroll(_a) {
120
127
  }
121
128
  observer.current.observe(node);
122
129
  }
123
- }, [isFetching, isReverse, hasNextPage, fetchNextPage, scrollParent, scrollBody]);
130
+ }, [isLoading, isFetching, isReverse, hasNextPage, fetchNextPage, scrollParent, scrollBody]);
124
131
  }
125
132
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
@@ -15,7 +15,7 @@ export interface ChatInterfaceProps {
15
15
  submitting: boolean;
16
16
  placeholder?: string;
17
17
  hasNextPage?: boolean;
18
- fetchNextPage?: () => Promise<void> | void;
18
+ fetchNextPage?: () => Promise<any> | any;
19
19
  /** Determines if the initial load is happening */
20
20
  isLoading: boolean;
21
21
  /** Determines if a data fetch is happening */
@@ -134,7 +134,7 @@ function ChatInterface() {
134
134
  setTimeout(function () {
135
135
  setMessages(__spreadArray(__spreadArray([], __read(messages), false), __read(generateMessagePage()), false));
136
136
  setFetching(false);
137
- }, 2000);
137
+ }, 1000);
138
138
  }
139
139
  function handleSend(message) {
140
140
  setSubmitting(true);
@@ -154,7 +154,7 @@ function ChatInterface() {
154
154
  }, 500);
155
155
  });
156
156
  }
157
- return ((0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border: 1px solid #ededed;\n height: 20rem;\n "], ["\n border: 1px solid #ededed;\n height: 20rem;\n "]))) },
157
+ return ((0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n border: 1px solid #ededed;\n height: 40rem;\n "], ["\n border: 1px solid #ededed;\n height: 40rem;\n "]))) },
158
158
  (0, react_1.jsx)(ChatInterface_1.default, { userId: "user1", messages: messages, handleSend: handleSend, submitting: submitting, fetchNextPage: loadMore, hasNextPage: hasMore, isLoading: isLoading, isFetching: isFetching })));
159
159
  }
160
160
  exports.ChatInterface = ChatInterface;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendorflow/components",
3
- "version": "2.0.33",
3
+ "version": "2.0.37",
4
4
  "description": "React components for vendorflow",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",