@vendorflow/components 2.0.43 → 2.0.44

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.
@@ -92,8 +92,6 @@ function ChatInterface() {
92
92
  setFetching(true);
93
93
  return new Promise(function (resolve) {
94
94
  setTimeout(function () {
95
- setSubmitting(false);
96
- setFetching(false);
97
95
  setMessages(__spreadArray([
98
96
  {
99
97
  id: generateId(),
@@ -103,6 +101,8 @@ function ChatInterface() {
103
101
  content: message,
104
102
  }
105
103
  ], __read(messages), false));
104
+ setSubmitting(false);
105
+ setFetching(false);
106
106
  resolve(true);
107
107
  }, 500);
108
108
  });
@@ -19,6 +19,7 @@ function MessageThread(_a) {
19
19
  var userId = _a.userId, messages = _a.messages, inputHeight = _a.inputHeight, hasNextPage = _a.hasNextPage, fetchNextPage = _a.fetchNextPage, isLoading = _a.isLoading, isFetching = _a.isFetching, isSubmitting = _a.isSubmitting, colors = _a.colors;
20
20
  var isInitialized = (0, react_2.useRef)(false);
21
21
  var isScrollLoad = (0, react_2.useRef)(false);
22
+ var hasSubmitted = (0, react_2.useRef)(false);
22
23
  var prevScrollTop = (0, react_2.useRef)(null);
23
24
  var prevScrollHeight = (0, react_2.useRef)(null);
24
25
  var shouldScrollToPrevPosition = (0, react_2.useRef)(false);
@@ -31,9 +32,14 @@ function MessageThread(_a) {
31
32
  fetchNextPage();
32
33
  }
33
34
  }, 300), [hasNextPage, fetchNextPage, isLoading, isFetching]);
35
+ (0, react_2.useEffect)(function () {
36
+ if (isSubmitting) {
37
+ hasSubmitted.current = true;
38
+ }
39
+ }, [isSubmitting]);
34
40
  // This will handle the initial loading of messages, then scroll to bottom
35
41
  (0, react_2.useEffect)(function () {
36
- if (!isInitialized.current && !isLoading && scrollParent.current) {
42
+ if (!isInitialized.current && !isFetching && scrollParent.current) {
37
43
  var _a = scrollParent.current, clientHeight = _a.clientHeight, scrollHeight = _a.scrollHeight;
38
44
  if (clientHeight >= scrollHeight && hasNextPage && fetchNextPage) {
39
45
  fetchNextPage();
@@ -42,7 +48,7 @@ function MessageThread(_a) {
42
48
  isInitialized.current = true;
43
49
  scrollParent.current.scrollTo(0, scrollHeight - clientHeight);
44
50
  }
45
- }, [isLoading, isInitialized.current, hasNextPage, fetchNextPage]);
51
+ }, [isFetching, isInitialized.current, hasNextPage, fetchNextPage]);
46
52
  // Sets up the scroll event listener
47
53
  (0, react_2.useEffect)(function () {
48
54
  if (scrollParent.current) {
@@ -70,8 +76,9 @@ function MessageThread(_a) {
70
76
  }, [isFetching, prevScrollHeight.current]);
71
77
  // Manages scroll position for data changes that are triggered from anything other than the scroll event
72
78
  (0, react_2.useEffect)(function () {
79
+ var _a;
73
80
  if (scrollParent.current && !isScrollLoad.current && isInitialized.current) {
74
- var _a = scrollParent.current, scrollHeight = _a.scrollHeight, scrollTop = _a.scrollTop, clientHeight = _a.clientHeight;
81
+ var _b = scrollParent.current, scrollHeight = _b.scrollHeight, scrollTop = _b.scrollTop, clientHeight = _b.clientHeight;
75
82
  if (isFetching) {
76
83
  // track the current position
77
84
  prevScrollHeight.current = scrollHeight;
@@ -81,18 +88,23 @@ function MessageThread(_a) {
81
88
  shouldScrollToPrevPosition.current = true;
82
89
  }
83
90
  }
84
- else if (!isFetching &&
85
- prevScrollHeight.current !== null &&
86
- prevScrollTop.current !== null &&
87
- scrollHeight > prevScrollHeight.current) {
91
+ else {
88
92
  // init to scroll to bottom delta
89
93
  var delta = scrollHeight - clientHeight;
90
- if (shouldScrollToPrevPosition.current) {
91
- delta = prevScrollTop.current;
94
+ if (hasSubmitted.current) {
95
+ // scroll to bottom if this was triggered by the current user's sent message
96
+ (_a = scrollParent.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, delta);
97
+ }
98
+ else if (!isFetching && prevScrollHeight.current !== null && prevScrollTop.current !== null) {
99
+ if (shouldScrollToPrevPosition.current) {
100
+ delta = prevScrollTop.current;
101
+ }
102
+ scrollParent.current.scrollTo(0, delta);
92
103
  }
93
- scrollParent.current.scrollTo(0, delta);
104
+ // clean up
94
105
  prevScrollHeight.current = null;
95
106
  prevScrollTop.current = null;
107
+ hasSubmitted.current = false;
96
108
  shouldScrollToPrevPosition.current = false;
97
109
  }
98
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendorflow/components",
3
- "version": "2.0.43",
3
+ "version": "2.0.44",
4
4
  "description": "React components for vendorflow",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",