@planningcenter/chat-react-native 4.7.1-qa-staging.3 → 4.7.1-rc.0

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 (231) hide show
  1. package/build/components/conversation/attachments/expanded_link.js +8 -8
  2. package/build/components/conversation/attachments/expanded_link.js.map +1 -1
  3. package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
  4. package/build/components/conversation/attachments/generic_file_attachment.js +2 -2
  5. package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
  6. package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
  7. package/build/components/conversation/attachments/giphy_attachment.js +2 -2
  8. package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
  9. package/build/components/conversation/attachments/image_attachment.js +2 -2
  10. package/build/components/conversation/attachments/image_attachment.js.map +1 -1
  11. package/build/components/conversation/message_form.js +2 -2
  12. package/build/components/conversation/message_form.js.map +1 -1
  13. package/build/components/conversation/message_markdown.js +2 -2
  14. package/build/components/conversation/message_markdown.js.map +1 -1
  15. package/build/components/conversations/conversation_actions.d.ts.map +1 -1
  16. package/build/components/conversations/conversation_actions.js +193 -333
  17. package/build/components/conversations/conversation_actions.js.map +1 -1
  18. package/build/components/conversations/conversation_preview.d.ts.map +1 -1
  19. package/build/components/conversations/conversation_preview.js +91 -106
  20. package/build/components/conversations/conversation_preview.js.map +1 -1
  21. package/build/components/conversations/conversations.d.ts.map +1 -1
  22. package/build/components/conversations/conversations.js +56 -63
  23. package/build/components/conversations/conversations.js.map +1 -1
  24. package/build/components/conversations/conversations_blank_state.d.ts +1 -2
  25. package/build/components/conversations/conversations_blank_state.d.ts.map +1 -1
  26. package/build/components/conversations/conversations_blank_state.js +39 -71
  27. package/build/components/conversations/conversations_blank_state.js.map +1 -1
  28. package/build/components/group_conversation_list.d.ts.map +1 -1
  29. package/build/components/group_conversation_list.js +0 -1
  30. package/build/components/group_conversation_list.js.map +1 -1
  31. package/build/contexts/conversations_context.d.ts +1 -3
  32. package/build/contexts/conversations_context.d.ts.map +1 -1
  33. package/build/contexts/conversations_context.js +31 -39
  34. package/build/contexts/conversations_context.js.map +1 -1
  35. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +0 -6
  36. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
  37. package/build/hooks/use_api.d.ts +0 -6
  38. package/build/hooks/use_api.d.ts.map +1 -1
  39. package/build/hooks/use_api.js +5 -8
  40. package/build/hooks/use_api.js.map +1 -1
  41. package/build/hooks/use_clear_conversation_filters.d.ts.map +1 -1
  42. package/build/hooks/use_clear_conversation_filters.js +0 -1
  43. package/build/hooks/use_clear_conversation_filters.js.map +1 -1
  44. package/build/hooks/use_conversation.d.ts.map +1 -1
  45. package/build/hooks/use_conversation.js +1 -1
  46. package/build/hooks/use_conversation.js.map +1 -1
  47. package/build/hooks/use_features.d.ts +0 -1
  48. package/build/hooks/use_features.d.ts.map +1 -1
  49. package/build/hooks/use_features.js +1 -2
  50. package/build/hooks/use_features.js.map +1 -1
  51. package/build/hooks/use_groups.d.ts +0 -6
  52. package/build/hooks/use_groups.d.ts.map +1 -1
  53. package/build/hooks/use_groups_groups.d.ts +0 -6
  54. package/build/hooks/use_groups_groups.d.ts.map +1 -1
  55. package/build/hooks/use_live_relative_time.js +6 -5
  56. package/build/hooks/use_live_relative_time.js.map +1 -1
  57. package/build/hooks/use_teams.d.ts +0 -6
  58. package/build/hooks/use_teams.d.ts.map +1 -1
  59. package/build/navigation/index.d.ts +0 -5
  60. package/build/navigation/index.d.ts.map +1 -1
  61. package/build/navigation/index.js +0 -5
  62. package/build/navigation/index.js.map +1 -1
  63. package/build/screens/age_check/age_check_underage_screen.js +3 -3
  64. package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
  65. package/build/screens/attachment_actions/attachment_actions_screen.js +2 -2
  66. package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -1
  67. package/build/screens/bug_report_screen.js +4 -4
  68. package/build/screens/bug_report_screen.js.map +1 -1
  69. package/build/screens/conversation_details_screen.d.ts.map +1 -1
  70. package/build/screens/conversation_details_screen.js +394 -460
  71. package/build/screens/conversation_details_screen.js.map +1 -1
  72. package/build/screens/conversation_filters/components/conversation_filters.d.ts.map +1 -1
  73. package/build/screens/conversation_filters/components/conversation_filters.js +12 -53
  74. package/build/screens/conversation_filters/components/conversation_filters.js.map +1 -1
  75. package/build/screens/conversation_filters/components/rows.d.ts +3 -6
  76. package/build/screens/conversation_filters/components/rows.d.ts.map +1 -1
  77. package/build/screens/conversation_filters/components/rows.js +62 -99
  78. package/build/screens/conversation_filters/components/rows.js.map +1 -1
  79. package/build/screens/conversation_filters/context/conversation_filter_context.d.ts.map +1 -1
  80. package/build/screens/conversation_filters/context/conversation_filter_context.js +0 -4
  81. package/build/screens/conversation_filters/context/conversation_filter_context.js.map +1 -1
  82. package/build/screens/conversation_filters/filter_types.d.ts +0 -1
  83. package/build/screens/conversation_filters/filter_types.d.ts.map +1 -1
  84. package/build/screens/conversation_filters/filter_types.js +0 -1
  85. package/build/screens/conversation_filters/filter_types.js.map +1 -1
  86. package/build/screens/conversation_filters/hooks/filters.d.ts +0 -12
  87. package/build/screens/conversation_filters/hooks/filters.d.ts.map +1 -1
  88. package/build/screens/conversation_filters/screen_props.d.ts +0 -1
  89. package/build/screens/conversation_filters/screen_props.d.ts.map +1 -1
  90. package/build/screens/conversation_filters/screen_props.js.map +1 -1
  91. package/build/screens/conversations/components/filter_dropdown_list_header_component.d.ts.map +1 -1
  92. package/build/screens/conversations/components/filter_dropdown_list_header_component.js +126 -138
  93. package/build/screens/conversations/components/filter_dropdown_list_header_component.js.map +1 -1
  94. package/build/screens/conversations/components/list_header_component.d.ts.map +1 -1
  95. package/build/screens/conversations/components/list_header_component.js +90 -95
  96. package/build/screens/conversations/components/list_header_component.js.map +1 -1
  97. package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
  98. package/build/screens/conversations/components/search_list_header_component.js +95 -100
  99. package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
  100. package/build/screens/conversations/conversations_screen.d.ts +0 -1
  101. package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
  102. package/build/screens/conversations/conversations_screen.js +10 -18
  103. package/build/screens/conversations/conversations_screen.js.map +1 -1
  104. package/build/screens/get_help_screen.d.ts.map +1 -1
  105. package/build/screens/get_help_screen.js +21 -5
  106. package/build/screens/get_help_screen.js.map +1 -1
  107. package/build/screens/index.d.ts +0 -1
  108. package/build/screens/index.d.ts.map +1 -1
  109. package/build/screens/index.js +0 -1
  110. package/build/screens/index.js.map +1 -1
  111. package/build/types/resources/conversation_membership.d.ts +0 -1
  112. package/build/types/resources/conversation_membership.d.ts.map +1 -1
  113. package/build/types/resources/conversation_membership.js.map +1 -1
  114. package/build/utils/date.d.ts +1 -1
  115. package/build/utils/date.d.ts.map +1 -1
  116. package/build/utils/date.js +4 -4
  117. package/build/utils/date.js.map +1 -1
  118. package/build/utils/index.d.ts +0 -1
  119. package/build/utils/index.d.ts.map +1 -1
  120. package/build/utils/index.js +0 -1
  121. package/build/utils/index.js.map +1 -1
  122. package/build/utils/request/conversation.d.ts +1 -3
  123. package/build/utils/request/conversation.d.ts.map +1 -1
  124. package/build/utils/request/conversation.js +0 -4
  125. package/build/utils/request/conversation.js.map +1 -1
  126. package/build/vendor/font_awesome_pro_solid_icons.d.ts +0 -1
  127. package/build/vendor/font_awesome_pro_solid_icons.d.ts.map +1 -1
  128. package/build/vendor/font_awesome_pro_solid_icons.js +0 -5
  129. package/build/vendor/font_awesome_pro_solid_icons.js.map +1 -1
  130. package/package.json +3 -3
  131. package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +1 -1
  132. package/src/__tests__/screens/conversation_filters/components/conversation_filters.test.tsx +0 -6
  133. package/src/__tests__/screens/get_help_screen.test.ts +1 -1
  134. package/src/components/conversation/attachments/expanded_link.tsx +4 -4
  135. package/src/components/conversation/attachments/generic_file_attachment.tsx +5 -2
  136. package/src/components/conversation/attachments/giphy_attachment.tsx +4 -2
  137. package/src/components/conversation/attachments/image_attachment.tsx +2 -2
  138. package/src/components/conversation/message_form.tsx +2 -2
  139. package/src/components/conversation/message_markdown.tsx +2 -2
  140. package/src/components/conversations/__tests__/conversation_actions.test.tsx +2 -77
  141. package/src/components/conversations/__tests__/conversation_preview.test.tsx +0 -29
  142. package/src/components/conversations/__tests__/conversations.test.tsx +0 -26
  143. package/src/components/conversations/__tests__/conversations_blank_state.test.tsx +0 -17
  144. package/src/components/conversations/conversation_actions.tsx +4 -73
  145. package/src/components/conversations/conversation_preview.tsx +1 -12
  146. package/src/components/conversations/conversations.tsx +0 -9
  147. package/src/components/conversations/conversations_blank_state.tsx +0 -18
  148. package/src/components/group_conversation_list.tsx +1 -4
  149. package/src/contexts/conversations_context.tsx +1 -8
  150. package/src/hooks/__tests__/use_live_relative_time.test.tsx +22 -0
  151. package/src/hooks/use_api.ts +1 -2
  152. package/src/hooks/use_clear_conversation_filters.ts +0 -1
  153. package/src/hooks/use_conversation.ts +0 -1
  154. package/src/hooks/use_features.ts +0 -1
  155. package/src/hooks/use_live_relative_time.ts +1 -1
  156. package/src/navigation/index.tsx +0 -8
  157. package/src/screens/__tests__/conversation_details_screen.test.tsx +1 -49
  158. package/src/screens/age_check/age_check_underage_screen.tsx +3 -3
  159. package/src/screens/attachment_actions/attachment_actions_screen.tsx +2 -2
  160. package/src/screens/bug_report_screen.tsx +4 -4
  161. package/src/screens/conversation_details_screen.tsx +0 -19
  162. package/src/screens/conversation_filters/__tests__/conversation_filters.test.tsx +0 -42
  163. package/src/screens/conversation_filters/components/conversation_filters.tsx +3 -22
  164. package/src/screens/conversation_filters/components/rows.tsx +10 -44
  165. package/src/screens/conversation_filters/context/conversation_filter_context.tsx +0 -4
  166. package/src/screens/conversation_filters/filter_types.ts +0 -1
  167. package/src/screens/conversation_filters/screen_props.ts +0 -1
  168. package/src/screens/conversations/__tests__/conversations_screen.test.tsx +0 -1
  169. package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -42
  170. package/src/screens/conversations/components/__tests__/list_header_component.test.tsx +0 -1
  171. package/src/screens/conversations/components/filter_dropdown_list_header_component.tsx +5 -21
  172. package/src/screens/conversations/components/list_header_component.tsx +4 -14
  173. package/src/screens/conversations/components/search_list_header_component.tsx +4 -14
  174. package/src/screens/conversations/conversations_screen.tsx +0 -3
  175. package/src/screens/get_help_screen.tsx +19 -5
  176. package/src/screens/index.ts +0 -1
  177. package/src/types/resources/conversation_membership.ts +0 -1
  178. package/src/utils/__tests__/date.test.ts +10 -1
  179. package/src/utils/date.ts +4 -4
  180. package/src/utils/index.ts +0 -1
  181. package/src/utils/request/conversation.ts +0 -6
  182. package/src/vendor/font_awesome_pro_solid_icons.ts +0 -12
  183. package/build/components/conversations/hidden_indicator.d.ts +0 -4
  184. package/build/components/conversations/hidden_indicator.d.ts.map +0 -1
  185. package/build/components/conversations/hidden_indicator.js +0 -52
  186. package/build/components/conversations/hidden_indicator.js.map +0 -1
  187. package/build/components/conversations/hidden_results_footer.d.ts +0 -2
  188. package/build/components/conversations/hidden_results_footer.d.ts.map +0 -1
  189. package/build/components/conversations/hidden_results_footer.js +0 -34
  190. package/build/components/conversations/hidden_results_footer.js.map +0 -1
  191. package/build/components/display/toast.d.ts +0 -3
  192. package/build/components/display/toast.d.ts.map +0 -1
  193. package/build/components/display/toast.js +0 -224
  194. package/build/components/display/toast.js.map +0 -1
  195. package/build/hooks/use_hidden_conversations_count.d.ts +0 -2
  196. package/build/hooks/use_hidden_conversations_count.d.ts.map +0 -1
  197. package/build/hooks/use_hidden_conversations_count.js +0 -32
  198. package/build/hooks/use_hidden_conversations_count.js.map +0 -1
  199. package/build/hooks/use_hide_conversation.d.ts +0 -108
  200. package/build/hooks/use_hide_conversation.d.ts.map +0 -1
  201. package/build/hooks/use_hide_conversation.js +0 -243
  202. package/build/hooks/use_hide_conversation.js.map +0 -1
  203. package/build/hooks/use_hide_conversations_enabled.d.ts +0 -2
  204. package/build/hooks/use_hide_conversations_enabled.d.ts.map +0 -1
  205. package/build/hooks/use_hide_conversations_enabled.js +0 -18
  206. package/build/hooks/use_hide_conversations_enabled.js.map +0 -1
  207. package/build/screens/conversation_actions_screen.d.ts +0 -7
  208. package/build/screens/conversation_actions_screen.d.ts.map +0 -1
  209. package/build/screens/conversation_actions_screen.js +0 -89
  210. package/build/screens/conversation_actions_screen.js.map +0 -1
  211. package/build/utils/open_url.d.ts +0 -11
  212. package/build/utils/open_url.d.ts.map +0 -1
  213. package/build/utils/open_url.js +0 -46
  214. package/build/utils/open_url.js.map +0 -1
  215. package/build/utils/toast_store.d.ts +0 -21
  216. package/build/utils/toast_store.d.ts.map +0 -1
  217. package/build/utils/toast_store.js +0 -27
  218. package/build/utils/toast_store.js.map +0 -1
  219. package/src/components/conversations/hidden_indicator.tsx +0 -30
  220. package/src/components/conversations/hidden_results_footer.tsx +0 -25
  221. package/src/components/display/__tests__/toast.test.tsx +0 -55
  222. package/src/components/display/toast.tsx +0 -115
  223. package/src/hooks/__tests__/use_hide_conversation.test.tsx +0 -189
  224. package/src/hooks/use_hidden_conversations_count.ts +0 -14
  225. package/src/hooks/use_hide_conversation.ts +0 -128
  226. package/src/hooks/use_hide_conversations_enabled.ts +0 -7
  227. package/src/screens/__tests__/conversation_actions_screen.test.tsx +0 -79
  228. package/src/screens/conversation_actions_screen.tsx +0 -53
  229. package/src/utils/__tests__/open_url.test.ts +0 -67
  230. package/src/utils/open_url.ts +0 -47
  231. package/src/utils/toast_store.ts +0 -45
