stream-chat-react-native-core 5.39.6 → 5.40.0-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 (433) hide show
  1. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerSelectionBar.js +27 -0
  2. package/lib/commonjs/components/AttachmentPicker/components/AttachmentPickerSelectionBar.js.map +1 -1
  3. package/lib/commonjs/components/Channel/Channel.js +17 -4
  4. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  5. package/lib/commonjs/components/Channel/hooks/useCreateInputMessageInputContext.js +7 -1
  6. package/lib/commonjs/components/Channel/hooks/useCreateInputMessageInputContext.js.map +1 -1
  7. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js +5 -1
  8. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  9. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +46 -3
  10. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  11. package/lib/commonjs/components/Chat/Chat.js +2 -0
  12. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  13. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js +10 -0
  14. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js.map +1 -1
  15. package/lib/commonjs/components/Message/Message.js +13 -0
  16. package/lib/commonjs/components/Message/Message.js.map +1 -1
  17. package/lib/commonjs/components/Message/MessageSimple/MessageContent.js +31 -15
  18. package/lib/commonjs/components/Message/MessageSimple/MessageContent.js.map +1 -1
  19. package/lib/commonjs/components/MessageInput/MessageInput.js +44 -1
  20. package/lib/commonjs/components/MessageInput/MessageInput.js.map +1 -1
  21. package/lib/commonjs/components/MessageInput/components/NativeAttachmentPicker.js +18 -1
  22. package/lib/commonjs/components/MessageInput/components/NativeAttachmentPicker.js.map +1 -1
  23. package/lib/commonjs/components/MessageOverlay/MessageOverlay.js +10 -0
  24. package/lib/commonjs/components/MessageOverlay/MessageOverlay.js.map +1 -1
  25. package/lib/commonjs/components/Poll/CreatePollContent.js +386 -0
  26. package/lib/commonjs/components/Poll/CreatePollContent.js.map +1 -0
  27. package/lib/commonjs/components/Poll/Poll.js +112 -0
  28. package/lib/commonjs/components/Poll/Poll.js.map +1 -0
  29. package/lib/commonjs/components/Poll/components/Button.js +513 -0
  30. package/lib/commonjs/components/Poll/components/Button.js.map +1 -0
  31. package/lib/commonjs/components/Poll/components/CreatePollIcon.js +23 -0
  32. package/lib/commonjs/components/Poll/components/CreatePollIcon.js.map +1 -0
  33. package/lib/commonjs/components/Poll/components/CreatePollOptions.js +281 -0
  34. package/lib/commonjs/components/Poll/components/CreatePollOptions.js.map +1 -0
  35. package/lib/commonjs/components/Poll/components/PollAnswersList.js +154 -0
  36. package/lib/commonjs/components/Poll/components/PollAnswersList.js.map +1 -0
  37. package/lib/commonjs/components/Poll/components/PollInputDialog.js +139 -0
  38. package/lib/commonjs/components/Poll/components/PollInputDialog.js.map +1 -0
  39. package/lib/commonjs/components/Poll/components/PollModalHeader.js +60 -0
  40. package/lib/commonjs/components/Poll/components/PollModalHeader.js.map +1 -0
  41. package/lib/commonjs/components/Poll/components/PollOption.js +209 -0
  42. package/lib/commonjs/components/Poll/components/PollOption.js.map +1 -0
  43. package/lib/commonjs/components/Poll/components/PollResults/PollOptionFullResults.js +123 -0
  44. package/lib/commonjs/components/Poll/components/PollResults/PollOptionFullResults.js.map +1 -0
  45. package/lib/commonjs/components/Poll/components/PollResults/PollResultItem.js +152 -0
  46. package/lib/commonjs/components/Poll/components/PollResults/PollResultItem.js.map +1 -0
  47. package/lib/commonjs/components/Poll/components/PollResults/PollResults.js +101 -0
  48. package/lib/commonjs/components/Poll/components/PollResults/PollResults.js.map +1 -0
  49. package/lib/commonjs/components/Poll/components/PollResults/index.js +37 -0
  50. package/lib/commonjs/components/Poll/components/PollResults/index.js.map +1 -0
  51. package/lib/commonjs/components/Poll/components/index.js +92 -0
  52. package/lib/commonjs/components/Poll/components/index.js.map +1 -0
  53. package/lib/commonjs/components/Poll/hooks/usePollAnswersPagination.js +129 -0
  54. package/lib/commonjs/components/Poll/hooks/usePollAnswersPagination.js.map +1 -0
  55. package/lib/commonjs/components/Poll/hooks/usePollOptionVotesPagination.js +140 -0
  56. package/lib/commonjs/components/Poll/hooks/usePollOptionVotesPagination.js.map +1 -0
  57. package/lib/commonjs/components/Poll/hooks/usePollState.js +103 -0
  58. package/lib/commonjs/components/Poll/hooks/usePollState.js.map +1 -0
  59. package/lib/commonjs/components/Poll/hooks/usePollStateStore.js +13 -0
  60. package/lib/commonjs/components/Poll/hooks/usePollStateStore.js.map +1 -0
  61. package/lib/commonjs/components/Poll/index.js +81 -0
  62. package/lib/commonjs/components/Poll/index.js.map +1 -0
  63. package/lib/commonjs/components/Reply/Reply.js +1 -1
  64. package/lib/commonjs/components/Reply/Reply.js.map +1 -1
  65. package/lib/commonjs/components/index.js +11 -0
  66. package/lib/commonjs/components/index.js.map +1 -1
  67. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  68. package/lib/commonjs/contexts/index.js +11 -0
  69. package/lib/commonjs/contexts/index.js.map +1 -1
  70. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +26 -3
  71. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  72. package/lib/commonjs/contexts/messageInputContext/hooks/useCreateMessageInputContext.js +9 -1
  73. package/lib/commonjs/contexts/messageInputContext/hooks/useCreateMessageInputContext.js.map +1 -1
  74. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  75. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  76. package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
  77. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +4 -0
  78. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  79. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +3 -0
  80. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  81. package/lib/commonjs/contexts/pollContext/createPollContentContext.js +33 -0
  82. package/lib/commonjs/contexts/pollContext/createPollContentContext.js.map +1 -0
  83. package/lib/commonjs/contexts/pollContext/index.js +26 -0
  84. package/lib/commonjs/contexts/pollContext/index.js.map +1 -0
  85. package/lib/commonjs/contexts/pollContext/pollContext.js +33 -0
  86. package/lib/commonjs/contexts/pollContext/pollContext.js.map +1 -0
  87. package/lib/commonjs/contexts/themeContext/utils/theme.js +126 -0
  88. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  89. package/lib/commonjs/i18n/en.json +34 -0
  90. package/lib/commonjs/i18n/es.json +38 -0
  91. package/lib/commonjs/i18n/fr.json +38 -0
  92. package/lib/commonjs/i18n/he.json +38 -0
  93. package/lib/commonjs/i18n/hi.json +34 -0
  94. package/lib/commonjs/i18n/it.json +38 -0
  95. package/lib/commonjs/i18n/ja.json +34 -0
  96. package/lib/commonjs/i18n/ko.json +34 -0
  97. package/lib/commonjs/i18n/nl.json +34 -0
  98. package/lib/commonjs/i18n/pt-br.json +38 -0
  99. package/lib/commonjs/i18n/ru.json +42 -0
  100. package/lib/commonjs/i18n/tr.json +34 -0
  101. package/lib/commonjs/icons/Back.js +19 -0
  102. package/lib/commonjs/icons/Back.js.map +1 -0
  103. package/lib/commonjs/icons/DragHandle.js +21 -0
  104. package/lib/commonjs/icons/DragHandle.js.map +1 -0
  105. package/lib/commonjs/icons/PollThumbnail.js +19 -0
  106. package/lib/commonjs/icons/PollThumbnail.js.map +1 -0
  107. package/lib/commonjs/icons/SendPoll.js +19 -0
  108. package/lib/commonjs/icons/SendPoll.js.map +1 -0
  109. package/lib/commonjs/icons/index.js +44 -0
  110. package/lib/commonjs/icons/index.js.map +1 -1
  111. package/lib/commonjs/store/QuickSqliteClient.js +1 -1
  112. package/lib/commonjs/store/apis/index.js +11 -0
  113. package/lib/commonjs/store/apis/index.js.map +1 -1
  114. package/lib/commonjs/store/apis/updatePollMessage.js +50 -0
  115. package/lib/commonjs/store/apis/updatePollMessage.js.map +1 -0
  116. package/lib/commonjs/store/mappers/mapMessageToStorable.js +5 -1
  117. package/lib/commonjs/store/mappers/mapMessageToStorable.js.map +1 -1
  118. package/lib/commonjs/store/mappers/mapStorableToMessage.js +5 -1
  119. package/lib/commonjs/store/mappers/mapStorableToMessage.js.map +1 -1
  120. package/lib/commonjs/store/schema.js +2 -0
  121. package/lib/commonjs/store/schema.js.map +1 -1
  122. package/lib/commonjs/version.json +1 -1
  123. package/lib/module/components/AttachmentPicker/components/AttachmentPickerSelectionBar.js +27 -0
  124. package/lib/module/components/AttachmentPicker/components/AttachmentPickerSelectionBar.js.map +1 -1
  125. package/lib/module/components/Channel/Channel.js +17 -4
  126. package/lib/module/components/Channel/Channel.js.map +1 -1
  127. package/lib/module/components/Channel/hooks/useCreateInputMessageInputContext.js +7 -1
  128. package/lib/module/components/Channel/hooks/useCreateInputMessageInputContext.js.map +1 -1
  129. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js +5 -1
  130. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  131. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +46 -3
  132. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  133. package/lib/module/components/Chat/Chat.js +2 -0
  134. package/lib/module/components/Chat/Chat.js.map +1 -1
  135. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js +10 -0
  136. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js.map +1 -1
  137. package/lib/module/components/Message/Message.js +13 -0
  138. package/lib/module/components/Message/Message.js.map +1 -1
  139. package/lib/module/components/Message/MessageSimple/MessageContent.js +31 -15
  140. package/lib/module/components/Message/MessageSimple/MessageContent.js.map +1 -1
  141. package/lib/module/components/MessageInput/MessageInput.js +44 -1
  142. package/lib/module/components/MessageInput/MessageInput.js.map +1 -1
  143. package/lib/module/components/MessageInput/components/NativeAttachmentPicker.js +18 -1
  144. package/lib/module/components/MessageInput/components/NativeAttachmentPicker.js.map +1 -1
  145. package/lib/module/components/MessageOverlay/MessageOverlay.js +10 -0
  146. package/lib/module/components/MessageOverlay/MessageOverlay.js.map +1 -1
  147. package/lib/module/components/Poll/CreatePollContent.js +386 -0
  148. package/lib/module/components/Poll/CreatePollContent.js.map +1 -0
  149. package/lib/module/components/Poll/Poll.js +112 -0
  150. package/lib/module/components/Poll/Poll.js.map +1 -0
  151. package/lib/module/components/Poll/components/Button.js +513 -0
  152. package/lib/module/components/Poll/components/Button.js.map +1 -0
  153. package/lib/module/components/Poll/components/CreatePollIcon.js +23 -0
  154. package/lib/module/components/Poll/components/CreatePollIcon.js.map +1 -0
  155. package/lib/module/components/Poll/components/CreatePollOptions.js +281 -0
  156. package/lib/module/components/Poll/components/CreatePollOptions.js.map +1 -0
  157. package/lib/module/components/Poll/components/PollAnswersList.js +154 -0
  158. package/lib/module/components/Poll/components/PollAnswersList.js.map +1 -0
  159. package/lib/module/components/Poll/components/PollInputDialog.js +139 -0
  160. package/lib/module/components/Poll/components/PollInputDialog.js.map +1 -0
  161. package/lib/module/components/Poll/components/PollModalHeader.js +60 -0
  162. package/lib/module/components/Poll/components/PollModalHeader.js.map +1 -0
  163. package/lib/module/components/Poll/components/PollOption.js +209 -0
  164. package/lib/module/components/Poll/components/PollOption.js.map +1 -0
  165. package/lib/module/components/Poll/components/PollResults/PollOptionFullResults.js +123 -0
  166. package/lib/module/components/Poll/components/PollResults/PollOptionFullResults.js.map +1 -0
  167. package/lib/module/components/Poll/components/PollResults/PollResultItem.js +152 -0
  168. package/lib/module/components/Poll/components/PollResults/PollResultItem.js.map +1 -0
  169. package/lib/module/components/Poll/components/PollResults/PollResults.js +101 -0
  170. package/lib/module/components/Poll/components/PollResults/PollResults.js.map +1 -0
  171. package/lib/module/components/Poll/components/PollResults/index.js +37 -0
  172. package/lib/module/components/Poll/components/PollResults/index.js.map +1 -0
  173. package/lib/module/components/Poll/components/index.js +92 -0
  174. package/lib/module/components/Poll/components/index.js.map +1 -0
  175. package/lib/module/components/Poll/hooks/usePollAnswersPagination.js +129 -0
  176. package/lib/module/components/Poll/hooks/usePollAnswersPagination.js.map +1 -0
  177. package/lib/module/components/Poll/hooks/usePollOptionVotesPagination.js +140 -0
  178. package/lib/module/components/Poll/hooks/usePollOptionVotesPagination.js.map +1 -0
  179. package/lib/module/components/Poll/hooks/usePollState.js +103 -0
  180. package/lib/module/components/Poll/hooks/usePollState.js.map +1 -0
  181. package/lib/module/components/Poll/hooks/usePollStateStore.js +13 -0
  182. package/lib/module/components/Poll/hooks/usePollStateStore.js.map +1 -0
  183. package/lib/module/components/Poll/index.js +81 -0
  184. package/lib/module/components/Poll/index.js.map +1 -0
  185. package/lib/module/components/Reply/Reply.js +1 -1
  186. package/lib/module/components/Reply/Reply.js.map +1 -1
  187. package/lib/module/components/index.js +11 -0
  188. package/lib/module/components/index.js.map +1 -1
  189. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  190. package/lib/module/contexts/index.js +11 -0
  191. package/lib/module/contexts/index.js.map +1 -1
  192. package/lib/module/contexts/messageInputContext/MessageInputContext.js +26 -3
  193. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  194. package/lib/module/contexts/messageInputContext/hooks/useCreateMessageInputContext.js +9 -1
  195. package/lib/module/contexts/messageInputContext/hooks/useCreateMessageInputContext.js.map +1 -1
  196. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  197. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  198. package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
  199. package/lib/module/contexts/overlayContext/OverlayProvider.js +4 -0
  200. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  201. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +3 -0
  202. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  203. package/lib/module/contexts/pollContext/createPollContentContext.js +33 -0
  204. package/lib/module/contexts/pollContext/createPollContentContext.js.map +1 -0
  205. package/lib/module/contexts/pollContext/index.js +26 -0
  206. package/lib/module/contexts/pollContext/index.js.map +1 -0
  207. package/lib/module/contexts/pollContext/pollContext.js +33 -0
  208. package/lib/module/contexts/pollContext/pollContext.js.map +1 -0
  209. package/lib/module/contexts/themeContext/utils/theme.js +126 -0
  210. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  211. package/lib/module/i18n/en.json +34 -0
  212. package/lib/module/i18n/es.json +38 -0
  213. package/lib/module/i18n/fr.json +38 -0
  214. package/lib/module/i18n/he.json +38 -0
  215. package/lib/module/i18n/hi.json +34 -0
  216. package/lib/module/i18n/it.json +38 -0
  217. package/lib/module/i18n/ja.json +34 -0
  218. package/lib/module/i18n/ko.json +34 -0
  219. package/lib/module/i18n/nl.json +34 -0
  220. package/lib/module/i18n/pt-br.json +38 -0
  221. package/lib/module/i18n/ru.json +42 -0
  222. package/lib/module/i18n/tr.json +34 -0
  223. package/lib/module/icons/Back.js +19 -0
  224. package/lib/module/icons/Back.js.map +1 -0
  225. package/lib/module/icons/DragHandle.js +21 -0
  226. package/lib/module/icons/DragHandle.js.map +1 -0
  227. package/lib/module/icons/PollThumbnail.js +19 -0
  228. package/lib/module/icons/PollThumbnail.js.map +1 -0
  229. package/lib/module/icons/SendPoll.js +19 -0
  230. package/lib/module/icons/SendPoll.js.map +1 -0
  231. package/lib/module/icons/index.js +44 -0
  232. package/lib/module/icons/index.js.map +1 -1
  233. package/lib/module/store/QuickSqliteClient.js +1 -1
  234. package/lib/module/store/apis/index.js +11 -0
  235. package/lib/module/store/apis/index.js.map +1 -1
  236. package/lib/module/store/apis/updatePollMessage.js +50 -0
  237. package/lib/module/store/apis/updatePollMessage.js.map +1 -0
  238. package/lib/module/store/mappers/mapMessageToStorable.js +5 -1
  239. package/lib/module/store/mappers/mapMessageToStorable.js.map +1 -1
  240. package/lib/module/store/mappers/mapStorableToMessage.js +5 -1
  241. package/lib/module/store/mappers/mapStorableToMessage.js.map +1 -1
  242. package/lib/module/store/schema.js +2 -0
  243. package/lib/module/store/schema.js.map +1 -1
  244. package/lib/module/version.json +1 -1
  245. package/lib/typescript/components/AttachmentPicker/components/AttachmentPickerSelectionBar.d.ts.map +1 -1
  246. package/lib/typescript/components/Channel/Channel.d.ts +2 -2
  247. package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
  248. package/lib/typescript/components/Channel/hooks/useCreateInputMessageInputContext.d.ts +1 -1
  249. package/lib/typescript/components/Channel/hooks/useCreateInputMessageInputContext.d.ts.map +1 -1
  250. package/lib/typescript/components/Channel/hooks/useCreateMessagesContext.d.ts +1 -1
  251. package/lib/typescript/components/Channel/hooks/useCreateMessagesContext.d.ts.map +1 -1
  252. package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts +5 -1
  253. package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts.map +1 -1
  254. package/lib/typescript/components/Chat/Chat.d.ts.map +1 -1
  255. package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts.map +1 -1
  256. package/lib/typescript/components/Message/Message.d.ts +1 -1
  257. package/lib/typescript/components/Message/Message.d.ts.map +1 -1
  258. package/lib/typescript/components/Message/MessageSimple/MessageContent.d.ts.map +1 -1
  259. package/lib/typescript/components/MessageInput/MessageInput.d.ts +1 -1
  260. package/lib/typescript/components/MessageInput/MessageInput.d.ts.map +1 -1
  261. package/lib/typescript/components/MessageInput/components/NativeAttachmentPicker.d.ts.map +1 -1
  262. package/lib/typescript/components/MessageOverlay/MessageOverlay.d.ts.map +1 -1
  263. package/lib/typescript/components/Poll/CreatePollContent.d.ts +6 -0
  264. package/lib/typescript/components/Poll/CreatePollContent.d.ts.map +1 -0
  265. package/lib/typescript/components/Poll/Poll.d.ts +13 -0
  266. package/lib/typescript/components/Poll/Poll.d.ts.map +1 -0
  267. package/lib/typescript/components/Poll/components/Button.d.ts +35 -0
  268. package/lib/typescript/components/Poll/components/Button.d.ts.map +1 -0
  269. package/lib/typescript/components/Poll/components/CreatePollIcon.d.ts +3 -0
  270. package/lib/typescript/components/Poll/components/CreatePollIcon.d.ts.map +1 -0
  271. package/lib/typescript/components/Poll/components/CreatePollOptions.d.ts +34 -0
  272. package/lib/typescript/components/Poll/components/CreatePollOptions.d.ts.map +1 -0
  273. package/lib/typescript/components/Poll/components/PollAnswersList.d.ts +15 -0
  274. package/lib/typescript/components/Poll/components/PollAnswersList.d.ts.map +1 -0
  275. package/lib/typescript/components/Poll/components/PollInputDialog.d.ts +10 -0
  276. package/lib/typescript/components/Poll/components/PollInputDialog.d.ts.map +1 -0
  277. package/lib/typescript/components/Poll/components/PollModalHeader.d.ts +7 -0
  278. package/lib/typescript/components/Poll/components/PollModalHeader.d.ts.map +1 -0
  279. package/lib/typescript/components/Poll/components/PollOption.d.ts +16 -0
  280. package/lib/typescript/components/Poll/components/PollOption.d.ts.map +1 -0
  281. package/lib/typescript/components/Poll/components/PollResults/PollOptionFullResults.d.ts +18 -0
  282. package/lib/typescript/components/Poll/components/PollResults/PollOptionFullResults.d.ts.map +1 -0
  283. package/lib/typescript/components/Poll/components/PollResults/PollResultItem.d.ts +9 -0
  284. package/lib/typescript/components/Poll/components/PollResults/PollResultItem.d.ts.map +1 -0
  285. package/lib/typescript/components/Poll/components/PollResults/PollResults.d.ts +10 -0
  286. package/lib/typescript/components/Poll/components/PollResults/PollResults.d.ts.map +1 -0
  287. package/lib/typescript/components/Poll/components/PollResults/index.d.ts +4 -0
  288. package/lib/typescript/components/Poll/components/PollResults/index.d.ts.map +1 -0
  289. package/lib/typescript/components/Poll/components/index.d.ts +9 -0
  290. package/lib/typescript/components/Poll/components/index.d.ts.map +1 -0
  291. package/lib/typescript/components/Poll/hooks/usePollAnswersPagination.d.ts +29 -0
  292. package/lib/typescript/components/Poll/hooks/usePollAnswersPagination.d.ts.map +1 -0
  293. package/lib/typescript/components/Poll/hooks/usePollOptionVotesPagination.d.ts +32 -0
  294. package/lib/typescript/components/Poll/hooks/usePollOptionVotesPagination.d.ts.map +1 -0
  295. package/lib/typescript/components/Poll/hooks/usePollState.d.ts +26 -0
  296. package/lib/typescript/components/Poll/hooks/usePollState.d.ts.map +1 -0
  297. package/lib/typescript/components/Poll/hooks/usePollStateStore.d.ts +3 -0
  298. package/lib/typescript/components/Poll/hooks/usePollStateStore.d.ts.map +1 -0
  299. package/lib/typescript/components/Poll/index.d.ts +8 -0
  300. package/lib/typescript/components/Poll/index.d.ts.map +1 -0
  301. package/lib/typescript/components/Reply/Reply.d.ts.map +1 -1
  302. package/lib/typescript/components/index.d.ts +1 -0
  303. package/lib/typescript/components/index.d.ts.map +1 -1
  304. package/lib/typescript/contexts/attachmentPickerContext/AttachmentPickerContext.d.ts +7 -1
  305. package/lib/typescript/contexts/attachmentPickerContext/AttachmentPickerContext.d.ts.map +1 -1
  306. package/lib/typescript/contexts/index.d.ts +1 -0
  307. package/lib/typescript/contexts/index.d.ts.map +1 -1
  308. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts +11 -2
  309. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts.map +1 -1
  310. package/lib/typescript/contexts/messageInputContext/hooks/useCreateMessageInputContext.d.ts +1 -1
  311. package/lib/typescript/contexts/messageInputContext/hooks/useCreateMessageInputContext.d.ts.map +1 -1
  312. package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts +2 -1
  313. package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts.map +1 -1
  314. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +9 -1
  315. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts.map +1 -1
  316. package/lib/typescript/contexts/overlayContext/OverlayContext.d.ts +1 -1
  317. package/lib/typescript/contexts/overlayContext/OverlayContext.d.ts.map +1 -1
  318. package/lib/typescript/contexts/overlayContext/OverlayProvider.d.ts.map +1 -1
  319. package/lib/typescript/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.d.ts +3 -0
  320. package/lib/typescript/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.d.ts.map +1 -1
  321. package/lib/typescript/contexts/pollContext/createPollContentContext.d.ts +20 -0
  322. package/lib/typescript/contexts/pollContext/createPollContentContext.d.ts.map +1 -0
  323. package/lib/typescript/contexts/pollContext/index.d.ts +3 -0
  324. package/lib/typescript/contexts/pollContext/index.d.ts.map +1 -0
  325. package/lib/typescript/contexts/pollContext/pollContext.d.ts +14 -0
  326. package/lib/typescript/contexts/pollContext/pollContext.d.ts.map +1 -0
  327. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +126 -0
  328. package/lib/typescript/contexts/themeContext/utils/theme.d.ts.map +1 -1
  329. package/lib/typescript/i18n/en.json +34 -0
  330. package/lib/typescript/i18n/es.json +38 -0
  331. package/lib/typescript/i18n/fr.json +38 -0
  332. package/lib/typescript/i18n/he.json +38 -0
  333. package/lib/typescript/i18n/hi.json +34 -0
  334. package/lib/typescript/i18n/it.json +38 -0
  335. package/lib/typescript/i18n/ja.json +34 -0
  336. package/lib/typescript/i18n/ko.json +34 -0
  337. package/lib/typescript/i18n/nl.json +34 -0
  338. package/lib/typescript/i18n/pt-br.json +38 -0
  339. package/lib/typescript/i18n/ru.json +42 -0
  340. package/lib/typescript/i18n/tr.json +34 -0
  341. package/lib/typescript/icons/Back.d.ts +4 -0
  342. package/lib/typescript/icons/Back.d.ts.map +1 -0
  343. package/lib/typescript/icons/DragHandle.d.ts +4 -0
  344. package/lib/typescript/icons/DragHandle.d.ts.map +1 -0
  345. package/lib/typescript/icons/PollThumbnail.d.ts +4 -0
  346. package/lib/typescript/icons/PollThumbnail.d.ts.map +1 -0
  347. package/lib/typescript/icons/SendPoll.d.ts +4 -0
  348. package/lib/typescript/icons/SendPoll.d.ts.map +1 -0
  349. package/lib/typescript/icons/index.d.ts +4 -0
  350. package/lib/typescript/icons/index.d.ts.map +1 -1
  351. package/lib/typescript/store/apis/index.d.ts +1 -0
  352. package/lib/typescript/store/apis/index.d.ts.map +1 -1
  353. package/lib/typescript/store/apis/updatePollMessage.d.ts +7 -0
  354. package/lib/typescript/store/apis/updatePollMessage.d.ts.map +1 -0
  355. package/lib/typescript/store/mappers/mapMessageToStorable.d.ts.map +1 -1
  356. package/lib/typescript/store/mappers/mapStorableToMessage.d.ts.map +1 -1
  357. package/lib/typescript/store/schema.d.ts +2 -0
  358. package/lib/typescript/store/schema.d.ts.map +1 -1
  359. package/lib/typescript/utils/i18n/Streami18n.d.ts +34 -0
  360. package/lib/typescript/utils/i18n/Streami18n.d.ts.map +1 -1
  361. package/package.json +2 -2
  362. package/src/components/AttachmentPicker/components/AttachmentPickerSelectionBar.tsx +35 -2
  363. package/src/components/Channel/Channel.tsx +27 -4
  364. package/src/components/Channel/hooks/useCreateInputMessageInputContext.ts +16 -1
  365. package/src/components/Channel/hooks/useCreateMessagesContext.ts +5 -0
  366. package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +63 -4
  367. package/src/components/Chat/Chat.tsx +2 -0
  368. package/src/components/Chat/hooks/handleEventToSyncDB.ts +19 -0
  369. package/src/components/Message/Message.tsx +15 -1
  370. package/src/components/Message/MessageSimple/MessageContent.tsx +16 -0
  371. package/src/components/MessageInput/MessageInput.tsx +58 -1
  372. package/src/components/MessageInput/__tests__/MessageInput.test.js +2 -0
  373. package/src/components/MessageInput/components/NativeAttachmentPicker.tsx +29 -2
  374. package/src/components/MessageOverlay/MessageOverlay.tsx +10 -0
  375. package/src/components/Poll/CreatePollContent.tsx +299 -0
  376. package/src/components/Poll/Poll.tsx +126 -0
  377. package/src/components/Poll/components/Button.tsx +465 -0
  378. package/src/components/Poll/components/CreatePollIcon.tsx +14 -0
  379. package/src/components/Poll/components/CreatePollOptions.tsx +351 -0
  380. package/src/components/Poll/components/PollAnswersList.tsx +134 -0
  381. package/src/components/Poll/components/PollInputDialog.tsx +117 -0
  382. package/src/components/Poll/components/PollModalHeader.tsx +42 -0
  383. package/src/components/Poll/components/PollOption.tsx +172 -0
  384. package/src/components/Poll/components/PollResults/PollOptionFullResults.tsx +108 -0
  385. package/src/components/Poll/components/PollResults/PollResultItem.tsx +115 -0
  386. package/src/components/Poll/components/PollResults/PollResults.tsx +79 -0
  387. package/src/components/Poll/components/PollResults/index.ts +3 -0
  388. package/src/components/Poll/components/index.ts +8 -0
  389. package/src/components/Poll/hooks/usePollAnswersPagination.ts +109 -0
  390. package/src/components/Poll/hooks/usePollOptionVotesPagination.ts +119 -0
  391. package/src/components/Poll/hooks/usePollState.ts +122 -0
  392. package/src/components/Poll/hooks/usePollStateStore.ts +13 -0
  393. package/src/components/Poll/index.ts +10 -0
  394. package/src/components/Reply/Reply.tsx +2 -0
  395. package/src/components/index.ts +1 -0
  396. package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +12 -1
  397. package/src/contexts/index.ts +1 -0
  398. package/src/contexts/messageInputContext/MessageInputContext.tsx +38 -10
  399. package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +4 -2
  400. package/src/contexts/messageInputContext/hooks/useCreateMessageInputContext.ts +9 -0
  401. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +2 -1
  402. package/src/contexts/messagesContext/MessagesContext.tsx +15 -2
  403. package/src/contexts/overlayContext/OverlayContext.tsx +1 -0
  404. package/src/contexts/overlayContext/OverlayProvider.tsx +3 -0
  405. package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +3 -0
  406. package/src/contexts/pollContext/createPollContentContext.tsx +49 -0
  407. package/src/contexts/pollContext/index.ts +2 -0
  408. package/src/contexts/pollContext/pollContext.tsx +43 -0
  409. package/src/contexts/themeContext/utils/theme.ts +233 -0
  410. package/src/i18n/en.json +34 -0
  411. package/src/i18n/es.json +38 -0
  412. package/src/i18n/fr.json +38 -0
  413. package/src/i18n/he.json +38 -0
  414. package/src/i18n/hi.json +34 -0
  415. package/src/i18n/it.json +38 -0
  416. package/src/i18n/ja.json +34 -0
  417. package/src/i18n/ko.json +34 -0
  418. package/src/i18n/nl.json +34 -0
  419. package/src/i18n/pt-br.json +38 -0
  420. package/src/i18n/ru.json +42 -0
  421. package/src/i18n/tr.json +34 -0
  422. package/src/icons/Back.tsx +12 -0
  423. package/src/icons/DragHandle.tsx +9 -0
  424. package/src/icons/PollThumbnail.tsx +12 -0
  425. package/src/icons/SendPoll.tsx +12 -0
  426. package/src/icons/index.ts +4 -0
  427. package/src/store/QuickSqliteClient.ts +1 -1
  428. package/src/store/apis/index.ts +1 -0
  429. package/src/store/apis/updatePollMessage.ts +48 -0
  430. package/src/store/mappers/mapMessageToStorable.ts +4 -0
  431. package/src/store/mappers/mapStorableToMessage.ts +4 -0
  432. package/src/store/schema.ts +4 -0
  433. package/src/version.json +1 -1
