@seamly/web-ui 20.8.1 → 21.0.1-beta.1

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.
Files changed (225) hide show
  1. package/build/dist/lib/components.js +14855 -20
  2. package/build/dist/lib/components.min.js +2 -1
  3. package/build/dist/lib/components.min.js.LICENSE.txt +48 -0
  4. package/build/dist/lib/config.js +9 -3
  5. package/build/dist/lib/config.min.js +1 -1
  6. package/build/dist/lib/contexts.js +14 -5
  7. package/build/dist/lib/contexts.min.js +1 -1
  8. package/build/dist/lib/deprecated-view.js +1 -1
  9. package/build/dist/lib/hooks.js +8446 -20
  10. package/build/dist/lib/hooks.min.js +2 -1
  11. package/build/dist/lib/hooks.min.js.LICENSE.txt +38 -0
  12. package/build/dist/lib/index.debug.js +585 -584
  13. package/build/dist/lib/index.debug.min.js +1 -1
  14. package/build/dist/lib/index.debug.min.js.LICENSE.txt +110 -110
  15. package/build/dist/lib/index.js +20279 -26454
  16. package/build/dist/lib/index.min.js +1 -1
  17. package/build/dist/lib/index.min.js.LICENSE.txt +6 -1
  18. package/build/dist/lib/standalone.js +27823 -34681
  19. package/build/dist/lib/standalone.min.js +1 -1
  20. package/build/dist/lib/standalone.min.js.LICENSE.txt +1 -1
  21. package/build/dist/lib/storage.js +6 -15
  22. package/build/dist/lib/style-guide.js +23181 -7921
  23. package/build/dist/lib/style-guide.min.js +1 -1
  24. package/build/dist/lib/style-guide.min.js.LICENSE.txt +10 -0
  25. package/build/dist/lib/styles-default-implementation.js +1 -1
  26. package/build/dist/lib/styles.js +1 -1
  27. package/build/dist/lib/utils.js +22149 -17
  28. package/build/dist/lib/utils.min.js +2 -1
  29. package/build/dist/lib/utils.min.js.LICENSE.txt +48 -0
  30. package/package.json +54 -52
  31. package/src/icons/icon_check-16.svg +14 -0
  32. package/src/icons/icon_check-32.svg +14 -0
  33. package/src/javascripts/api/conversation-connector.ts +149 -0
  34. package/src/javascripts/api/errors/seamly-base-error.js +19 -0
  35. package/src/javascripts/api/errors/seamly-unavailable-error.js +5 -7
  36. package/src/javascripts/api/{index.js → index.ts} +163 -116
  37. package/src/javascripts/config.types.ts +5 -4
  38. package/src/javascripts/domains/app/actions.ts +47 -46
  39. package/src/javascripts/domains/app/hooks.js +1 -1
  40. package/src/javascripts/domains/config/actions.ts +2 -8
  41. package/src/javascripts/domains/config/hooks.ts +1 -1
  42. package/src/javascripts/domains/config/selectors.ts +6 -6
  43. package/src/javascripts/domains/config/slice.ts +3 -3
  44. package/src/javascripts/domains/errors/index.ts +66 -0
  45. package/src/javascripts/domains/forms/context.ts +1 -1
  46. package/src/javascripts/domains/forms/forms.types.ts +3 -3
  47. package/src/javascripts/domains/forms/hooks.ts +10 -10
  48. package/src/javascripts/domains/forms/provider.tsx +9 -9
  49. package/src/javascripts/domains/i18n/actions.ts +11 -5
  50. package/src/javascripts/domains/i18n/hooks.ts +11 -8
  51. package/src/javascripts/domains/i18n/selectors.ts +10 -4
  52. package/src/javascripts/domains/i18n/slice.ts +0 -1
  53. package/src/javascripts/domains/interrupt/hooks.ts +1 -1
  54. package/src/javascripts/domains/interrupt/middleware.ts +1 -1
  55. package/src/javascripts/domains/store/index.ts +1 -1
  56. package/src/javascripts/domains/store/selectors.ts +16 -0
  57. package/src/javascripts/domains/store/slice.ts +47 -41
  58. package/src/javascripts/domains/store/store.types.ts +38 -10
  59. package/src/javascripts/domains/translations/components/{options-button.js → options-button.tsx} +30 -20
  60. package/src/javascripts/domains/translations/components/options-dialog/index.tsx +33 -0
  61. package/src/javascripts/domains/translations/components/options-dialog/translation-option.tsx +42 -0
  62. package/src/javascripts/domains/translations/components/options-dialog/translation-options.tsx +81 -0
  63. package/src/javascripts/domains/translations/components/translation-status.tsx +15 -0
  64. package/src/javascripts/domains/translations/hooks.ts +77 -11
  65. package/src/javascripts/domains/translations/slice.ts +20 -9
  66. package/src/javascripts/domains/translations/translations.types.ts +4 -2
  67. package/src/javascripts/domains/visibility/actions.ts +6 -10
  68. package/src/javascripts/domains/visibility/hooks.ts +33 -14
  69. package/src/javascripts/domains/visibility/selectors.ts +3 -2
  70. package/src/javascripts/domains/visibility/slice.ts +2 -6
  71. package/src/javascripts/index.ts +18 -22
  72. package/src/javascripts/lib/engine/{index.js → index.tsx} +25 -7
  73. package/src/javascripts/lib/url-helpers.ts +112 -0
  74. package/src/javascripts/package/components.js +15 -1
  75. package/src/javascripts/package/config.js +1 -1
  76. package/src/javascripts/package/contexts.js +5 -3
  77. package/src/javascripts/package/hooks.js +19 -1
  78. package/src/javascripts/package/utils.js +13 -3
  79. package/src/javascripts/schema.ts +28 -0
  80. package/src/javascripts/style-guide/components/app.js +16 -12
  81. package/src/javascripts/style-guide/components/links.js +6 -6
  82. package/src/javascripts/style-guide/components/static-core.js +14 -9
  83. package/src/javascripts/style-guide/components/view.js +2 -2
  84. package/src/javascripts/style-guide/states.js +132 -36
  85. package/src/javascripts/style-guide/style-guide-engine.js +2 -1
  86. package/src/javascripts/style-guide/style-guide-external-api.js +1 -1
  87. package/src/javascripts/ui/components/app-options/index.js +25 -6
  88. package/src/javascripts/ui/components/chat-app.js +1 -1
  89. package/src/javascripts/ui/components/chat-status/chat-status-action.tsx +30 -0
  90. package/src/javascripts/ui/components/chat-status/index.tsx +61 -0
  91. package/src/javascripts/ui/components/conversation/component-filter.js +9 -9
  92. package/src/javascripts/ui/components/conversation/{conversation.js → conversation.tsx} +32 -41
  93. package/src/javascripts/ui/components/conversation/event/card-component.js +2 -2
  94. package/src/javascripts/ui/components/conversation/event/card-message.js +1 -1
  95. package/src/javascripts/ui/components/conversation/event/carousel-component/components/controls.js +2 -2
  96. package/src/javascripts/ui/components/conversation/event/carousel-component/index.js +4 -4
  97. package/src/javascripts/ui/components/conversation/event/carousel-message/components/slide.js +2 -2
  98. package/src/javascripts/ui/components/conversation/event/carousel-message/index.js +1 -1
  99. package/src/javascripts/ui/components/conversation/event/chat-scroll/chat-scroll-context.ts +12 -0
  100. package/src/javascripts/ui/components/conversation/event/chat-scroll/chat-scroll-provider.tsx +46 -0
  101. package/src/javascripts/ui/components/conversation/event/chat-scroll/unread-messages-button.tsx +30 -0
  102. package/src/javascripts/ui/components/conversation/event/choice-prompt.js +12 -8
  103. package/src/javascripts/ui/components/conversation/event/conversation-suggestions.js +6 -6
  104. package/src/javascripts/ui/components/conversation/event/cta.js +2 -2
  105. package/src/javascripts/ui/components/conversation/event/divider/index.js +0 -1
  106. package/src/javascripts/ui/components/conversation/event/divider/variants/default.js +1 -1
  107. package/src/javascripts/ui/components/conversation/event/divider/variants/new-translation.js +17 -22
  108. package/src/javascripts/ui/components/conversation/event/divider/variants/time-indicator.js +2 -2
  109. package/src/javascripts/ui/components/conversation/event/event-participant.js +1 -1
  110. package/src/javascripts/ui/components/conversation/event/event.tsx +66 -0
  111. package/src/javascripts/ui/components/conversation/event/hooks/use-event-link-click-handler.js +1 -1
  112. package/src/javascripts/ui/components/conversation/event/hooks/use-formatted-date.js +1 -1
  113. package/src/javascripts/ui/components/conversation/event/image-lightbox.js +1 -1
  114. package/src/javascripts/ui/components/conversation/event/image.js +2 -2
  115. package/src/javascripts/ui/components/conversation/event/splash.js +1 -1
  116. package/src/javascripts/ui/components/conversation/event/translation.js +1 -1
  117. package/src/javascripts/ui/components/conversation/event/upload.js +2 -2
  118. package/src/javascripts/ui/components/conversation/event/video.js +2 -2
  119. package/src/javascripts/ui/components/conversation/event-divider.js +1 -1
  120. package/src/javascripts/ui/components/conversation/message-container.js +1 -1
  121. package/src/javascripts/ui/components/conversation/use-chat-scroll.ts +108 -0
  122. package/src/javascripts/ui/components/core/{seamly-activity-monitor.js → seamly-activity-monitor.tsx} +12 -5
  123. package/src/javascripts/ui/components/core/seamly-api-context.ts +7 -0
  124. package/src/javascripts/ui/components/core/seamly-chat.tsx +8 -0
  125. package/src/javascripts/ui/components/core/{seamly-core.js → seamly-core.tsx} +27 -14
  126. package/src/javascripts/ui/components/core/seamly-event-subscriber.ts +340 -0
  127. package/src/javascripts/ui/components/core/seamly-file-upload.js +2 -2
  128. package/src/javascripts/ui/components/core/seamly-idle-detach-counter.js +1 -1
  129. package/src/javascripts/ui/components/core/seamly-instance-functions-loader.js +24 -11
  130. package/src/javascripts/ui/components/core/seamly-live-region.js +4 -4
  131. package/src/javascripts/ui/components/core/seamly-new-notifications.js +3 -3
  132. package/src/javascripts/ui/components/core/seamly-read-state.js +2 -33
  133. package/src/javascripts/ui/components/entry/deprecated-toggle-button.js +4 -4
  134. package/src/javascripts/ui/components/entry/entry-container.js +8 -8
  135. package/src/javascripts/ui/components/entry/text-entry/hooks.js +3 -3
  136. package/src/javascripts/ui/components/entry/text-entry/index.js +3 -3
  137. package/src/javascripts/ui/components/entry/text-entry/text-entry-form.js +4 -4
  138. package/src/javascripts/ui/components/entry/upload/file-upload-form.js +3 -3
  139. package/src/javascripts/ui/components/entry/upload/index.js +5 -5
  140. package/src/javascripts/ui/components/entry/upload-toggle.js +6 -6
  141. package/src/javascripts/ui/components/faq/faq.js +14 -14
  142. package/src/javascripts/ui/components/form-controls/error.js +2 -2
  143. package/src/javascripts/ui/components/form-controls/file-input.js +3 -3
  144. package/src/javascripts/ui/components/layout/agent-info.js +3 -3
  145. package/src/javascripts/ui/components/layout/chat-frame.js +20 -12
  146. package/src/javascripts/ui/components/layout/chat.js +5 -5
  147. package/src/javascripts/ui/components/layout/deprecated-app-frame.js +6 -6
  148. package/src/javascripts/ui/components/layout/deprecated-chat-frame.js +34 -0
  149. package/src/javascripts/ui/components/layout/header.js +2 -2
  150. package/src/javascripts/ui/components/layout/icon.js +11 -9
  151. package/src/javascripts/ui/components/layout/interrupt.js +7 -5
  152. package/src/javascripts/ui/components/layout/pre-chat-messages.js +1 -1
  153. package/src/javascripts/ui/components/layout/privacy-disclaimer.js +2 -2
  154. package/src/javascripts/ui/components/options/options-button.js +5 -5
  155. package/src/javascripts/ui/components/options/{options-frame.js → options-frame.tsx} +52 -18
  156. package/src/javascripts/ui/components/options/transcript/index.js +9 -10
  157. package/src/javascripts/ui/components/options/transcript/transcript-form.js +2 -2
  158. package/src/javascripts/ui/components/suggestions/index.js +8 -8
  159. package/src/javascripts/ui/components/suggestions/suggestions-item.js +1 -1
  160. package/src/javascripts/{domains/translations/components/chat-status.js → ui/components/translation-chat-status/index.tsx} +13 -14
  161. package/src/javascripts/ui/components/translation-proposal/index.tsx +36 -0
  162. package/src/javascripts/ui/components/view/app-view.js +2 -7
  163. package/src/javascripts/ui/components/view/deprecated-view.js +8 -10
  164. package/src/javascripts/ui/components/view/index.js +6 -6
  165. package/src/javascripts/ui/components/view/inline-view.js +4 -8
  166. package/src/javascripts/ui/components/view/window-view/collapse-button.js +2 -2
  167. package/src/javascripts/ui/components/view/window-view/index.js +11 -17
  168. package/src/javascripts/ui/components/view/window-view/window-open-button.js +6 -6
  169. package/src/javascripts/ui/components/warnings/idle-detach-warning.js +3 -3
  170. package/src/javascripts/ui/components/warnings/prompt.js +1 -1
  171. package/src/javascripts/ui/components/warnings/resume-conversation-prompt.js +4 -4
  172. package/src/javascripts/ui/components/widgets/in-out-transition.js +20 -18
  173. package/src/javascripts/ui/components/widgets/lightbox.js +3 -3
  174. package/src/javascripts/ui/components/widgets/modal.js +2 -2
  175. package/src/javascripts/ui/components/widgets/upload-progress.js +2 -2
  176. package/src/javascripts/ui/hooks/file-upload-hooks.js +1 -1
  177. package/src/javascripts/ui/hooks/focus-helper-hooks.js +1 -1
  178. package/src/javascripts/ui/hooks/seamly-entry-hooks.js +6 -6
  179. package/src/javascripts/ui/hooks/seamly-hooks.js +11 -10
  180. package/src/javascripts/ui/hooks/seamly-option-hooks.js +6 -6
  181. package/src/javascripts/ui/hooks/{seamly-state-hooks.js → seamly-state-hooks.ts} +9 -6
  182. package/src/javascripts/ui/hooks/use-click-outside.ts +29 -0
  183. package/src/javascripts/ui/hooks/use-event-component-mapping.js +11 -10
  184. package/src/javascripts/ui/hooks/use-interval.js +1 -1
  185. package/src/javascripts/ui/hooks/use-seamly-actions.ts +29 -29
  186. package/src/javascripts/ui/hooks/use-seamly-chat.js +14 -24
  187. package/src/javascripts/ui/hooks/use-seamly-commands.js +20 -15
  188. package/src/javascripts/ui/hooks/use-seamly-idle-detach-countdown.js +8 -8
  189. package/src/javascripts/ui/hooks/use-seamly-resume-conversation-prompt.js +2 -2
  190. package/src/javascripts/ui/hooks/use-single-file-upload.js +1 -1
  191. package/src/javascripts/ui/hooks/utility-hooks.js +1 -1
  192. package/src/javascripts/ui/utils/general-utils.js +0 -23
  193. package/src/javascripts/ui/utils/seamly-utils.ts +10 -1
  194. package/src/javascripts/ui/utils/seamly-utils.types.ts +9 -0
  195. package/src/stylesheets/1-settings/_config.scss +1 -1
  196. package/src/stylesheets/3-chat/_chat.scss +24 -9
  197. package/src/stylesheets/5-components/_chat-status.scss +72 -16
  198. package/src/stylesheets/5-components/_conversation.scss +35 -1
  199. package/src/stylesheets/5-components/_disclaimer.scss +0 -5
  200. package/src/stylesheets/5-components/_options.scss +16 -6
  201. package/src/stylesheets/5-components/_translation-options.scss +51 -0
  202. package/src/stylesheets/6-default-implementation/_scrollbar.scss +1 -1
  203. package/src/stylesheets/7-deprecated/3-app/_app.scss +19 -4
  204. package/src/stylesheets/7-deprecated/5-components/_chat-status.scss +5 -0
  205. package/src/stylesheets/7-deprecated/5-components/_options.scss +1 -4
  206. package/src/stylesheets/7-deprecated/5-components/_translation-options.scss +49 -0
  207. package/src/stylesheets/deprecated-view.scss +1 -0
  208. package/src/stylesheets/styles.scss +1 -0
  209. package/webpack/config.common.js +4 -4
  210. package/webpack/config.package.js +10 -16
  211. package/webpack/config.site.js +4 -1
  212. package/webpack/config.test.js +2 -1
  213. package/build/dist/lib/deprecated-view.css +0 -1
  214. package/build/dist/lib/styles-default-implementation.css +0 -1
  215. package/build/dist/lib/styles.css +0 -1
  216. package/src/.DS_Store +0 -0
  217. package/src/javascripts/api/event-producer.js +0 -20
  218. package/src/javascripts/api/producer.js +0 -136
  219. package/src/javascripts/domains/errors/index.js +0 -37
  220. package/src/javascripts/domains/translations/components/options-dialog/form.js +0 -70
  221. package/src/javascripts/domains/translations/components/options-dialog/index.js +0 -87
  222. package/src/javascripts/ui/components/chat-status/index.js +0 -38
  223. package/src/javascripts/ui/components/conversation/event/event.js +0 -36
  224. package/src/javascripts/ui/components/core/seamly-api-context.js +0 -5
  225. package/src/javascripts/ui/components/core/seamly-event-subscriber.js +0 -279
