@planningcenter/chat-react-native 3.4.1-rc.9 → 3.4.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 (109) hide show
  1. package/build/components/conversation/attachments/audio_attachment.d.ts +2 -1
  2. package/build/components/conversation/attachments/audio_attachment.d.ts.map +1 -1
  3. package/build/components/conversation/attachments/audio_attachment.js +14 -11
  4. package/build/components/conversation/attachments/audio_attachment.js.map +1 -1
  5. package/build/components/conversation/attachments/expanded_link.d.ts +4 -2
  6. package/build/components/conversation/attachments/expanded_link.d.ts.map +1 -1
  7. package/build/components/conversation/attachments/expanded_link.js +5 -4
  8. package/build/components/conversation/attachments/expanded_link.js.map +1 -1
  9. package/build/components/conversation/attachments/generic_file_attachment.d.ts +2 -1
  10. package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
  11. package/build/components/conversation/attachments/generic_file_attachment.js +5 -4
  12. package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
  13. package/build/components/conversation/attachments/giphy_attachment.d.ts +2 -1
  14. package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
  15. package/build/components/conversation/attachments/giphy_attachment.js +2 -2
  16. package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
  17. package/build/components/conversation/attachments/image_attachment.d.ts +4 -2
  18. package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
  19. package/build/components/conversation/attachments/image_attachment.js +5 -4
  20. package/build/components/conversation/attachments/image_attachment.js.map +1 -1
  21. package/build/components/conversation/attachments/video_attachment.d.ts +2 -1
  22. package/build/components/conversation/attachments/video_attachment.d.ts.map +1 -1
  23. package/build/components/conversation/attachments/video_attachment.js +5 -4
  24. package/build/components/conversation/attachments/video_attachment.js.map +1 -1
  25. package/build/components/conversation/message.d.ts.map +1 -1
  26. package/build/components/conversation/message.js +6 -1
  27. package/build/components/conversation/message.js.map +1 -1
  28. package/build/components/conversation/message_attachments.d.ts +1 -0
  29. package/build/components/conversation/message_attachments.d.ts.map +1 -1
  30. package/build/components/conversation/message_attachments.js +9 -9
  31. package/build/components/conversation/message_attachments.js.map +1 -1
  32. package/build/components/page/error_boundary.d.ts.map +1 -1
  33. package/build/components/page/error_boundary.js +4 -3
  34. package/build/components/page/error_boundary.js.map +1 -1
  35. package/build/components/primitive/actions_form_sheet.d.ts +34 -0
  36. package/build/components/primitive/actions_form_sheet.d.ts.map +1 -0
  37. package/build/components/primitive/actions_form_sheet.js +91 -0
  38. package/build/components/primitive/actions_form_sheet.js.map +1 -0
  39. package/build/contexts/chat_context.d.ts +7 -6
  40. package/build/contexts/chat_context.d.ts.map +1 -1
  41. package/build/contexts/chat_context.js +2 -2
  42. package/build/contexts/chat_context.js.map +1 -1
  43. package/build/hooks/use_conversation.d.ts +4 -4
  44. package/build/hooks/use_suspense_api.d.ts +6 -5
  45. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  46. package/build/hooks/use_suspense_api.js +16 -3
  47. package/build/hooks/use_suspense_api.js.map +1 -1
  48. package/build/index.d.ts +6 -4
  49. package/build/index.d.ts.map +1 -1
  50. package/build/index.js +6 -4
  51. package/build/index.js.map +1 -1
  52. package/build/navigation/index.d.ts +5 -0
  53. package/build/navigation/index.d.ts.map +1 -1
  54. package/build/navigation/index.js +6 -0
  55. package/build/navigation/index.js.map +1 -1
  56. package/build/screens/attachment_actions/attachment_actions_screen.d.ts +9 -0
  57. package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -0
  58. package/build/screens/attachment_actions/attachment_actions_screen.js +39 -0
  59. package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -0
  60. package/build/types/api_primitives.d.ts +1 -1
  61. package/build/types/api_primitives.d.ts.map +1 -1
  62. package/build/types/api_primitives.js.map +1 -1
  63. package/build/utils/index.d.ts +1 -0
  64. package/build/utils/index.d.ts.map +1 -1
  65. package/build/utils/index.js +1 -0
  66. package/build/utils/index.js.map +1 -1
  67. package/build/utils/native_adapters/configuration.d.ts +8 -5
  68. package/build/utils/native_adapters/configuration.d.ts.map +1 -1
  69. package/build/utils/native_adapters/configuration.js +7 -5
  70. package/build/utils/native_adapters/configuration.js.map +1 -1
  71. package/build/utils/native_adapters/index.d.ts +1 -0
  72. package/build/utils/native_adapters/index.d.ts.map +1 -1
  73. package/build/utils/native_adapters/index.js +1 -0
  74. package/build/utils/native_adapters/index.js.map +1 -1
  75. package/build/utils/native_adapters/log.d.ts +15 -0
  76. package/build/utils/native_adapters/log.d.ts.map +1 -0
  77. package/build/utils/native_adapters/log.js +21 -0
  78. package/build/utils/native_adapters/log.js.map +1 -0
  79. package/build/utils/navigation_constants.d.ts +2 -0
  80. package/build/utils/navigation_constants.d.ts.map +1 -0
  81. package/build/utils/navigation_constants.js +11 -0
  82. package/build/utils/navigation_constants.js.map +1 -0
  83. package/build/utils/response_error.d.ts +9 -0
  84. package/build/utils/response_error.d.ts.map +1 -0
  85. package/build/utils/response_error.js +15 -0
  86. package/build/utils/response_error.js.map +1 -0
  87. package/package.json +2 -2
  88. package/src/components/conversation/attachments/audio_attachment.tsx +25 -17
  89. package/src/components/conversation/attachments/expanded_link.tsx +17 -4
  90. package/src/components/conversation/attachments/generic_file_attachment.tsx +9 -3
  91. package/src/components/conversation/attachments/giphy_attachment.tsx +8 -1
  92. package/src/components/conversation/attachments/image_attachment.tsx +12 -4
  93. package/src/components/conversation/attachments/video_attachment.tsx +9 -3
  94. package/src/components/conversation/message.tsx +12 -1
  95. package/src/components/conversation/message_attachments.tsx +43 -8
  96. package/src/components/page/error_boundary.tsx +4 -3
  97. package/src/components/primitive/actions_form_sheet.tsx +159 -0
  98. package/src/contexts/chat_context.tsx +12 -8
  99. package/src/hooks/use_suspense_api.ts +23 -7
  100. package/src/index.tsx +6 -12
  101. package/src/navigation/index.tsx +6 -0
  102. package/src/screens/attachment_actions/attachment_actions_screen.tsx +56 -0
  103. package/src/types/api_primitives.ts +1 -1
  104. package/src/utils/index.ts +1 -0
  105. package/src/utils/native_adapters/configuration.ts +8 -5
  106. package/src/utils/native_adapters/index.ts +1 -0
  107. package/src/utils/native_adapters/log.ts +29 -0
  108. package/src/utils/navigation_constants.ts +12 -0
  109. package/src/utils/response_error.ts +17 -0