@@ -1,27 +0,0 @@
1
- let currentToast = null;
2
- let nextId = 1;
3
- const listeners = new Set();
4
- const emit = () => listeners.forEach(listener => listener());
5
- export const toastStore = {
6
- getSnapshot: () => currentToast,
7
- subscribe: listener => {
8
- listeners.add(listener);
9
- return () => {
10
- listeners.delete(listener);
11
- };
12
- }
13
- };
14
- export function showToast(options) {
15
- currentToast = {
16
- ...options,
17
- id: nextId++
18
- };
19
- emit();
20
- }
21
- export function dismissToast(id) {
22
- if (!currentToast) return;
23
- if (id !== undefined && currentToast.id !== id) return;
24
- currentToast = null;
25
- emit();
26
- }
27
- //# sourceMappingURL=toast_store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toast_store.js","names":["currentToast","nextId","listeners","Set","emit","forEach","listener","toastStore","getSnapshot","subscribe","add","delete","showToast","options","id","dismissToast","undefined"],"sources":["../../src/utils/toast_store.ts"],"sourcesContent":["export interface ToastAction {\n label: string\n onPress: () => void\n}\n\nexport interface ToastOptions {\n title: string\n subtitle?: string\n action?: ToastAction\n}\n\nexport interface ToastState extends ToastOptions {\n id: number\n}\n\ntype Listener = () => void\n\nlet currentToast: ToastState | null = null\nlet nextId = 1\nconst listeners = new Set<Listener>()\n\nconst emit = () => listeners.forEach(listener => listener())\n\nexport const toastStore = {\n getSnapshot: () => currentToast,\n subscribe: (listener: Listener) => {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n },\n}\n\nexport function showToast(options: ToastOptions) {\n currentToast = { ...options, id: nextId++ }\n emit()\n}\n\nexport function dismissToast(id?: number) {\n if (!currentToast) return\n if (id !== undefined && currentToast.id !== id) return\n\n currentToast = null\n emit()\n}\n"],"mappings":"AAiBA,IAAIA,YAA+B,GAAG,IAAI;AAC1C,IAAIC,MAAM,GAAG,CAAC;AACd,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,MAAMC,IAAI,GAAGA,CAAA,KAAMF,SAAS,CAACG,OAAO,CAACC,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC;AAE5D,OAAO,MAAMC,UAAU,GAAG;EACxBC,WAAW,EAAEA,CAAA,KAAMR,YAAY;EAC/BS,SAAS,EAAGH,QAAkB,IAAK;IACjCJ,SAAS,CAACQ,GAAG,CAACJ,QAAQ,CAAC;IACvB,OAAO,MAAM;MACXJ,SAAS,CAACS,MAAM,CAACL,QAAQ,CAAC;IAC5B,CAAC;EACH;AACF,CAAC;AAED,OAAO,SAASM,SAASA,CAACC,OAAqB,EAAE;EAC/Cb,YAAY,GAAG;IAAE,GAAGa,OAAO;IAAEC,EAAE,EAAEb,MAAM;EAAG,CAAC;EAC3CG,IAAI,CAAC,CAAC;AACR;AAEA,OAAO,SAASW,YAAYA,CAACD,EAAW,EAAE;EACxC,IAAI,CAACd,YAAY,EAAE;EACnB,IAAIc,EAAE,KAAKE,SAAS,IAAIhB,YAAY,CAACc,EAAE,KAAKA,EAAE,EAAE;EAEhDd,YAAY,GAAG,IAAI;EACnBI,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
@@ -1,30 +0,0 @@
1
- import React from 'react'
2
- import { StyleSheet } from 'react-native'
3
- import { useTheme } from '../../hooks'
4
- import { MAX_FONT_SIZE_MULTIPLIER } from '../../utils'
5
- import { Icon } from '../display'
6
-
7
- export const HiddenIndicator = ({ hidden }: { hidden: boolean }) => {
8
- const styles = useStyles()
9
-
10
- if (!hidden) return null
11
-
12
- return (
13
- <Icon
14
- name="general.hideEye"
15
- style={styles.hiddenIcon}
16
- testID="conversation-hidden-icon"
17
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
18
- />
19
- )
20
- }
21
-
22
- const useStyles = () => {
23
- const { colors } = useTheme()
24
- return StyleSheet.create({
25
- hiddenIcon: {
26
- color: colors.iconColorDefaultDim,
27
- fontSize: 16,
28
- },
29
- })
30
- }
@@ -1,25 +0,0 @@
1
- import React from 'react'
2
- import { StyleSheet, View } from 'react-native'
3
- import { Text } from '../display'
4
-
5
- export function HiddenResultsFooter() {
6
- return (
7
- <View style={styles.container}>
8
- <Text variant="tertiary" style={styles.text}>
9
- Hidden just for you. A conversation comes back to your list when someone sends a new
10
- message, unless it&rsquo;s also silenced.
11
- </Text>
12
- </View>
13
- )
14
- }
15
-
16
- const styles = StyleSheet.create({
17
- container: {
18
- alignItems: 'center',
19
- paddingVertical: 24,
20
- paddingHorizontal: 16,
21
- },
22
- text: {
23
- textAlign: 'center',
24
- },
25
- })
@@ -1,55 +0,0 @@
1
- import { act, fireEvent, render } from '@testing-library/react-native'
2
- import React from 'react'
3
- import { SafeAreaProvider } from 'react-native-safe-area-context'
4
- import { dismissToast, showToast } from '../../../utils/toast_store'
5
- import { Toast, TOAST_DURATION_MS } from '../toast'
6
-
7
- const safeAreaMetrics = {
8
- frame: { x: 0, y: 0, width: 390, height: 844 },
9
- insets: { top: 0, right: 0, bottom: 0, left: 0 },
10
- }
11
-
12
- const renderToast = () =>
13
- render(
14
- <SafeAreaProvider initialMetrics={safeAreaMetrics}>
15
- <Toast />
16
- </SafeAreaProvider>
17
- )
18
-
19
- describe('Toast', () => {
20
- beforeEach(() => {
21
- jest.useFakeTimers()
22
- dismissToast()
23
- })
24
-
25
- afterEach(() => {
26
- jest.useRealTimers()
27
- })
28
-
29
- it('runs the action and dismisses when the action is pressed', () => {
30
- const onUndo = jest.fn()
31
- const view = renderToast()
32
- act(() =>
33
- showToast({
34
- title: 'Conversation hidden',
35
- subtitle: 'Subtitle',
36
- action: { label: 'Undo', onPress: onUndo },
37
- })
38
- )
39
-
40
- expect(view.getByText('Subtitle')).toBeTruthy()
41
- fireEvent.press(view.getByText('Undo'))
42
-
43
- expect(onUndo).toHaveBeenCalledTimes(1)
44
- expect(view.queryByText('Conversation hidden')).toBeNull()
45
- })
46
-
47
- it('dismisses itself after a delay', () => {
48
- const view = renderToast()
49
- act(() => showToast({ title: 'Conversation hidden' }))
50
-
51
- act(() => jest.advanceTimersByTime(TOAST_DURATION_MS))
52
-
53
- expect(view.queryByText('Conversation hidden')).toBeNull()
54
- })
55
- })
@@ -1,115 +0,0 @@
1
- import React, { useEffect, useSyncExternalStore } from 'react'
2
- import { AccessibilityInfo, StyleSheet, View } from 'react-native'
3
- import Animated, { FadeInDown, FadeOutDown, ReduceMotion } from 'react-native-reanimated'
4
- import { useSafeAreaInsets } from 'react-native-safe-area-context'
5
- import { useReduceMotion, useTheme } from '../../hooks'
6
- import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../utils/styles'
7
- import { dismissToast, toastStore } from '../../utils/toast_store'
8
- import { Text } from './text'
9
- import { TextButton } from './text_button'
10
-
11
- export const TOAST_DURATION_MS = 5000
12
-
13
- export function Toast() {
14
- const toast = useSyncExternalStore(toastStore.subscribe, toastStore.getSnapshot)
15
- const styles = useStyles()
16
- const reduceMotion = useReduceMotion() ? ReduceMotion.Always : ReduceMotion.Never
17
-
18
- useEffect(() => {
19
- if (!toast) return
20
-
21
- AccessibilityInfo.announceForAccessibility(
22
- [toast.title, toast.subtitle].filter(Boolean).join('. ')
23
- )
24
- const timeout = setTimeout(() => dismissToast(toast.id), TOAST_DURATION_MS)
25
- return () => clearTimeout(timeout)
26
- }, [toast])
27
-
28
- useEffect(() => () => dismissToast(), [])
29
-
30
- if (!toast) return null
31
-
32
- const { id, title, subtitle, action } = toast
33
-
34
- return (
35
- <View style={styles.container} pointerEvents="box-none">
36
- <Animated.View
37
- key={id}
38
- entering={FadeInDown.duration(200).reduceMotion(reduceMotion)}
39
- exiting={FadeOutDown.duration(200).reduceMotion(reduceMotion)}
40
- style={styles.toast}
41
- accessibilityLiveRegion="polite"
42
- testID="toast"
43
- >
44
- <View style={styles.content}>
45
- <Text
46
- style={styles.title}
47
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
48
- accessibilityRole="alert"
49
- >
50
- {title}
51
- </Text>
52
- {Boolean(subtitle) && (
53
- <Text
54
- variant="footnote"
55
- style={styles.subtitle}
56
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
57
- >
58
- {subtitle}
59
- </Text>
60
- )}
61
- </View>
62
- {action && (
63
- <TextButton
64
- textStyle={styles.actionText}
65
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
66
- onPress={() => {
67
- dismissToast(id)
68
- action.onPress()
69
- }}
70
- >
71
- {action.label}
72
- </TextButton>
73
- )}
74
- </Animated.View>
75
- </View>
76
- )
77
- }
78
-
79
- const useStyles = () => {
80
- const { colors } = useTheme()
81
- const { bottom } = useSafeAreaInsets()
82
-
83
- return StyleSheet.create({
84
- container: {
85
- position: 'absolute',
86
- left: 0,
87
- right: 0,
88
- bottom: bottom + 16,
89
- paddingHorizontal: 16,
90
- },
91
- toast: {
92
- flexDirection: 'row',
93
- alignItems: 'center',
94
- gap: 16,
95
- paddingVertical: 12,
96
- paddingHorizontal: 16,
97
- borderRadius: 8,
98
- backgroundColor: colors.fillColorNeutral010,
99
- },
100
- content: {
101
- flex: 1,
102
- gap: 2,
103
- },
104
- title: {
105
- color: colors.fillColorNeutral100Inverted,
106
- fontWeight: '600',
107
- },
108
- subtitle: {
109
- color: colors.fillColorNeutral070,
110
- },
111
- actionText: {
112
- color: colors.fillColorNeutral100Inverted,
113
- },
114
- })
115
- }
@@ -1,189 +0,0 @@
1
- import { QueryClientProvider } from '@tanstack/react-query'
2
- import { act, renderHook } from '@testing-library/react-native'
3
- import React from 'react'
4
- import { Alert } from 'react-native'
5
- import { buildTestQueryClient } from '../../__utils__/query_client'
6
- import type { ConversationResource } from '../../types'
7
- import { getConversationsRequestArgs } from '../../utils/request/conversation'
8
- import { dismissToast, toastStore } from '../../utils/toast_store'
9
- import { getConversationRequestArgs } from '../use_conversation'
10
- import {
11
- HIDDEN_AND_SILENCED_TOAST_SUBTITLE,
12
- HIDDEN_TOAST_SUBTITLE,
13
- useHideConversation,
14
- } from '../use_hide_conversation'
15
- import { getRequestQueryKey } from '../use_suspense_api'
16
-
17
- const mockPatch = jest.fn()
18
- jest.mock('../use_api_client', () => ({
19
- useApiClient: () => ({ chat: { patch: mockPatch } }),
20
- }))
21
-
22
- const conversation = { id: 7, muted: false } as ConversationResource
23
- const otherConversation = { id: 8, muted: false } as ConversationResource
24
- const conversationKey = getRequestQueryKey(getConversationRequestArgs({ conversation_id: 7 }))
25
- const allKey = getRequestQueryKey(getConversationsRequestArgs({ gids: 'all' }))
26
- const unreadKey = getRequestQueryKey(
27
- getConversationsRequestArgs({ gids: 'all', show_unread: true })
28
- )
29
- const hiddenKey = getRequestQueryKey(getConversationsRequestArgs({ show_hidden: true }))
30
-
31
- const listData = (conversations: ConversationResource[]) => ({
32
- pages: [{ data: conversations, links: {}, meta: { count: conversations.length } }],
33
- pageParams: [{}],
34
- })
35
-
36
- const listIds = (queryKey: unknown[]) =>
37
- (
38
- queryClient.getQueryData(queryKey) as ReturnType<typeof listData> | undefined
39
- )?.pages[0].data.map(({ id }) => id)
40
-
41
- const buildQueryClient = () =>
42
- buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
43
-
44
- let queryClient = buildQueryClient()
45
-
46
- const wrapper = ({ children }: { children: React.ReactNode }) => (
47
- <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
48
- )
49
-
50
- const renderHide = (target: ConversationResource = conversation, hidden?: boolean) =>
51
- renderHook(() => useHideConversation({ conversation: target, hidden }), { wrapper })
52
-
53
- describe('useHideConversation', () => {
54
- beforeEach(() => {
55
- queryClient = buildQueryClient()
56
- queryClient.setQueryData(allKey, listData([conversation, otherConversation]))
57
- queryClient.setQueryData(unreadKey, listData([conversation]))
58
- queryClient.setQueryData(conversationKey, {
59
- data: { id: 7, conversationMembership: { muted: false } },
60
- })
61
- mockPatch.mockReset()
62
- dismissToast()
63
- jest.spyOn(Alert, 'alert').mockImplementation(() => {})
64
- })
65
-
66
- afterEach(() => {
67
- jest.restoreAllMocks()
68
- })
69
-
70
- it('removes the conversation from every list before the request resolves', async () => {
71
- mockPatch.mockReturnValue(new Promise(() => {}))
72
- const { result } = renderHide()
73
-
74
- await act(async () => result.current.setHidden(true))
75
-
76
- expect(listIds(allKey)).toEqual([8])
77
- expect(listIds(unreadKey)).toEqual([])
78
- expect(queryClient.getQueryData(conversationKey)).toEqual({
79
- data: { id: 7, conversationMembership: { muted: false, hidden: true } },
80
- })
81
- })
82
-
83
- it('patches hidden on the membership', async () => {
84
- mockPatch.mockResolvedValue({ data: {} })
85
- const { result } = renderHide()
86
-
87
- await act(() => result.current.mutateAsync(true))
88
-
89
- expect(mockPatch).toHaveBeenCalledWith({
90
- url: '/me/conversations/7/conversation_membership',
91
- data: {
92
- data: { type: 'ConversationMembership', attributes: { hidden: true } },
93
- fields: { ConversationMembership: 'hidden' },
94
- },
95
- })
96
- })
97
-
98
- it.each([
99
- [false, HIDDEN_TOAST_SUBTITLE],
100
- [true, HIDDEN_AND_SILENCED_TOAST_SUBTITLE],
101
- ])('shows an undo toast for muted=%s', async (muted, subtitle) => {
102
- mockPatch.mockResolvedValue({ data: {} })
103
- const { result } = renderHide({ ...conversation, muted })
104
-
105
- await act(() => result.current.mutateAsync(true))
106
-
107
- expect(toastStore.getSnapshot()).toMatchObject({
108
- title: 'Conversation hidden',
109
- subtitle,
110
- action: { label: 'Undo' },
111
- })
112
- })
113
-
114
- it('restores the lists and unhides on undo', async () => {
115
- mockPatch.mockResolvedValue({ data: {} })
116
- const { result } = renderHide()
117
- await act(() => result.current.mutateAsync(true))
118
-
119
- await act(async () => toastStore.getSnapshot()?.action?.onPress())
120
-
121
- expect(listIds(allKey)).toEqual([7, 8])
122
- expect(listIds(unreadKey)).toEqual([7])
123
- expect(mockPatch).toHaveBeenLastCalledWith(
124
- expect.objectContaining({
125
- data: expect.objectContaining({
126
- data: { type: 'ConversationMembership', attributes: { hidden: false } },
127
- }),
128
- })
129
- )
130
- })
131
-
132
- it('puts the conversation back and alerts when hiding fails', async () => {
133
- mockPatch.mockRejectedValue(new Error('nope'))
134
- const { result } = renderHide()
135
-
136
- await act(() => result.current.mutateAsync(true).catch(() => {}))
137
-
138
- expect(listIds(allKey)).toEqual([7, 8])
139
- expect(queryClient.getQueryData(conversationKey)).toEqual({
140
- data: { id: 7, conversationMembership: { muted: false, hidden: false } },
141
- })
142
- expect(toastStore.getSnapshot()).toBeNull()
143
- expect(Alert.alert).toHaveBeenCalledWith(
144
- 'Oops',
145
- "Couldn't hide this conversation. Please try again."
146
- )
147
- })
148
-
149
- describe('from the hidden list', () => {
150
- beforeEach(() => {
151
- queryClient.setQueryData(hiddenKey, listData([conversation, otherConversation]))
152
- })
153
-
154
- it('removes the conversation from the hidden list before the request resolves', async () => {
155
- mockPatch.mockReturnValue(new Promise(() => {}))
156
- const { result } = renderHide(conversation, true)
157
-
158
- expect(result.current.hidden).toBe(true)
159
-
160
- await act(async () => result.current.setHidden(false))
161
-
162
- expect(listIds(hiddenKey)).toEqual([8])
163
- expect(listIds(allKey)).toEqual([7, 8])
164
- })
165
-
166
- it('puts the conversation back in the hidden list when unhiding fails', async () => {
167
- mockPatch.mockRejectedValue(new Error('nope'))
168
- const { result } = renderHide(conversation, true)
169
-
170
- await act(() => result.current.mutateAsync(false).catch(() => {}))
171
-
172
- expect(listIds(hiddenKey)).toEqual([7, 8])
173
- expect(Alert.alert).toHaveBeenCalledWith(
174
- 'Oops',
175
- "Couldn't unhide this conversation. Please try again."
176
- )
177
- })
178
-
179
- it('refreshes the hidden list after hiding elsewhere', async () => {
180
- mockPatch.mockResolvedValue({ data: {} })
181
- const { result } = renderHide(otherConversation)
182
-
183
- await act(() => result.current.mutateAsync(true))
184
-
185
- expect(queryClient.getQueryState(hiddenKey)?.isInvalidated).toBe(true)
186
- expect(queryClient.getQueryState(unreadKey)?.isInvalidated).toBe(false)
187
- })
188
- })
189
- })
@@ -1,14 +0,0 @@
1
- import { ConversationResource } from '../types'
2
- import { getConversationsRequestArgs } from '../utils/request/conversation'
3
- import { useApiPaginator } from './use_api'
4
- import { useHideConversationsEnabled } from './use_hide_conversations_enabled'
5
-
6
- export function useHiddenConversationsCount() {
7
- const enabled = useHideConversationsEnabled()
8
- const { totalCount } = useApiPaginator<ConversationResource>(
9
- getConversationsRequestArgs({ show_hidden: true }),
10
- { enabled }
11
- )
12
-
13
- return enabled ? totalCount : 0
14
- }
@@ -1,128 +0,0 @@
1
- import { InfiniteData, QueryKey, useMutation, useQueryClient } from '@tanstack/react-query'
2
- import { Alert } from 'react-native'
3
- import {
4
- ApiCollection,
5
- ApiResource,
6
- ConversationMembershipResource,
7
- ConversationResource,
8
- } from '../types'
9
- import { deleteRecordInPagesData } from '../utils/cache/page_mutations'
10
- import { Haptic } from '../utils/native_adapters'
11
- import {
12
- getConversationsRequestArgs,
13
- HIDDEN_CONVERSATIONS_FILTER,
14
- } from '../utils/request/conversation'
15
- import { showToast } from '../utils/toast_store'
16
- import { useApiClient } from './use_api_client'
17
- import { getConversationRequestArgs } from './use_conversation'
18
- import { getRequestQueryKey } from './use_suspense_api'
19
-
20
- type ConversationsData = InfiniteData<ApiCollection<ConversationResource>>
21
- type ListsSnapshot = Array<[QueryKey, ConversationsData | undefined]>
22
-
23
- export const HIDDEN_TOAST_TITLE = 'Conversation hidden'
24
- export const HIDDEN_TOAST_SUBTITLE = "It'll come back if someone sends a new message."
25
- export const HIDDEN_AND_SILENCED_TOAST_SUBTITLE =
26
- "It's silenced too, so it stays hidden until you unhide it."
27
-
28
- export const useHideConversation = ({
29
- conversation,
30
- hidden: knownHidden,
31
- }: {
32
- conversation: ConversationResource
33
- hidden?: boolean
34
- }) => {
35
- const apiClient = useApiClient()
36
- const queryClient = useQueryClient()
37
- const listsQueryKey = [getConversationsRequestArgs().url]
38
- const hiddenListsQueryKey = [...listsQueryKey, { filter: HIDDEN_CONVERSATIONS_FILTER }]
39
- const conversationQueryKey = getRequestQueryKey(
40
- getConversationRequestArgs({ conversation_id: conversation.id })
41
- )
42
- const hidden = knownHidden ?? !!conversation.conversationMembership?.hidden
43
-
44
- const setMembershipHidden = (value: boolean) =>
45
- queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, prev => {
46
- if (!prev?.data) return prev
47
-
48
- return {
49
- ...prev,
50
- data: {
51
- ...prev.data,
52
- conversationMembership: { ...prev.data.conversationMembership, hidden: value },
53
- },
54
- }
55
- })
56
-
57
- const removeFromLists = (queryKey: QueryKey) =>
58
- queryClient.setQueriesData<ConversationsData>({ queryKey }, prev => {
59
- if (!prev?.pages) return prev
60
-
61
- return deleteRecordInPagesData({ data: prev, record: { id: conversation.id } })
62
- })
63
-
64
- const restoreLists = (lists: ListsSnapshot) => {
65
- lists.forEach(([queryKey, data]) => {
66
- queryClient.setQueryData<ConversationsData>(queryKey, data)
67
- })
68
- }
69
-
70
- const { mutate: setHidden, ...mutation } = useMutation({
71
- mutationKey: ['hideConversation', conversation.id],
72
- scope: { id: `hideConversation-${conversation.id}` },
73
- onMutate: async (value: boolean) => {
74
- await queryClient.cancelQueries({ queryKey: listsQueryKey })
75
- const previousLists = queryClient.getQueriesData<ConversationsData>({
76
- queryKey: listsQueryKey,
77
- })
78
-
79
- removeFromLists(value ? listsQueryKey : hiddenListsQueryKey)
80
- setMembershipHidden(value)
81
-
82
- return { previousLists }
83
- },
84
- mutationFn: (value: boolean) =>
85
- apiClient.chat.patch<ApiResource<ConversationMembershipResource>>({
86
- url: `/me/conversations/${conversation.id}/conversation_membership`,
87
- data: {
88
- data: { type: 'ConversationMembership', attributes: { hidden: value } },
89
- fields: { ConversationMembership: 'hidden' },
90
- },
91
- }),
92
- onSuccess: (_response, value, { previousLists }) => {
93
- Haptic.notificationSuccess()
94
-
95
- if (!value) {
96
- queryClient.invalidateQueries({ queryKey: listsQueryKey })
97
- return
98
- }
99
-
100
- queryClient.invalidateQueries({ queryKey: hiddenListsQueryKey })
101
- showToast({
102
- title: HIDDEN_TOAST_TITLE,
103
- subtitle: conversation.muted ? HIDDEN_AND_SILENCED_TOAST_SUBTITLE : HIDDEN_TOAST_SUBTITLE,
104
- action: {
105
- label: 'Undo',
106
- onPress: () => {
107
- restoreLists(previousLists)
108
- setHidden(false)
109
- },
110
- },
111
- })
112
- },
113
- onError: (_error, value, context) => {
114
- if (context) restoreLists(context.previousLists)
115
- setMembershipHidden(!value)
116
- Alert.alert(
117
- 'Oops',
118
- `Couldn't ${value ? 'hide' : 'unhide'} this conversation. Please try again.`
119
- )
120
- },
121
- })
122
-
123
- return {
124
- hidden,
125
- setHidden,
126
- ...mutation,
127
- }
128
- }
@@ -1,7 +0,0 @@
1
- import { availableFeatures, useFeatures } from './use_features'
2
-
3
- export function useHideConversationsEnabled() {
4
- const { featureEnabled } = useFeatures()
5
-
6
- return featureEnabled(availableFeatures.hide_conversations)
7
- }
@@ -1,79 +0,0 @@
1
- import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
2
- import { fireEvent, render } from '@testing-library/react-native'
3
- import React from 'react'
4
- import { SafeAreaProvider } from 'react-native-safe-area-context'
5
- import type { ConversationResource } from '../../types'
6
- import { ConversationActionsScreen } from '../conversation_actions_screen'
7
-
8
- const mockNavigation = { goBack: jest.fn() }
9
- jest.mock('@react-navigation/native', () => ({
10
- ...jest.requireActual('@react-navigation/native'),
11
- useNavigation: () => mockNavigation,
12
- }))
13
- jest.mock('@react-navigation/elements', () => ({
14
- ...jest.requireActual('@react-navigation/elements'),
15
- useHeaderHeight: () => 0,
16
- }))
17
-
18
- const conversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
19
- jest.mock('../../hooks/use_conversation', () => ({
20
- useConversation: () => ({ data: conversation }),
21
- }))
22
-
23
- let mockHidden = false
24
- const mockSetHidden = jest.fn()
25
- jest.mock('../../hooks/use_hide_conversation', () => ({
26
- useHideConversation: () => ({ hidden: mockHidden, setHidden: mockSetHidden, isPending: false }),
27
- }))
28
-
29
- let mockHideEnabled = true
30
- jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
31
- useHideConversationsEnabled: () => mockHideEnabled,
32
- }))
33
-
34
- const safeAreaMetrics = {
35
- frame: { x: 0, y: 0, width: 390, height: 844 },
36
- insets: { top: 0, right: 0, bottom: 0, left: 0 },
37
- }
38
-
39
- const renderScreen = () =>
40
- render(
41
- <SafeAreaProvider initialMetrics={safeAreaMetrics}>
42
- <ThemeProvider value={DefaultTheme}>
43
- <ConversationActionsScreen route={{ params: { conversation_id: 7 } }} />
44
- </ThemeProvider>
45
- </SafeAreaProvider>
46
- )
47
-
48
- describe('ConversationActionsScreen', () => {
49
- beforeEach(() => {
50
- mockHidden = false
51
- mockHideEnabled = true
52
- jest.clearAllMocks()
53
- })
54
-
55
- it('offers nothing when the flag is off', () => {
56
- mockHideEnabled = false
57
- const { queryByText } = renderScreen()
58
-
59
- expect(queryByText('Hide conversation')).toBeNull()
60
- })
61
-
62
- it('hides the conversation and closes the sheet', () => {
63
- const { getByText } = renderScreen()
64
-
65
- fireEvent.press(getByText('Hide conversation'))
66
-
67
- expect(mockSetHidden).toHaveBeenCalledWith(true)
68
- expect(mockNavigation.goBack).toHaveBeenCalledTimes(1)
69
- })
70
-
71
- it('unhides a hidden conversation', () => {
72
- mockHidden = true
73
- const { getByText } = renderScreen()
74
-
75
- fireEvent.press(getByText('Unhide conversation'))
76
-
77
- expect(mockSetHidden).toHaveBeenCalledWith(false)
78
- })
79
- })