@@ -0,0 +1,172 @@
1
+ import React, { useMemo } from 'react';
2
+
3
+ import { ScrollViewProps, StyleSheet, Text, View } from 'react-native';
4
+
5
+ import { ScrollView } from 'react-native-gesture-handler';
6
+
7
+ import { PollOption as PollOptionClass, PollVote } from 'stream-chat';
8
+
9
+ import { VoteButton } from './Button';
10
+
11
+ import { PollContextProvider, PollContextValue, useTheme } from '../../../contexts';
12
+
13
+ import { Avatar } from '../../Avatar/Avatar';
14
+ import { usePollState } from '../hooks/usePollState';
15
+
16
+ export type PollOptionProps = {
17
+ option: PollOptionClass;
18
+ showProgressBar?: boolean;
19
+ };
20
+
21
+ export type PollAllOptionsContentProps = PollContextValue & {
22
+ additionalScrollViewProps?: Partial<ScrollViewProps>;
23
+ PollAllOptionsContent?: React.ComponentType;
24
+ };
25
+
26
+ export const PollAllOptionsContent = ({
27
+ additionalScrollViewProps,
28
+ }: Pick<PollAllOptionsContentProps, 'additionalScrollViewProps'>) => {
29
+ const { name, options } = usePollState();
30
+
31
+ const {
32
+ theme: {
33
+ colors: { bg_user, black, white },
34
+ poll: {
35
+ allOptions: { listContainer, titleContainer, titleText, wrapper },
36
+ },
37
+ },
38
+ } = useTheme();
39
+
40
+ return (
41
+ <ScrollView
42
+ contentContainerStyle={{ paddingBottom: 70 }}
43
+ style={[styles.allOptionsWrapper, { backgroundColor: white }, wrapper]}
44
+ {...additionalScrollViewProps}
45
+ >
46
+ <View style={[styles.allOptionsTitleContainer, { backgroundColor: bg_user }, titleContainer]}>
47
+ <Text style={[styles.allOptionsTitleText, { color: black }, titleText]}>{name}</Text>
48
+ </View>
49
+ <View style={[styles.allOptionsListContainer, { backgroundColor: bg_user }, listContainer]}>
50
+ {options?.map((option: PollOptionClass) => (
51
+ <View key={`full_poll_options_${option.id}`} style={{ paddingVertical: 16 }}>
52
+ <PollOption key={option.id} option={option} showProgressBar={false} />
53
+ </View>
54
+ ))}
55
+ </View>
56
+ </ScrollView>
57
+ );
58
+ };
59
+
60
+ export const PollAllOptions = ({
61
+ additionalScrollViewProps,
62
+ message,
63
+ poll,
64
+ PollAllOptionsContent: PollAllOptionsContentOverride,
65
+ }: PollAllOptionsContentProps) => (
66
+ <PollContextProvider value={{ message, poll }}>
67
+ {PollAllOptionsContentOverride ? (
68
+ <PollAllOptionsContentOverride />
69
+ ) : (
70
+ <PollAllOptionsContent additionalScrollViewProps={additionalScrollViewProps} />
71
+ )}
72
+ </PollContextProvider>
73
+ );
74
+
75
+ export const PollOption = ({ option, showProgressBar = true }: PollOptionProps) => {
76
+ const { is_closed, latest_votes_by_option, maxVotedOptionIds, vote_counts_by_option } =
77
+ usePollState();
78
+
79
+ const relevantVotes = useMemo(
80
+ () => latest_votes_by_option?.[option.id]?.slice(0, 2) || [],
81
+ [latest_votes_by_option, option.id],
82
+ );
83
+ const maxVotes = useMemo(
84
+ () =>
85
+ maxVotedOptionIds?.[0] && vote_counts_by_option
86
+ ? vote_counts_by_option[maxVotedOptionIds[0]]
87
+ : 0,
88
+ [maxVotedOptionIds, vote_counts_by_option],
89
+ );
90
+ const votes = vote_counts_by_option[option.id] || 0;
91
+
92
+ const {
93
+ theme: {
94
+ colors: { accent_dark_blue, accent_info, black, grey },
95
+ poll: {
96
+ message: {
97
+ option: {
98
+ container,
99
+ progressBar,
100
+ progressBarEmptyFill,
101
+ progressBarVotedFill,
102
+ progressBarWinnerFill,
103
+ text,
104
+ votesContainer,
105
+ wrapper,
106
+ },
107
+ },
108
+ },
109
+ },
110
+ } = useTheme();
111
+
112
+ return (
113
+ <View style={[styles.wrapper, wrapper]}>
114
+ <View style={[styles.container, container]}>
115
+ <VoteButton option={option} />
116
+ <Text style={[styles.text, { color: black }, text]}>{option.text}</Text>
117
+ <View style={[styles.votesContainer, votesContainer]}>
118
+ {relevantVotes.map((vote: PollVote) => (
119
+ <Avatar image={vote.user?.image as string} key={vote.id} size={20} />
120
+ ))}
121
+ <Text style={{ color: black, marginLeft: 2 }}>
122
+ {vote_counts_by_option[option.id] || 0}
123
+ </Text>
124
+ </View>
125
+ </View>
126
+ {showProgressBar ? (
127
+ <View style={[styles.progressBar, progressBar]}>
128
+ <View
129
+ style={{
130
+ backgroundColor:
131
+ is_closed && maxVotedOptionIds.length === 1 && maxVotedOptionIds[0] === option.id
132
+ ? progressBarWinnerFill || accent_info
133
+ : progressBarVotedFill || accent_dark_blue,
134
+ flex: maxVotes > 0 ? votes / maxVotes : 0,
135
+ }}
136
+ />
137
+ <View
138
+ style={{
139
+ backgroundColor: progressBarEmptyFill || grey,
140
+ flex: maxVotes > 0 ? (maxVotes - votes) / maxVotes : 1,
141
+ }}
142
+ />
143
+ </View>
144
+ ) : null}
145
+ </View>
146
+ );
147
+ };
148
+
149
+ const styles = StyleSheet.create({
150
+ allOptionsListContainer: {
151
+ borderRadius: 12,
152
+ marginTop: 32,
153
+ paddingBottom: 18,
154
+ paddingHorizontal: 16,
155
+ },
156
+ allOptionsTitleContainer: {
157
+ borderRadius: 12,
158
+ paddingHorizontal: 16,
159
+ paddingVertical: 18,
160
+ },
161
+ allOptionsTitleText: { fontSize: 16, fontWeight: '500' },
162
+ allOptionsWrapper: { flex: 1, marginBottom: 16, padding: 16 },
163
+ container: { flexDirection: 'row' },
164
+ progressBar: { borderRadius: 4, flex: 1, flexDirection: 'row', height: 4, marginTop: 2 },
165
+ text: {
166
+ flex: 1,
167
+ fontSize: 16,
168
+ marginLeft: 4,
169
+ },
170
+ votesContainer: { flexDirection: 'row', marginLeft: 4 },
171
+ wrapper: { marginTop: 8, paddingVertical: 8 },
172
+ });
@@ -0,0 +1,108 @@
1
+ import React, { useCallback } from 'react';
2
+ import { FlatList, type FlatListProps, StyleSheet, Text, View } from 'react-native';
3
+
4
+ import { PollOption, PollVote as PollVoteClass } from 'stream-chat';
5
+
6
+ import { PollVote } from './PollResultItem';
7
+
8
+ import {
9
+ PollContextProvider,
10
+ PollContextValue,
11
+ useTheme,
12
+ useTranslationContext,
13
+ } from '../../../../contexts';
14
+ import type { DefaultStreamChatGenerics } from '../../../../types/types';
15
+ import { usePollOptionVotesPagination } from '../../hooks/usePollOptionVotesPagination';
16
+ import { usePollState } from '../../hooks/usePollState';
17
+
18
+ export type PollOptionFullResultsProps<
19
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
20
+ > = PollContextValue & {
21
+ option: PollOption<StreamChatGenerics>;
22
+ additionalFlatListProps?: Partial<FlatListProps<PollVoteClass<StreamChatGenerics>>>;
23
+ PollOptionFullResultsContent?: React.ComponentType<{ option: PollOption<StreamChatGenerics> }>;
24
+ };
25
+
26
+ export const PollOptionFullResultsItem = ({ item }: { item: PollVoteClass }) => (
27
+ <PollVote {...item} />
28
+ );
29
+
30
+ export const PollOptionFullResultsContent = ({
31
+ additionalFlatListProps,
32
+ option,
33
+ }: Pick<PollOptionFullResultsProps, 'option' | 'additionalFlatListProps'>) => {
34
+ const { t } = useTranslationContext();
35
+ const { hasNextPage, loadMore, votes } = usePollOptionVotesPagination({ option });
36
+ const { vote_counts_by_option } = usePollState();
37
+
38
+ const {
39
+ theme: {
40
+ colors: { bg_user, black, white },
41
+ poll: {
42
+ fullResults: { container, contentContainer, headerContainer, headerText },
43
+ },
44
+ },
45
+ } = useTheme();
46
+
47
+ const PollOptionFullResultsHeader = useCallback(
48
+ () => (
49
+ <View style={[styles.headerContainer, headerContainer]}>
50
+ <Text style={[styles.headerText, { color: black }, headerText]}>
51
+ {t<string>('{{count}} votes', { count: vote_counts_by_option[option.id] ?? 0 })}
52
+ </Text>
53
+ </View>
54
+ ),
55
+ [black, headerContainer, headerText, option.id, t, vote_counts_by_option],
56
+ );
57
+
58
+ return (
59
+ <View style={[styles.container, { backgroundColor: white }, container]}>
60
+ <FlatList
61
+ contentContainerStyle={[
62
+ styles.contentContainer,
63
+ { backgroundColor: bg_user },
64
+ contentContainer,
65
+ ]}
66
+ data={votes}
67
+ keyExtractor={(item) => `option_full_results_${item.id}`}
68
+ ListHeaderComponent={PollOptionFullResultsHeader}
69
+ onEndReached={() => hasNextPage && loadMore()}
70
+ renderItem={PollOptionFullResultsItem}
71
+ {...additionalFlatListProps}
72
+ />
73
+ </View>
74
+ );
75
+ };
76
+
77
+ export const PollOptionFullResults = ({
78
+ additionalFlatListProps,
79
+ message,
80
+ option,
81
+ poll,
82
+ PollOptionFullResultsContent: PollOptionFullResultsContentOverride,
83
+ }: PollOptionFullResultsProps) => (
84
+ <PollContextProvider value={{ message, poll }}>
85
+ {PollOptionFullResultsContentOverride ? (
86
+ <PollOptionFullResultsContentOverride option={option} />
87
+ ) : (
88
+ <PollOptionFullResultsContent
89
+ additionalFlatListProps={additionalFlatListProps}
90
+ option={option}
91
+ />
92
+ )}
93
+ </PollContextProvider>
94
+ );
95
+
96
+ const styles = StyleSheet.create({
97
+ container: { flex: 1 },
98
+ contentContainer: {
99
+ borderRadius: 12,
100
+ marginBottom: 8,
101
+ marginHorizontal: 16,
102
+ marginTop: 16,
103
+ paddingHorizontal: 16,
104
+ paddingVertical: 12,
105
+ },
106
+ headerContainer: { flexDirection: 'row', justifyContent: 'flex-end', marginBottom: 8 },
107
+ headerText: { fontSize: 16, marginLeft: 16 },
108
+ });
@@ -0,0 +1,115 @@
1
+ import React, { useMemo } from 'react';
2
+ import { StyleSheet, Text, View } from 'react-native';
3
+
4
+ import { PollOption, PollVote as PollVoteClass, VotingVisibility } from 'stream-chat';
5
+
6
+ import { useTheme, useTranslationContext } from '../../../../contexts';
7
+ import type { DefaultStreamChatGenerics } from '../../../../types/types';
8
+ import { getDateString } from '../../../../utils/i18n/getDateString';
9
+ import { Avatar } from '../../../Avatar/Avatar';
10
+ import { usePollState } from '../../hooks/usePollState';
11
+ import { ShowAllVotesButton } from '../Button';
12
+
13
+ export type PollResultItemProps<
14
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
15
+ > = {
16
+ option: PollOption<StreamChatGenerics>;
17
+ };
18
+
19
+ export const PollVote = (vote: PollVoteClass) => {
20
+ const { t, tDateTimeParser } = useTranslationContext();
21
+ const { voting_visibility } = usePollState();
22
+ const {
23
+ theme: {
24
+ colors: { black, text_low_emphasis },
25
+ poll: {
26
+ results: {
27
+ vote: { container, dateText, userName },
28
+ },
29
+ },
30
+ },
31
+ } = useTheme();
32
+
33
+ const dateString = useMemo(
34
+ () =>
35
+ getDateString({
36
+ date: vote.created_at,
37
+ t,
38
+ tDateTimeParser,
39
+ timestampTranslationKey: 'timestamp/PollVote',
40
+ }),
41
+ [vote.created_at, t, tDateTimeParser],
42
+ );
43
+
44
+ const isAnonymous = useMemo(
45
+ () => voting_visibility === VotingVisibility.anonymous,
46
+ [voting_visibility],
47
+ );
48
+
49
+ return (
50
+ <View key={`results_vote_${vote.id}`} style={[styles.voteContainer, container]}>
51
+ <View style={{ flexDirection: 'row' }}>
52
+ {!isAnonymous && vote.user?.image ? (
53
+ <Avatar image={vote.user.image as string} key={vote.id} size={20} />
54
+ ) : null}
55
+ <Text style={[styles.voteUserName, { color: black }, userName]}>
56
+ {isAnonymous ? t<string>('Anonymous') : vote.user?.name}
57
+ </Text>
58
+ </View>
59
+ <Text style={[styles.voteDate, { color: text_low_emphasis }, dateText]}>{dateString}</Text>
60
+ </View>
61
+ );
62
+ };
63
+
64
+ export const PollResultsItem = ({ option }: PollResultItemProps) => {
65
+ const { t } = useTranslationContext();
66
+ const { latest_votes_by_option, vote_counts_by_option } = usePollState();
67
+
68
+ const {
69
+ theme: {
70
+ colors: { bg_user, black },
71
+ poll: {
72
+ results: {
73
+ item: { container, headerContainer, title, voteCount },
74
+ },
75
+ },
76
+ },
77
+ } = useTheme();
78
+
79
+ return (
80
+ <View style={[styles.container, { backgroundColor: bg_user }, container]}>
81
+ <View style={[styles.headerContainer, headerContainer]}>
82
+ <Text style={[styles.title, { color: black }, title]}>{option.text}</Text>
83
+ <Text style={[styles.voteCount, { color: black }, voteCount]}>
84
+ {t<string>('{{count}} votes', { count: vote_counts_by_option[option.id] ?? 0 })}
85
+ </Text>
86
+ </View>
87
+ {latest_votes_by_option?.[option.id]?.length > 0 ? (
88
+ <View style={{ marginTop: 16 }}>
89
+ {(latest_votes_by_option?.[option.id] ?? []).slice(0, 5).map(PollVote)}
90
+ </View>
91
+ ) : null}
92
+ <ShowAllVotesButton option={option} />
93
+ </View>
94
+ );
95
+ };
96
+
97
+ const styles = StyleSheet.create({
98
+ container: {
99
+ borderRadius: 12,
100
+ marginBottom: 8,
101
+ paddingHorizontal: 16,
102
+ paddingVertical: 12,
103
+ },
104
+ headerContainer: { flexDirection: 'row', justifyContent: 'space-between' },
105
+ title: { flex: 1, fontSize: 16, fontWeight: '500' },
106
+ voteContainer: {
107
+ flexDirection: 'row',
108
+ justifyContent: 'space-between',
109
+ marginBottom: 8,
110
+ paddingVertical: 8,
111
+ },
112
+ voteCount: { fontSize: 16, marginLeft: 16 },
113
+ voteDate: { fontSize: 14 },
114
+ voteUserName: { fontSize: 14, marginLeft: 2 },
115
+ });
@@ -0,0 +1,79 @@
1
+ import React, { useMemo } from 'react';
2
+ import { ScrollViewProps, StyleSheet, Text, View } from 'react-native';
3
+
4
+ import { ScrollView } from 'react-native-gesture-handler';
5
+
6
+ import { PollResultsItem } from './PollResultItem';
7
+
8
+ import { PollContextProvider, PollContextValue, useTheme } from '../../../../contexts';
9
+ import { usePollState } from '../../hooks/usePollState';
10
+
11
+ export type PollResultsProps = PollContextValue & {
12
+ additionalScrollViewProps?: Partial<ScrollViewProps>;
13
+ PollResultsContent?: React.ComponentType;
14
+ };
15
+
16
+ export const PollResultsContent = ({
17
+ additionalScrollViewProps,
18
+ }: Pick<PollResultsProps, 'additionalScrollViewProps'>) => {
19
+ const { name, options, vote_counts_by_option } = usePollState();
20
+
21
+ const sortedOptions = useMemo(
22
+ () =>
23
+ [...options].sort(
24
+ (a, b) => (vote_counts_by_option[b.id] ?? 0) - (vote_counts_by_option[a.id] ?? 0),
25
+ ),
26
+ [vote_counts_by_option, options],
27
+ );
28
+
29
+ const {
30
+ theme: {
31
+ colors: { bg_user, black, white },
32
+ poll: {
33
+ results: { container, scrollView, title },
34
+ },
35
+ },
36
+ } = useTheme();
37
+
38
+ return (
39
+ <ScrollView
40
+ style={[styles.scrollView, { backgroundColor: white }, scrollView]}
41
+ {...additionalScrollViewProps}
42
+ >
43
+ <View style={[styles.container, { backgroundColor: bg_user }, container]}>
44
+ <Text style={[styles.title, { color: black }, title]}>{name}</Text>
45
+ </View>
46
+ <View style={{ marginTop: 16 }}>
47
+ {sortedOptions.map((option) => (
48
+ <PollResultsItem key={`results_${option.id}`} option={option} />
49
+ ))}
50
+ </View>
51
+ </ScrollView>
52
+ );
53
+ };
54
+
55
+ export const PollResults = ({
56
+ additionalScrollViewProps,
57
+ message,
58
+ poll,
59
+ PollResultsContent: PollResultsContentOverride,
60
+ }: PollResultsProps) => (
61
+ <PollContextProvider value={{ message, poll }}>
62
+ {PollResultsContentOverride ? (
63
+ <PollResultsContentOverride />
64
+ ) : (
65
+ <PollResultsContent additionalScrollViewProps={additionalScrollViewProps} />
66
+ )}
67
+ </PollContextProvider>
68
+ );
69
+
70
+ const styles = StyleSheet.create({
71
+ container: {
72
+ borderRadius: 12,
73
+ marginTop: 16,
74
+ paddingHorizontal: 16,
75
+ paddingVertical: 18,
76
+ },
77
+ scrollView: { flex: 1, marginHorizontal: 16 },
78
+ title: { fontSize: 16, fontWeight: '500' },
79
+ });
@@ -0,0 +1,3 @@
1
+ export * from './PollResults';
2
+ export * from './PollResultItem';
3
+ export * from './PollOptionFullResults';
@@ -0,0 +1,8 @@
1
+ export * from './Button';
2
+ export * from './CreatePollIcon';
3
+ export * from './CreatePollOptions';
4
+ export * from './PollAnswersList';
5
+ export * from './PollInputDialog';
6
+ export * from './PollOption';
7
+ export * from './PollResults';
8
+ export * from './PollModalHeader';
@@ -0,0 +1,109 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+
3
+ import uniqBy from 'lodash/uniqBy';
4
+ import type { PollAnswer, PollAnswersQueryParams } from 'stream-chat';
5
+ import { isVoteAnswer } from 'stream-chat';
6
+
7
+ import { useChatContext, usePollContext } from '../../../contexts';
8
+
9
+ export type UsePollAnswersPaginationParams = {
10
+ loadFirstPage?: boolean;
11
+ paginationParams?: PollAnswersQueryParams;
12
+ };
13
+
14
+ export type UsePollAnswersReturnType = {
15
+ error: Error | undefined;
16
+ hasNextPage: boolean;
17
+ loading: boolean;
18
+ loadMore: () => void;
19
+ next: string | null | undefined;
20
+ pollAnswers: PollAnswer[];
21
+ };
22
+
23
+ /**
24
+ * A hook that queries answers for a given Poll and returns them in a paginated fashion.
25
+ * Should be used instead of the latest_answers property within the reactive state in the
26
+ * event that we need more than the top 10 answers. The returned property pollAnswers will
27
+ * automatically be updated and trigger a state change when paginating further.
28
+ *
29
+ * @param loadFirstPage {boolean} Signifies whether the first page should be automatically loaded whenever
30
+ * the hook is first called.
31
+ * @param paginationParams {PollAnswersQueryParams} The pagination params we might want to use for our custom
32
+ * needs when invoking the hook.
33
+ *
34
+ * @returns {UsePollAnswersReturnType} An object containing all of the needed pagination values as well as the
35
+ * answers.
36
+ **/
37
+ export const usePollAnswersPagination = ({
38
+ loadFirstPage = true,
39
+ paginationParams,
40
+ }: UsePollAnswersPaginationParams = {}): UsePollAnswersReturnType => {
41
+ const { poll } = usePollContext();
42
+ const { client } = useChatContext();
43
+
44
+ const [pollAnswers, setPollAnswers] = useState<PollAnswer[]>([]);
45
+ const [loading, setLoading] = useState(false);
46
+ const [error, setError] = useState<Error>();
47
+ const cursorRef = useRef<string | null>();
48
+ const queryInProgress = useRef(false);
49
+
50
+ const loadMore = useCallback(async () => {
51
+ if (cursorRef.current === null || queryInProgress.current) return;
52
+ const next = cursorRef.current;
53
+
54
+ setLoading(true);
55
+ queryInProgress.current = true;
56
+ try {
57
+ const { next: newNext, votes: answers } = await poll.queryAnswers({
58
+ filter: paginationParams?.filter,
59
+ options: !next ? paginationParams?.options : { ...paginationParams?.options, next },
60
+ sort: { updated_at: -1, ...paginationParams?.sort },
61
+ });
62
+ cursorRef.current = newNext || null;
63
+ setPollAnswers((prev) => uniqBy([...prev, ...answers], 'id'));
64
+ } catch (e) {
65
+ setError(e as Error);
66
+ }
67
+ queryInProgress.current = false;
68
+ setLoading(false);
69
+ }, [paginationParams, poll]);
70
+
71
+ useEffect(() => {
72
+ if (!loadFirstPage || pollAnswers.length) return;
73
+ loadMore();
74
+ }, [loadFirstPage, loadMore, pollAnswers]);
75
+
76
+ useEffect(() => {
77
+ const castedListeners = ['poll.vote_casted', 'poll.vote_changed'].map((eventName) =>
78
+ client.on(eventName, (event) => {
79
+ if (event.poll?.id && event.poll.id !== poll.id) return;
80
+ const vote = event.poll_vote;
81
+ if (vote && isVoteAnswer(vote)) {
82
+ setPollAnswers([vote, ...pollAnswers.filter((answer) => answer.id !== vote.id)]);
83
+ }
84
+ }),
85
+ );
86
+
87
+ const removedListener = client.on('poll.vote_removed', (event) => {
88
+ if (event.poll?.id && event.poll.id !== poll.id) return;
89
+ const vote = event.poll_vote;
90
+ if (vote && isVoteAnswer(vote)) {
91
+ setPollAnswers(pollAnswers.filter((item) => item.id !== vote.id));
92
+ }
93
+ });
94
+
95
+ return () => {
96
+ castedListeners.forEach((listener) => listener.unsubscribe());
97
+ removedListener.unsubscribe();
98
+ };
99
+ }, [client, poll, pollAnswers]);
100
+
101
+ return {
102
+ error,
103
+ hasNextPage: cursorRef.current !== null,
104
+ loading,
105
+ loadMore,
106
+ next: cursorRef.current,
107
+ pollAnswers,
108
+ };
109
+ };