@@ -0,0 +1,56 @@
1
+ import { StaticScreenProps, useNavigation } from '@react-navigation/native'
2
+ import React from 'react'
3
+ import { Linking } from 'react-native'
4
+ import { DenormalizedAttachmentResource } from '../../types/resources/denormalized_attachment_resource'
5
+ import ActionsFormSheet, {
6
+ BaseActionsFormSheetOptions,
7
+ } from '../../components/primitive/actions_form_sheet'
8
+
9
+ export const AttachmentActionsScreenOptions = BaseActionsFormSheetOptions
10
+
11
+ export type AttachmentActionsScreenProps = StaticScreenProps<{
12
+ attachment: DenormalizedAttachmentResource
13
+ }>
14
+
15
+ export function AttachmentActionsScreen({ route }: AttachmentActionsScreenProps) {
16
+ const navigation = useNavigation()
17
+ const { attachment } = route.params
18
+
19
+ const attachmentName = getAttachmentLabelName(attachment)
20
+
21
+ const handleSaveAttachment = () => {
22
+ if (attachment.type === 'giphy') {
23
+ Linking.openURL(attachment.titleLink)
24
+ } else {
25
+ Linking.openURL(attachment.attributes.url)
26
+ }
27
+
28
+ navigation.goBack()
29
+ }
30
+
31
+ return (
32
+ <ActionsFormSheet.Root>
33
+ <ActionsFormSheet.Action
34
+ iconName="general.newWindow"
35
+ title="Open in browser"
36
+ accessibilityRole="link"
37
+ accessibilityLabel={`Open ${attachmentName} in browser`}
38
+ accessibilityHint={`${attachmentName} can be downloaded and shared through the browser.`}
39
+ onPress={handleSaveAttachment}
40
+ />
41
+ </ActionsFormSheet.Root>
42
+ )
43
+ }
44
+
45
+ function getAttachmentLabelName(attachment: DenormalizedAttachmentResource) {
46
+ if (attachment.type === 'giphy') return 'giphy'
47
+ if (attachment.type === 'ExpandedLink') return 'link'
48
+
49
+ const { contentType } = attachment.attributes
50
+ if (contentType.startsWith('image/')) return 'image'
51
+ if (contentType.startsWith('video/')) return 'video'
52
+ if (contentType.startsWith('audio/')) return 'audio'
53
+ if (contentType.startsWith('application/')) return 'file'
54
+
55
+ return ''
56
+ }
@@ -23,7 +23,7 @@ export type ApiCollection<Type = ResourceObject> = {
23
23
  meta: CollectionMeta
24
24
  }
25
25
 