@@ -0,0 +1,30 @@
1
+ import { useContext } from 'preact/hooks'
2
+ import ChatScrollContext from 'ui/components/conversation/event/chat-scroll/chat-scroll-context'
3
+ import Icon from 'ui/components/layout/icon'
4
+ import InOutTransition from 'ui/components/widgets/in-out-transition'
5
+ import { useI18n } from 'domains/i18n/hooks'
6
+ import { useVisibility } from 'domains/visibility/hooks'
7
+ import { className } from 'lib/css'
8
+
9
+ const UnreadMessagesButton = () => {
10
+ const { scrollToRef, unreadIds } = useContext(ChatScrollContext)
11
+ const { isMinimized } = useVisibility()
12
+ const { t } = useI18n()
13
+
14
+ return (
15
+ <InOutTransition isActive={!!unreadIds.length && !isMinimized}>
16
+ <div className={className('unread-messages')}>
17
+ <button
18
+ type="button"
19
+ className={className('button', 'button--primary')}
20
+ onClick={scrollToRef}
21
+ >
22
+ {t('message.unreadMessagesCount', { unreadCount: unreadIds.length })}
23
+ <Icon name="chevronDown" size="32" alt="" />
24
+ </button>
25
+ </div>
26
+ </InOutTransition>
27
+ )
28
+ }
29
+
30
+ export default UnreadMessagesButton
@@ -1,17 +1,18 @@
1
1
  import { toChildArray } from 'preact'
