@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.
- package/build/components/conversation/attachments/audio_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/audio_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/audio_attachment.js +14 -11
- package/build/components/conversation/attachments/audio_attachment.js.map +1 -1
- package/build/components/conversation/attachments/expanded_link.d.ts +4 -2
- package/build/components/conversation/attachments/expanded_link.d.ts.map +1 -1
- package/build/components/conversation/attachments/expanded_link.js +5 -4
- package/build/components/conversation/attachments/expanded_link.js.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.js +5 -4
- package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.js +2 -2
- package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
- package/build/components/conversation/attachments/image_attachment.d.ts +4 -2
- package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +5 -4
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/attachments/video_attachment.d.ts +2 -1
- package/build/components/conversation/attachments/video_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/video_attachment.js +5 -4
- package/build/components/conversation/attachments/video_attachment.js.map +1 -1
- package/build/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +6 -1
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/conversation/message_attachments.d.ts +1 -0
- package/build/components/conversation/message_attachments.d.ts.map +1 -1
- package/build/components/conversation/message_attachments.js +9 -9
- package/build/components/conversation/message_attachments.js.map +1 -1
- package/build/components/page/error_boundary.d.ts.map +1 -1
- package/build/components/page/error_boundary.js +4 -3
- package/build/components/page/error_boundary.js.map +1 -1
- package/build/components/primitive/actions_form_sheet.d.ts +34 -0
- package/build/components/primitive/actions_form_sheet.d.ts.map +1 -0
- package/build/components/primitive/actions_form_sheet.js +91 -0
- package/build/components/primitive/actions_form_sheet.js.map +1 -0
- package/build/contexts/chat_context.d.ts +7 -6
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +2 -2
- package/build/contexts/chat_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts +4 -4
- package/build/hooks/use_suspense_api.d.ts +6 -5
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +16 -3
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/index.d.ts +6 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -4
- package/build/index.js.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +6 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts +9 -0
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -0
- package/build/screens/attachment_actions/attachment_actions_screen.js +39 -0
- package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -0
- package/build/types/api_primitives.d.ts +1 -1
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/native_adapters/configuration.d.ts +8 -5
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +7 -5
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/log.d.ts +15 -0
- package/build/utils/native_adapters/log.d.ts.map +1 -0
- package/build/utils/native_adapters/log.js +21 -0
- package/build/utils/native_adapters/log.js.map +1 -0
- package/build/utils/navigation_constants.d.ts +2 -0
- package/build/utils/navigation_constants.d.ts.map +1 -0
- package/build/utils/navigation_constants.js +11 -0
- package/build/utils/navigation_constants.js.map +1 -0
- package/build/utils/response_error.d.ts +9 -0
- package/build/utils/response_error.d.ts.map +1 -0
- package/build/utils/response_error.js +15 -0
- package/build/utils/response_error.js.map +1 -0
- package/package.json +2 -2
- package/src/components/conversation/attachments/audio_attachment.tsx +25 -17
- package/src/components/conversation/attachments/expanded_link.tsx +17 -4
- package/src/components/conversation/attachments/generic_file_attachment.tsx +9 -3
- package/src/components/conversation/attachments/giphy_attachment.tsx +8 -1
- package/src/components/conversation/attachments/image_attachment.tsx +12 -4
- package/src/components/conversation/attachments/video_attachment.tsx +9 -3
- package/src/components/conversation/message.tsx +12 -1
- package/src/components/conversation/message_attachments.tsx +43 -8
- package/src/components/page/error_boundary.tsx +4 -3
- package/src/components/primitive/actions_form_sheet.tsx +159 -0
- package/src/contexts/chat_context.tsx +12 -8
- package/src/hooks/use_suspense_api.ts +23 -7
- package/src/index.tsx +6 -12
- package/src/navigation/index.tsx +6 -0
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +56 -0
- package/src/types/api_primitives.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/native_adapters/configuration.ts +8 -5
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/log.ts +29 -0
- package/src/utils/navigation_constants.ts +12 -0
- 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
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -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
|
|
65
|
+
export let Log: LogAdapter = new LogAdapter()
|
|
@@ -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
|
+
}
|