26
- export interface ApiError {
26
+ export interface ApiError extends Response {
27
27
  errors: ErrorObject[]
28
28
  }
29
29
 
@@ -8,3 +8,4 @@ export * from './cache'
8
8
  export * from './native_adapters'
9
9
  export * from './pluralize'
10
10
  export * from './destructure_chat_group_graph_id'
11
+ export * from './navigation_constants'
@@ -1,3 +1,4 @@
1
+ import { LogAdapter } from './log'
1
2
  import { AudioAdapter } from './audio'
2
3
  import { ClipboardAdapter } from './clipboard'
3
4
  import { ImagePickerAdapter } from './image_picker'
@@ -8,6 +9,7 @@ type ChatConfigurations = {
8
9
  audio: AudioAdapter
9
10
  video: VideoAdapter
10
11
  imagePicker: ImagePickerAdapter
12
+ log?: LogAdapter
11
13
  }
12
14
 
13
15
  export class ChatAdapters {
@@ -16,6 +18,7 @@ export class ChatAdapters {
16
18
  Audio = configurations.audio
17
19
  Video = configurations.video
18
20
  ImagePicker = configurations.imagePicker
21
+ Log = configurations.log || new LogAdapter()
19
22
  }
20
23
  }
21
24
 
@@ -23,7 +26,7 @@ const methodMissing = () => {
23
26
  console.warn('ChatAdapters.configure() must be called before using any adapters')
24
27
  }
25
28
 
26
- let Clipboard: ClipboardAdapter = new ClipboardAdapter({
29
+ export let Clipboard: ClipboardAdapter = new ClipboardAdapter({
27
30
  getStringAsync: async () => {
28
31
  methodMissing()
29
32
  return ''
@@ -31,14 +34,14 @@ let Clipboard: ClipboardAdapter = new ClipboardAdapter({
31
34
  setStringAsync: async (_: string) => methodMissing(),
32
35
  })
33
36
 
34
- let Audio: AudioAdapter = new AudioAdapter({
37
+ export let Audio: AudioAdapter = new AudioAdapter({
35
38
  useAudio: (_: string) => {
36
39
  methodMissing()
37
40
  return {} as any
38
41
  },
39
42
  })
40
43
 
41
- let Video: VideoAdapter = new VideoAdapter({
44
+ export let Video: VideoAdapter = new VideoAdapter({
42
45
  Player: Object.assign(
43
46
  () => {
44
47
  methodMissing()
@@ -48,7 +51,7 @@ let Video: VideoAdapter = new VideoAdapter({
48
51
  ),
49
52
  })
50
53
 
51
- let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
54
+ export let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
52
55
  openCameraAsync: async () => {
53
56
  methodMissing()
54
57
  return { canceled: true, assets: null }
@@ -59,4 +62,4 @@ let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
59
62
  },
60
63
  })
61
64
 
62
- export { Clipboard, Audio, Video, ImagePicker }
65
+ export let Log: LogAdapter = new LogAdapter()
@@ -3,3 +3,4 @@ export * from './configuration'
3
3
  export * from './audio'
4
4
  export * from './image_picker'
5
5
  export * from './video'
6
+ export * from './log'
@@ -0,0 +1,29 @@
1
+ interface LogAdapterConfig {
2
+ enabled: boolean
3
+ error: (message: string, ...args: any[]) => void
4
+ info: (message: string, ...args: any[]) => void
5
+ }
6
+
7
+ export class LogAdapter {
8
+ enabled: boolean
9
+ onError?: LogAdapterConfig['error']
10
+ onInfo?: LogAdapterConfig['info']
11
+
12
+ constructor(config: Partial<LogAdapterConfig> = {}) {
13
+ this.enabled = config.enabled ?? false
14
+ this.onError = config.error
15
+ this.onInfo = config.info
16
+ }
17
+
18
+ error(message: string, ...args: any[]) {
19
+ if (!this.enabled) return
20
+
21
+ this.onError?.(message, ...args)
22
+ }
23
+
24
+ info(message: string, ...args: any[]) {
25
+ if (!this.enabled) return
26
+
27
+ this.onInfo?.(message, ...args)
28
+ }
29
+ }
@@ -0,0 +1,12 @@
1
+ import { Platform } from 'react-native'
2
+
3
+ /*
4
+ * Android doesn't support "fitToContents" yet, so we need to manually set the detents.
5
+ * This tries to mimic iOS by setting a small detent of 25%, but allowing the user to "grow" the sheet to a full screen detent of 100% as an escape hatch if there is a lot of content.
6
+ */
7
+
8
+ export const PLATFORM_SHEET_ALLOWED_DETENTS_FIT_TO_CONTENTS = Platform.select({
9
+ ios: 'fitToContents',
10
+ // @ts-expect-error TS was seeing this as "fitToContents", even though it is valid to pass number[] to NativeStackNavigationOptions['sheetAllowedDetents']
11
+ android: [0.25, 1],
12
+ } as const)
@@ -0,0 +1,17 @@
1
+ import { ApiError } from '../types/api_primitives'
2
+
3
+ export class ResponseError extends Error {
4
+ status: number
5
+ statusText: string
6
+ errors: ApiError['errors']
7
+ response: ApiError
8
+
9
+ constructor(response: ApiError) {
10
+ super(`ResponseError: ${response?.status} ${response?.statusText}`)
11
+ this.name = 'ResponseError'
12
+ this.status = response?.status
13
+ this.statusText = response?.statusText
14
+ this.errors = response?.errors || []
15
+ this.response = response
16
+ }
17
+ }