2
- import { useEffect, useState, useMemo } from 'preact/hooks'
2
+ import { useEffect, useMemo, useState } from 'preact/hooks'
3
+ import MessageContainer from 'ui/components/conversation/message-container'
4
+ import Icon from 'ui/components/layout/icon'
3
5
  import {
6
+ useGeneratedId,
7
+ useLastMessageEventId,
4
8
  useSeamlyCommands,
5
9
  useSeamlyServiceInfo,
6
- useLastMessageEventId,
7
- useGeneratedId,
8
10
  } from 'ui/hooks/seamly-hooks'
9
- import { className } from 'lib/css'
10
11
  import { actionTypes } from 'ui/utils/seamly-utils'
11
- import Icon from 'ui/components/layout/icon'
12
12
  import { useI18n } from 'domains/i18n/hooks'
13
13
  import { useTranslatedEventData } from 'domains/translations/hooks'
14
- import MessageContainer from 'ui/components/conversation/message-container'
14
+ import { className } from 'lib/css'
15
+ import { randomId } from 'lib/id'
15
16
 
16
17
  export const useChoicePrompt = (event) => {
17
18
  const { payload } = event
@@ -46,10 +47,12 @@ export const useChoicePrompt = (event) => {
46
47
  }, [payload, lastEventId])
47
48
 
48
49
  const onChoiceClickHandler = (choice) => {
50
+ const transactionId = randomId()
51
+
49
52
  if (chooseAgain) {
50
- addDivider('new_topic')
53
+ addDivider('new_topic', transactionId)
51
54
  }
52
- addMessageBubble(choice.text)
55
+ addMessageBubble(choice.text, transactionId)
53
56
  sendAction({
54
57
  type: actionTypes.pickChoice,
55
58
  originMessage: payload.id,
@@ -58,6 +61,7 @@ export const useChoicePrompt = (event) => {
58
61
  text: choice.text,
59
62
  chooseAgain,
60
63
  },
64
+ transactionId,
61
65
  })
62
66
  setShowOptions(false)
63
67
  }
@@ -1,15 +1,15 @@
1
- import { useUserHasResponded } from 'domains/app/hooks'
2
- import { setHasResponded } from 'domains/app/slice'
3
- import { useConfig } from 'domains/config/hooks'
4
- import { useI18n } from 'domains/i18n/hooks'
5
- import { useTranslatedEventData } from 'domains/translations/hooks'
6
- import { className } from 'lib/css'
7
1
  import { useCallback, useMemo, useState } from 'preact/hooks'
8
2
  import { useDispatch } from 'react-redux'
9
3
  import MessageContainer from 'ui/components/conversation/message-container'
10
4
  import SuggestionsList from 'ui/components/suggestions/suggestions-list'
11
5
  import { useEvents, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
12
6
  import { actionTypes } from 'ui/utils/seamly-utils'
7
+ import { useUserHasResponded } from 'domains/app/hooks'
8
+ import { setHasResponded } from 'domains/app/slice'
9
+ import { useConfig } from 'domains/config/hooks'
10
+ import { useI18n } from 'domains/i18n/hooks'
11
+ import { useTranslatedEventData } from 'domains/translations/hooks'
12
+ import { className } from 'lib/css'
13
13
 
14
14
  export const useSuggestions = (event) => {
15
15
  const { payload } = event
@@ -1,9 +1,9 @@
1
1
  import { useCallback } from 'preact/hooks'
2
- import { className } from 'lib/css'
2
+ import MessageContainer from 'ui/components/conversation/message-container'
3
3
  import { useGeneratedId, useSeamlyCommands } from 'ui/hooks/seamly-hooks'
4
4
  import { actionTypes } from 'ui/utils/seamly-utils'
5
- import MessageContainer from 'ui/components/conversation/message-container'
6
5
  import { useTranslatedEventData } from 'domains/translations/hooks'
6
+ import { className } from 'lib/css'
7
7
  import useEventLinkClickHandler from './hooks/use-event-link-click-handler'
8
8
 
9
9
  const Cta = ({ event }) => {
@@ -1,5 +1,4 @@
1
1
  import { dividerKeys } from 'ui/utils/seamly-utils'
2
-
3
2
  import DefaultDivider from './variants/default'
4
3
  import NewTranslationDivider from './variants/new-translation'
5
4
 
@@ -1,6 +1,6 @@
1
+ import EventDivider from 'ui/components/conversation/event-divider'
1
2
  import { dividerKeys } from 'ui/utils/seamly-utils'
2
3
  import { useI18n } from 'domains/i18n/hooks'
3
- import EventDivider from 'ui/components/conversation/event-divider'
4
4
 
5
5
  const dividerTypes = {
6
6
  [dividerKeys.new_topic]: 'newtopic',
@@ -1,27 +1,29 @@
1
- import { useI18n } from 'domains/i18n/hooks'
2
- import EventDivider from 'ui/components/conversation/event-divider'
3
- import { className } from 'lib/css'
4
- import {
5
- useTranslations,
6
- useLocaleNativeName,
7
- } from 'domains/translations/hooks'
1
+ import { useCallback } from 'preact/hooks'
8
2
  import { useDispatch, useSelector } from 'react-redux'
3
+ import EventDivider from 'ui/components/conversation/event-divider'
4
+ import { useEvents } from 'ui/hooks/seamly-state-hooks'
5
+ import { useI18n } from 'domains/i18n/hooks'
6
+ import { useTranslations } from 'domains/translations/hooks'
9
7
  import {
10
- enableEventsTranslation,
11
8
  disableEventsTranslation,
9
+ enableEventsTranslation,
12
10
  } from 'domains/translations/slice'
13
- import { useCallback } from 'preact/hooks'
14
- import { useEvents } from 'ui/hooks/seamly-hooks'
11
+ import { className } from 'lib/css'
15
12
 
16
13
  const NewTranslationDivider = ({ event }) => {
17
14
  const { t } = useI18n()
18
15
  const events = useEvents()
19
16
  const {
20
- body: { translationEnabled, translationLocale, text },
17
+ body: {
18
+ restartButtonText,
19
+ translationEnabled,
20
+ translationLocale,
21
+ text,
22
+ title,
23
+ },
21
24
  id,
22
25
  } = event.payload
23
26
  const { enableTranslations } = useTranslations()
24
- const localeNativeName = useLocaleNativeName(translationLocale)
25
27
  const translatedEventGroups = useSelector(
26
28
  (state) => state.translations.translatedEventGroups,
27
29
  )
@@ -41,17 +43,10 @@ const NewTranslationDivider = ({ event }) => {
41
43
  }
42
44
  return (
43
45
  <EventDivider iconName="newTranslation" dividerType="newtranslation">
44
- <p className={className('divider__title')}>
45
- {t(
46
- translationEnabled
47
- ? 'translations.divider.startText'
48
- : 'translations.divider.stopText',
49
- { language: localeNativeName },
50
- )}
51
- </p>
46
+ <p className={className('divider__title')}>{title}</p>
47
+ {text && <p>{text}</p>}
52
48
  {translationEnabled ? (
53
49
  <>
54
- <p>{text}</p>
55
50
  <button
56
51
  className={className('button', 'button--secondary')}
57
52
  onClick={toggleTranslations}
@@ -69,7 +64,7 @@ const NewTranslationDivider = ({ event }) => {
69
64
  data-testid="restartTranslationButton"
70
65
  onClick={handleRestartButtonclick}
71
66
  >
72
- {t('translations.divider.restartButtonText')}
67
+ {restartButtonText}
73
68
  </button>
74
69
  )}
75
70
  </EventDivider>
@@ -1,9 +1,9 @@
1
1
  import { useEffect } from 'preact/hooks'
2
2
  import EventDivider from 'ui/components/conversation/event-divider'
3
- import { className } from 'lib/css'
4
- import { microsecondsToMilliseconds } from 'ui/utils/general-utils'
5
3
  import { useFormattedDate } from 'ui/components/conversation/event/hooks/use-formatted-date'
6
4
  import { useForceUpdate } from 'ui/hooks/utility-hooks'
5
+ import { microsecondsToMilliseconds } from 'ui/utils/general-utils'
6
+ import { className } from 'lib/css'
7
7
 
8
8
  const TimeIndicator = ({ event }) => {
9
9
  const forceUpdate = useForceUpdate()
@@ -1,7 +1,7 @@
1
1
  import { useSeamlyParticipant } from 'ui/hooks/seamly-hooks'
2
- import { className } from 'lib/css'
3
2
  import { useConfig } from 'domains/config/hooks'
4
3
  import { useI18n } from 'domains/i18n/hooks'
4
+ import { className } from 'lib/css'
5
5
 
6
6
  const EventParticipant = ({ eventPayload }) => {
7
7
  const { t } = useI18n()
@@ -0,0 +1,66 @@
1
+ import { FunctionComponent, useContext, useEffect } from 'preact/compat'
2
+ import { useDispatch } from 'react-redux'
3
+ import ChatScrollContext from 'ui/components/conversation/event/chat-scroll/chat-scroll-context'
4
+ import TimeIndicator from 'ui/components/conversation/event/divider/variants/time-indicator'
5
+ import { useSeamlyCommands } from 'ui/hooks/seamly-hooks'
6
+ import useEventComponentMapping from 'ui/hooks/use-event-component-mapping'
7
+ import { actionTypes } from 'ui/utils/seamly-utils'
8
+ import { setEventsRead } from 'domains/store/slice'
9
+ import { useIntersect } from 'domains/visibility/hooks'
10
+ import { className } from 'lib/css'
11
+
12
+ const Event: FunctionComponent<{
13
+ event
14
+ newParticipant: boolean
15
+ }> = ({ event, newParticipant }) => {
16
+ const { eventRefs, unreadIds } = useContext(ChatScrollContext)
17
+ const { sendAction } = useSeamlyCommands()
18
+ const ref = eventRefs[event.payload.id]
19
+ const { containerRef, isVisible } = useIntersect({
20
+ containerRef: ref,
21
+ freezeOnceVisible: true,
22
+ })
23
+ const dispatch = useDispatch()
24
+ const [Component, SubComponent] = useEventComponentMapping(event)
25
+
26
+ useEffect(() => {
27
+ if (isVisible && unreadIds?.includes(event.payload.id)) {
28
+ const readIds = unreadIds.reduce<string[]>(
29
+ (arr, id) => (!arr.includes(event.payload.id) ? arr.concat(id) : arr),
30
+ [],
31
+ )
32
+
33
+ dispatch(setEventsRead(readIds))
34
+ sendAction({ type: actionTypes.read, events: readIds })
35
+ }
36
+ }, [dispatch, event.payload.id, isVisible, sendAction, unreadIds])
37
+
38
+ if (!Component) {
39
+ return null
40
+ }
41
+
42
+ const classNames = ['conversation__item']
43
+
44
+ if (event.type === 'info') {
45
+ classNames.push('conversation__item--source-info')
46
+ } else if (event.payload.fromClient) {
47
+ classNames.push('conversation__item--source-user')
48
+ } else {
49
+ classNames.push('conversation__item--source-agent')
50
+ }
51
+
52
+ if (newParticipant) {
53
+ classNames.push('conversation__item--new-participant')
54
+ }
55
+
56
+ return (
57
+ <li className={className(classNames)} ref={containerRef}>
58
+ {event.timeIndicator && <TimeIndicator event={event} />}
59
+ <Component event={event}>
60
+ <SubComponent event={event} />
61
+ </Component>
62
+ </li>
63
+ )
64
+ }
65
+
66
+ export default Event
@@ -1,5 +1,5 @@
1
- import { actionTypes } from 'ui/utils/seamly-utils'
2
1
  import { useSeamlyCommands } from 'ui/hooks/seamly-hooks'
2
+ import { actionTypes } from 'ui/utils/seamly-utils'
3
3
 
4
4
  const useEventLinkClickHandler = (eventId) => {
5
5
  const { sendAction } = useSeamlyCommands()
@@ -1,6 +1,6 @@
1
- import { useI18n } from 'domains/i18n/hooks'
2
1
  import { getRelativeDate } from 'ui/utils/general-utils'
3
2
  import { useConfig } from 'domains/config/hooks'
3
+ import { useI18n } from 'domains/i18n/hooks'
4
4
 
5
5
  const dateFormatOptions = { month: 'long', day: 'numeric', year: 'numeric' }
6
6
  const timeFormatOptions = { hour: 'numeric', minute: 'numeric' }
@@ -1,8 +1,8 @@
1
1
  import { useState } from 'preact/hooks'
2
+ import Icon from 'ui/components/layout/icon'
2
3
  import Lightbox from 'ui/components/widgets/lightbox'
3
4
  import { useI18n } from 'domains/i18n/hooks'
4
5
  import { className } from 'lib/css'
5
- import Icon from 'ui/components/layout/icon'
6
6
 
7
7
  const ImageLightbox = ({ description, url }) => {
8
8
  const { t } = useI18n()
@@ -1,8 +1,8 @@
1
- import { setLoadedImageEventIds } from 'domains/store/slice'
2
- import { useTranslatedEventData } from 'domains/translations/hooks'
3
1
  import { useState } from 'preact/hooks'
4
2
  import { useDispatch } from 'react-redux'
5
3
  import MessageContainer from 'ui/components/conversation/message-container'
4
+ import { setLoadedImageEventIds } from 'domains/store/slice'
5
+ import { useTranslatedEventData } from 'domains/translations/hooks'
6
6
  import ImageLightbox from './image-lightbox'
7
7
 
8
8
  const Image = ({ event, descriptorId, ...props }) => {
@@ -1,6 +1,6 @@
1
- import { useTranslatedEventData } from 'domains/translations/hooks'
2
1
  import useEventLinkClickHandler from 'ui/components/conversation/event/hooks/use-event-link-click-handler'
3
2
  import MessageContainer from 'ui/components/conversation/message-container'
3
+ import { useTranslatedEventData } from 'domains/translations/hooks'
4
4
 
5
5
  const Splash = ({ event, ...props }) => {
6
6
  const { payload } = event
@@ -1,5 +1,5 @@
1
- import { useI18n } from 'domains/i18n/hooks'
2
1
  import MessageContainer from 'ui/components/conversation/message-container'
2
+ import { useI18n } from 'domains/i18n/hooks'
3
3
  import { useTranslatedEventData } from 'domains/translations/hooks'
4
4
 
5
5
  const Translation = ({ event, ...props }) => {
@@ -1,9 +1,9 @@
1
1
  import { useMemo } from 'preact/hooks'
2
- import { className } from 'lib/css'
2
+ import MessageContainer from 'ui/components/conversation/message-container'
3
3
  import Icon from 'ui/components/layout/icon'
4
4
  import { useI18n } from 'domains/i18n/hooks'
5
- import MessageContainer from 'ui/components/conversation/message-container'
6
5
  import { useTranslatedEventData } from 'domains/translations/hooks'
6
+ import { className } from 'lib/css'
7
7
 
8
8
  const UploadContent = ({ children, url, target }) =>
9
9
  url ? (
@@ -1,7 +1,7 @@
1
- import { className } from 'lib/css'
1
+ import MessageContainer from 'ui/components/conversation/message-container'
2
2
  import { useSeamlyMessageContainerClassNames } from 'ui/hooks/seamly-hooks'
3
3
  import { useTranslatedEventData } from 'domains/translations/hooks'
4
- import MessageContainer from 'ui/components/conversation/message-container'
4
+ import { className } from 'lib/css'
5
5
 
6
6
  const Video = ({ event, descriptorId, ...props }) => {
7
7
  const { body } = useTranslatedEventData(event)
@@ -1,5 +1,5 @@
1
- import { className } from 'lib/css'
2
1
  import Icon from 'ui/components/layout/icon'
2
+ import { className } from 'lib/css'
3
3
 
4
4
  export default function EventDivider({
5
5
  children,
@@ -1,6 +1,6 @@
1
- import { className } from 'lib/css'
2
1
  import { useSeamlyMessageContainerClassNames } from 'ui/hooks/component-helper-hooks'
3
2
  import { useTranslatedEventData } from 'domains/translations/hooks'
3
+ import { className } from 'lib/css'
4
4
  import EventParticipant from './event/event-participant'
5
5
 
6
6
  function MessageContainer({
@@ -0,0 +1,108 @@
1
+ import { RefObject } from 'preact'
2
+ import {
3
+ MutableRef,
4
+ useCallback,
5
+ useEffect,
6
+ useRef,
7
+ useState,
8
+ } from 'preact/hooks'
9
+ import { useSelector } from 'react-redux'
10
+ import { timeout } from 'ui/hooks/focus-helper-hooks'
11
+ import {
12
+ useEvents,
13
+ useLoadedImageEventIds,
14
+ useSeamlyIsLoading,
15
+ } from 'ui/hooks/seamly-state-hooks'
16
+ import { RootState } from 'domains/store'
17
+ import { selectUnreadEventIds } from 'domains/store/selectors'
18
+ import { useVisibility } from 'domains/visibility/hooks'
19
+
20
+ /**
21
+ * Threshold defines how close to the bottom user needs to scroll for it to be treated as the bottom of the conversation.
22
+ */
23
+ const THRESHOLD = 10
24
+
25
+ const useChatScroll = (
26
+ eventRefs: Record<string, RefObject<HTMLElement>>,
27
+ ): {
28
+ containerRef: MutableRef<HTMLDivElement>
29
+ unreadIds: string[]
30
+ scrollToRef: () => void
31
+ scrollToBottom: () => void
32
+ } => {
33
+ const containerRef = useRef<HTMLDivElement>()
34
+ const [hasScrolledToBottom, setHasScrolledToBottom] = useState(true)
35
+ const unreadIds = useSelector(selectUnreadEventIds)
36
+ const events = useEvents()
37
+ const isLoading = useSeamlyIsLoading()
38
+ const { isOpen } = useVisibility()
39
+ const loadedImageEventIds = useLoadedImageEventIds()
40
+ const isLastEventFromClient = useSelector(
41
+ (state: RootState) => state.state.isLastEventFromClient,
42
+ )
43
+
44
+ useEffect(() => {
45
+ const element = containerRef.current
46
+ const onScroll = () => {
47
+ const { scrollHeight, scrollTop, clientHeight } = element
48
+ const hasScrolledUp =
49
+ Math.abs(scrollHeight - scrollTop - clientHeight) > THRESHOLD
50
+
51
+ setHasScrolledToBottom(!hasScrolledUp)
52
+ }
53
+
54
+ element.addEventListener('scroll', onScroll)
55
+
56
+ return () => element.removeEventListener('scroll', onScroll)
57
+ }, [])
58
+
59
+ const scrollToBottom = useCallback(() => {
60
+ requestAnimationFrame(async () => {
61
+ await timeout(30)
62
+ containerRef.current?.scrollTo({
63
+ top: containerRef.current?.scrollHeight,
64
+ left: 0,
65
+ behavior: 'auto',
66
+ })
67
+ })
68
+ }, [])
69
+
70
+ useEffect(() => {
71
+ if (isLastEventFromClient) {
72
+ scrollToBottom()
73
+ }
74
+ }, [isLastEventFromClient, scrollToBottom])
75
+
76
+ useEffect(() => {
77
+ if (hasScrolledToBottom) {
78
+ scrollToBottom()
79
+ }
80
+ }, [
81
+ hasScrolledToBottom,
82
+ unreadIds,
83
+ events,
84
+ isLoading,
85
+ isOpen,
86
+ loadedImageEventIds,
87
+ scrollToBottom,
88
+ ])
89
+
90
+ const scrollToRef = () => {
91
+ const ref = eventRefs[unreadIds?.at(0)]?.current
92
+ // We scroll to the oldest unread event
93
+ containerRef.current?.scrollTo({
94
+ top: ref?.offsetTop,
95
+ behavior: 'auto',
96
+ left: 0,
97
+ })
98
+ }
99
+
100
+ return {
101
+ containerRef,
102
+ unreadIds,
103
+ scrollToRef,
104
+ scrollToBottom,
105
+ }
106
+ }
107
+
108
+ export default useChatScroll
@@ -1,23 +1,30 @@
1
- import { useRef, useCallback } from 'preact/hooks'
1
+ import { useCallback, useRef } from 'preact/hooks'
2
+ import { activitySendDelay } from 'config'
2
3
  import {
3
4
  useSeamlyCommands,
4
5
  useSeamlyIdleDetachCountdown,
5
6
  } from 'ui/hooks/seamly-hooks'
6
- import { activitySendDelay } from 'config'
7
+ import { actionTypes } from 'ui/utils/seamly-utils'
8
+ import { useVisibility } from 'domains/visibility/hooks'
7
9
  import { className } from 'lib/css'
8
10
  import SeamlyActivityEventContext from './seamly-activity-event-context'
9
11
 
10
12
  const SeamlyActivityMonitor = ({ children }) => {
13
+ const { isMinimized } = useVisibility()
11
14
  const prevSendTimestamp = useRef(0)
12
15
  const { sendAction } = useSeamlyCommands()
13
16
  const { hasCountdown, isActive, stopCountdown } =
14
17
  useSeamlyIdleDetachCountdown()
15
18
 
16
19
  const onActivityHandler = useCallback(() => {
20
+ if (isMinimized) {
21
+ return
22
+ }
23
+
17
24
  const timeStamp = new Date().getTime()
18
25
 
19
26
  const sendActive = () => {
20
- sendAction({ type: 'interactivity_update' })
27
+ sendAction({ type: actionTypes.interactivityUpdate })
21
28
  prevSendTimestamp.current = timeStamp
22
29
  }
23
30
 
@@ -29,7 +36,7 @@ const SeamlyActivityMonitor = ({ children }) => {
29
36
  if (timeStamp - prevSendTimestamp.current > activitySendDelay) {
30
37
  sendActive()
31
38
  }
32
- }, [sendAction, hasCountdown, isActive, stopCountdown])
39
+ }, [sendAction, hasCountdown, isActive, stopCountdown, isMinimized])
33
40
 
34
41
  // It is important to use keyUp here as focus may be set from outside the
35
42
  // chat container via keyboard. In this case the keyDown handler would not
@@ -37,7 +44,7 @@ const SeamlyActivityMonitor = ({ children }) => {
37
44
  return (
38
45
  <div
39
46
  className={className('activity-monitor')}
40
- tabIndex="-1"
47
+ tabIndex={-1}
41
48
  onMouseDown={onActivityHandler}
42
49
  onKeyUp={onActivityHandler}
43
50
  onTouchStart={onActivityHandler}
@@ -0,0 +1,7 @@
1
+ import { API } from 'api'
2
+ import { Events } from 'minivents'
3
+ import { createContext } from 'preact'
4
+
5
+ export const SeamlyApiContext = createContext<API>(null)
6
+
7
+ export const SeamlyEventBusContext = createContext<Events>(null)
@@ -0,0 +1,8 @@
1
+ import useSeamlyChat from 'ui/hooks/use-seamly-chat'
2
+
3
+ const SeamlyChat = ({ children }) => {
4
+ useSeamlyChat()
5
+ return <>{children}</>
6
+ }
7
+
8
+ export default SeamlyChat
@@ -1,6 +1,11 @@
1
- import { catchError } from 'domains/errors'
1
+ import { API } from 'api'
2
+ import { Events } from 'minivents'
3
+ import { FunctionComponent } from 'preact'
2
4
  import { useErrorBoundary } from 'preact/hooks'
3
5
  import { Provider } from 'react-redux'
6
+ import SeamlyChat from 'ui/components/core/seamly-chat'
7
+ import { catchError } from 'domains/errors'
8
+ import { Store } from 'domains/store'
4
9
  import ComponentFilter from '../conversation/component-filter'
5
10
  import SeamlyActivityMonitor from './seamly-activity-monitor'
6
11
  import { SeamlyApiContext, SeamlyEventBusContext } from './seamly-api-context'
@@ -13,25 +18,33 @@ import SeamlyLiveRegion from './seamly-live-region'
13
18
  import SeamlyNewNotifications from './seamly-new-notifications'
14
19
  import SeamlyReadState from './seamly-read-state'
15
20
 
16
- const SeamlyCore = ({ store, children, eventBus, api }) => {
17
- useErrorBoundary((error) => store.dispatch(catchError(error)))
21
+ const SeamlyCore: FunctionComponent<{
22
+ store: Store
23
+ eventBus: Events
24
+ api: API
25
+ }> = ({ store, children, eventBus, api }) => {
26
+ useErrorBoundary((error) => {
27
+ store.dispatch(catchError(error))
28
+ })
18
29
 
19
30
  return (
20
31
  <Provider store={store}>
21
32
  <SeamlyEventBusContext.Provider value={eventBus}>
22
33
  <SeamlyApiContext.Provider value={api}>
23
34
  <SeamlyLiveRegion>
24
- <ComponentFilter>
25
- <SeamlyInitializer />
26
- <SeamlyEventSubscriber eventBus={eventBus} />
27
- <SeamlyReadState />
28
- <SeamlyNewNotifications />
29
- <SeamlyIdleDetachCounter />
30
- <SeamlyActivityMonitor>
31
- <SeamlyInstanceFunctionsLoader />
32
- <SeamlyFileUpload>{children}</SeamlyFileUpload>
33
- </SeamlyActivityMonitor>
34
- </ComponentFilter>
35
+ <SeamlyChat>
36
+ <ComponentFilter>
37
+ <SeamlyInitializer />
38
+ <SeamlyEventSubscriber />
39
+ <SeamlyReadState />
40
+ <SeamlyNewNotifications />
41
+ <SeamlyIdleDetachCounter />
42
+ <SeamlyActivityMonitor>
43
+ <SeamlyInstanceFunctionsLoader />
44
+ <SeamlyFileUpload>{children}</SeamlyFileUpload>
45
+ </SeamlyActivityMonitor>
46
+ </ComponentFilter>
47
+ </SeamlyChat>
35
48
  </SeamlyLiveRegion>
36
49
  </SeamlyApiContext.Provider>
37
50
  </SeamlyEventBusContext.Provider>