@planningcenter/chat-react-native 4.5.1-rc.0 → 4.6.0-qa-1063.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/assets/powered_by_giphy.png +0 -0
- package/assets/powered_by_giphy_dark.png +0 -0
- 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.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +5 -3
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +2 -2
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +155 -123
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +1 -0
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/conversation_avatar.d.ts +3 -1
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js +77 -66
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/components/display/keyboard_scroll_view.d.ts.map +1 -1
- package/build/components/display/keyboard_scroll_view.js +1 -0
- package/build/components/display/keyboard_scroll_view.js.map +1 -1
- package/build/components/page/page_error_boundary.d.ts +9 -1
- package/build/components/page/page_error_boundary.d.ts.map +1 -1
- package/build/components/page/page_error_boundary.js +56 -31
- package/build/components/page/page_error_boundary.js.map +1 -1
- package/build/hooks/use_conversation_avatar_update.d.ts +4 -3
- package/build/hooks/use_conversation_avatar_update.d.ts.map +1 -1
- package/build/hooks/use_conversation_avatar_update.js +146 -48
- package/build/hooks/use_conversation_avatar_update.js.map +1 -1
- package/build/icons/font_awesome.js +6 -6
- package/build/icons/font_awesome.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +3 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/page_error_fallbacks.d.ts +7 -0
- package/build/navigation/page_error_fallbacks.d.ts.map +1 -0
- package/build/navigation/page_error_fallbacks.js +7 -0
- package/build/navigation/page_error_fallbacks.js.map +1 -0
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +10 -6
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/screens/age_check/age_check_required_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_required_screen.js +1 -0
- package/build/screens/age_check/age_check_required_screen.js.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +2 -1
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.js +5 -2
- package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.d.ts.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.js +76 -66
- package/build/screens/avatar_picker/avatar_picker_screen.js.map +1 -1
- package/build/screens/avatar_picker/constants.d.ts.map +1 -1
- package/build/screens/avatar_picker/constants.js +5 -3
- package/build/screens/avatar_picker/constants.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +3 -3
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +1 -0
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_new/components/form_list.d.ts.map +1 -1
- package/build/screens/conversation_new/components/form_list.js +1 -0
- package/build/screens/conversation_new/components/form_list.js.map +1 -1
- package/build/screens/conversation_new/components/groups_form.js +25 -18
- package/build/screens/conversation_new/components/groups_form.js.map +1 -1
- package/build/screens/conversation_new/components/services_form.js +51 -40
- package/build/screens/conversation_new/components/services_form.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js +332 -291
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js +2 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js.map +1 -1
- package/build/screens/design_system_screen.js +6 -3
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/screens/get_help_screen.js +57 -63
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/group_notification_settings_screen.js +3 -2
- package/build/screens/group_notification_settings_screen.js.map +1 -1
- package/build/screens/notification_settings_screen.d.ts.map +1 -1
- package/build/screens/notification_settings_screen.js +1 -0
- package/build/screens/notification_settings_screen.js.map +1 -1
- package/build/screens/preferred_app_selection_screen.js +45 -39
- package/build/screens/preferred_app_selection_screen.js.map +1 -1
- package/build/screens/search/components/search_results_list.d.ts +4 -1
- package/build/screens/search/components/search_results_list.d.ts.map +1 -1
- package/build/screens/search/components/search_results_list.js +136 -110
- package/build/screens/search/components/search_results_list.js.map +1 -1
- package/build/screens/search/search_screen.d.ts.map +1 -1
- package/build/screens/search/search_screen.js +21 -28
- package/build/screens/search/search_screen.js.map +1 -1
- package/build/screens/send_giphy_screen.d.ts.map +1 -1
- package/build/screens/send_giphy_screen.js +93 -136
- package/build/screens/send_giphy_screen.js.map +1 -1
- package/build/screens/settings_screen.d.ts.map +1 -1
- package/build/screens/settings_screen.js +7 -6
- package/build/screens/settings_screen.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/membership_sync_info_text.d.ts +2 -0
- package/build/utils/membership_sync_info_text.d.ts.map +1 -0
- package/build/utils/membership_sync_info_text.js +4 -0
- package/build/utils/membership_sync_info_text.js.map +1 -0
- package/build/utils/native_adapters/linking.d.ts +11 -3
- package/build/utils/native_adapters/linking.d.ts.map +1 -1
- package/build/utils/native_adapters/linking.js.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.d.ts +6 -6
- package/build/vendor/font_awesome_pro_solid_icons.d.ts.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.js +6 -6
- package/build/vendor/font_awesome_pro_solid_icons.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/screens/get_help_screen.test.ts +36 -0
- package/src/__utils__/render_with_query_client.tsx +13 -0
- package/src/components/conversation/__tests__/message_list.test.tsx +4 -0
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- package/src/components/conversation/attachments/image_attachment.tsx +2 -3
- package/src/components/conversation/message_form.tsx +1 -1
- package/src/components/conversation/message_list.tsx +6 -0
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +2 -2
- package/src/components/conversations/conversations.tsx +1 -0
- package/src/components/display/__tests__/conversation_avatar.test.tsx +94 -0
- package/src/components/display/conversation_avatar.tsx +9 -2
- package/src/components/display/keyboard_scroll_view.tsx +1 -0
- package/src/components/page/__tests__/page_error_boundary.test.tsx +33 -0
- package/src/components/page/page_error_boundary.tsx +43 -12
- package/src/hooks/__tests__/use_conversation_avatar_update.test.tsx +40 -0
- package/src/hooks/use_conversation_avatar_update.ts +67 -11
- package/src/icons/font_awesome.ts +12 -12
- package/src/navigation/index.tsx +6 -2
- package/src/navigation/page_error_fallbacks.ts +14 -0
- package/src/navigation/screenLayout.tsx +3 -1
- package/src/screens/age_check/age_check_required_screen.tsx +5 -1
- package/src/screens/age_check/age_check_underage_screen.tsx +2 -1
- package/src/screens/attachment_actions/__tests__/attachment_actions_screen.test.tsx +37 -1
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +3 -2
- package/src/screens/avatar_picker/__tests__/avatar_picker_screen.test.tsx +67 -0
- package/src/screens/avatar_picker/__tests__/constants.test.ts +16 -0
- package/src/screens/avatar_picker/avatar_picker_screen.tsx +7 -1
- package/src/screens/avatar_picker/constants.ts +11 -6
- package/src/screens/bug_report_screen.tsx +3 -11
- package/src/screens/conversation_details_screen.tsx +1 -0
- package/src/screens/conversation_new/components/form_list.tsx +1 -0
- package/src/screens/conversation_new/components/groups_form.tsx +2 -2
- package/src/screens/conversation_new/components/services_form.tsx +2 -2
- package/src/screens/conversation_select_recipients/__tests__/conversation_select_direct_message_recipients_screen.test.tsx +100 -0
- package/src/screens/conversation_select_recipients/conversation_new_entry_screen.tsx +4 -1
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +78 -68
- package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx +2 -1
- package/src/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.tsx +1 -0
- package/src/screens/design_system_screen.tsx +10 -6
- package/src/screens/get_help_screen.tsx +5 -5
- package/src/screens/group_notification_settings_screen.tsx +3 -3
- package/src/screens/notification_settings_screen.tsx +1 -0
- package/src/screens/preferred_app_selection_screen.tsx +4 -4
- package/src/screens/search/__tests__/search_screen.test.tsx +11 -12
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +14 -5
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +5 -4
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +10 -5
- package/src/screens/search/components/search_results_list.tsx +34 -13
- package/src/screens/search/search_screen.tsx +8 -18
- package/src/screens/send_giphy_screen.tsx +13 -44
- package/src/screens/settings_screen.tsx +25 -25
- package/src/utils/__tests__/membership_sync_info_text.test.ts +15 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/membership_sync_info_text.ts +3 -0
- package/src/utils/native_adapters/__tests__/linking.test.ts +12 -0
- package/src/utils/native_adapters/linking.ts +12 -3
- package/src/vendor/font_awesome_pro_solid_icons.ts +6 -6
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { ViewStyle } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
applyAvatarUpdate,
|
|
5
|
+
usePendingConversationAvatarUpdate,
|
|
6
|
+
} from '../../hooks/use_conversation_avatar_update'
|
|
3
7
|
import type { ConversationAvatarData } from '../../types'
|
|
4
8
|
import AvatarPrimitive, { type AvatarRootProps } from '../primitive/avatar_primitive'
|
|
5
9
|
import { AvatarGroup } from './avatar_group'
|
|
@@ -38,7 +42,7 @@ function resolveAvatar(conversation: ConversationAvatarData): ResolvedAvatar {
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
interface ConversationAvatarProps {
|
|
41
|
-
conversation: ConversationAvatarData
|
|
45
|
+
conversation: ConversationAvatarData & { id?: number }
|
|
42
46
|
size?: AvatarRootProps['size']
|
|
43
47
|
showFallback?: boolean
|
|
44
48
|
fallbackIconName?: IconString
|
|
@@ -54,7 +58,10 @@ export function ConversationAvatar({
|
|
|
54
58
|
style,
|
|
55
59
|
maxFontSizeMultiplier,
|
|
56
60
|
}: ConversationAvatarProps) {
|
|
57
|
-
const
|
|
61
|
+
const pendingUpdate = usePendingConversationAvatarUpdate(conversation.id)
|
|
62
|
+
const avatar = resolveAvatar(
|
|
63
|
+
pendingUpdate ? applyAvatarUpdate(conversation, pendingUpdate) : conversation
|
|
64
|
+
)
|
|
58
65
|
const sizeProps = { size, maxFontSizeMultiplier, style }
|
|
59
66
|
|
|
60
67
|
switch (avatar.kind) {
|
|
@@ -43,6 +43,7 @@ export function KeyboardScrollView({ children, contentContainerStyle }: Keyboard
|
|
|
43
43
|
<KeyboardView>
|
|
44
44
|
<ScrollView
|
|
45
45
|
ref={scrollViewRef}
|
|
46
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
46
47
|
contentContainerStyle={contentContainerStyle}
|
|
47
48
|
onLayout={scrollFocusedInputIntoView}
|
|
48
49
|
onContentSizeChange={scrollFocusedInputIntoView}
|
|
@@ -4,6 +4,7 @@ import { render } from '@testing-library/react-native'
|
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
6
6
|
import { Log } from '../../../utils/native_adapters/configuration'
|
|
7
|
+
import { ResponseError } from '../../../utils/response_error'
|
|
7
8
|
import { PageErrorBoundary } from '../page_error_boundary'
|
|
8
9
|
|
|
9
10
|
jest.mock('../../primitive/blank_state_primitive', () => {
|
|
@@ -74,4 +75,36 @@ describe('PageErrorBoundary', () => {
|
|
|
74
75
|
expect(getByText('Oops!')).toBeTruthy()
|
|
75
76
|
expect(getByText('Something unexpected happened.')).toBeTruthy()
|
|
76
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('with a generic fallback override', () => {
|
|
80
|
+
const genericFallback = { heading: 'Nothing here', body: 'Come back later.' }
|
|
81
|
+
const responseError = (status: number) =>
|
|
82
|
+
new ResponseError({ status, statusText: 'x', errors: [] } as never)
|
|
83
|
+
|
|
84
|
+
it.each([
|
|
85
|
+
['a plain error', new Error('boom')],
|
|
86
|
+
['an unhandled status', responseError(500)],
|
|
87
|
+
])('replaces the Oops copy for %s', (_label, thrown) => {
|
|
88
|
+
const { getByText, queryByText } = renderWithProviders(
|
|
89
|
+
<PageErrorBoundary genericFallback={genericFallback}>
|
|
90
|
+
<Boom thrown={thrown} />
|
|
91
|
+
</PageErrorBoundary>
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(getByText('Nothing here')).toBeTruthy()
|
|
95
|
+
expect(getByText('Come back later.')).toBeTruthy()
|
|
96
|
+
expect(queryByText('Oops!')).toBeNull()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('leaves a known status alone', () => {
|
|
100
|
+
const { getByText, queryByText } = renderWithProviders(
|
|
101
|
+
<PageErrorBoundary genericFallback={genericFallback}>
|
|
102
|
+
<Boom thrown={responseError(403)} />
|
|
103
|
+
</PageErrorBoundary>
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
expect(getByText('Permission required')).toBeTruthy()
|
|
107
|
+
expect(queryByText('Nothing here')).toBeNull()
|
|
108
|
+
})
|
|
109
|
+
})
|
|
77
110
|
})
|
|
@@ -6,11 +6,26 @@ import { ResponseError } from '../../utils/response_error'
|
|
|
6
6
|
import BlankState from '../primitive/blank_state_primitive'
|
|
7
7
|
import { ErrorBoundary, ErrorBoundaryFallback, ErrorBoundaryProps } from './error_boundary'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export type PageErrorFallback = { heading: string; body: string }
|
|
10
|
+
|
|
11
|
+
const GENERIC_FALLBACK: PageErrorFallback = {
|
|
12
|
+
heading: 'Oops!',
|
|
13
|
+
body: 'Something unexpected happened.',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type PageErrorBoundaryProps = PropsWithChildren<
|
|
17
|
+
ErrorBoundaryProps & { genericFallback?: PageErrorFallback }
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
export function PageErrorBoundary({
|
|
21
|
+
children,
|
|
22
|
+
genericFallback = GENERIC_FALLBACK,
|
|
23
|
+
...props
|
|
24
|
+
}: PageErrorBoundaryProps) {
|
|
25
|
+
const renderPageFallback: ErrorBoundaryFallback = (error, reset) => (
|
|
26
|
+
<ErrorView error={error} reset={reset} generic={genericFallback} />
|
|
27
|
+
)
|
|
12
28
|
|
|
13
|
-
export function PageErrorBoundary({ children, ...props }: PropsWithChildren<ErrorBoundaryProps>) {
|
|
14
29
|
return (
|
|
15
30
|
<ErrorBoundary scope="screen" fallback={renderPageFallback} {...props}>
|
|
16
31
|
{children}
|
|
@@ -18,7 +33,15 @@ export function PageErrorBoundary({ children, ...props }: PropsWithChildren<Erro
|
|
|
18
33
|
)
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
function ErrorView({
|
|
36
|
+
function ErrorView({
|
|
37
|
+
error,
|
|
38
|
+
reset,
|
|
39
|
+
generic,
|
|
40
|
+
}: {
|
|
41
|
+
error: Error
|
|
42
|
+
reset: () => void
|
|
43
|
+
generic: PageErrorFallback
|
|
44
|
+
}) {
|
|
22
45
|
const { reset: resetQueries } = useQueryErrorResetBoundary()
|
|
23
46
|
|
|
24
47
|
const handleReset = useCallback(() => {
|
|
@@ -29,7 +52,7 @@ function ErrorView({ error, reset }: { error: Error; reset: () => void }) {
|
|
|
29
52
|
useEffect(() => handleReset, [handleReset])
|
|
30
53
|
|
|
31
54
|
if (error instanceof ResponseError) {
|
|
32
|
-
return <ResponseErrorView response={error.response} onReset={handleReset} />
|
|
55
|
+
return <ResponseErrorView response={error.response} onReset={handleReset} generic={generic} />
|
|
33
56
|
}
|
|
34
57
|
|
|
35
58
|
if (isNetworkError(error)) {
|
|
@@ -41,7 +64,7 @@ function ErrorView({ error, reset }: { error: Error; reset: () => void }) {
|
|
|
41
64
|
)
|
|
42
65
|
}
|
|
43
66
|
|
|
44
|
-
return <ErrorContent heading={
|
|
67
|
+
return <ErrorContent heading={generic.heading} body={generic.body} />
|
|
45
68
|
}
|
|
46
69
|
|
|
47
70
|
function isNetworkError(error: Error) {
|
|
@@ -54,7 +77,15 @@ function isNetworkError(error: Error) {
|
|
|
54
77
|
return new RegExp(networkFailedMessages.join('|'), 'i').test(error.message)
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
function ResponseErrorView({
|
|
80
|
+
function ResponseErrorView({
|
|
81
|
+
response,
|
|
82
|
+
onReset,
|
|
83
|
+
generic,
|
|
84
|
+
}: {
|
|
85
|
+
response: Response
|
|
86
|
+
onReset: () => void
|
|
87
|
+
generic: PageErrorFallback
|
|
88
|
+
}) {
|
|
58
89
|
const { status } = response
|
|
59
90
|
|
|
60
91
|
const heading = useMemo(() => {
|
|
@@ -64,9 +95,9 @@ function ResponseErrorView({ response, onReset }: { response: Response; onReset:
|
|
|
64
95
|
case 404:
|
|
65
96
|
return 'Content not found'
|
|
66
97
|
default:
|
|
67
|
-
return
|
|
98
|
+
return generic.heading
|
|
68
99
|
}
|
|
69
|
-
}, [status])
|
|
100
|
+
}, [status, generic.heading])
|
|
70
101
|
|
|
71
102
|
const body = useMemo(() => {
|
|
72
103
|
switch (status) {
|
|
@@ -75,9 +106,9 @@ function ResponseErrorView({ response, onReset }: { response: Response; onReset:
|
|
|
75
106
|
case 404:
|
|
76
107
|
return 'If you believe something should be here, please reach out to your administrator.'
|
|
77
108
|
default:
|
|
78
|
-
return
|
|
109
|
+
return generic.body
|
|
79
110
|
}
|
|
80
|
-
}, [status])
|
|
111
|
+
}, [status, generic.body])
|
|
81
112
|
|
|
82
113
|
useEffect(() => {
|
|
83
114
|
if (status !== 401) return
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
+
import { useConversationAvatarUpdate } from '../use_conversation_avatar_update'
|
|
6
|
+
|
|
7
|
+
const mockPatch = jest.fn().mockResolvedValue({ data: { id: 7 } })
|
|
8
|
+
let finishUpload = () => {}
|
|
9
|
+
jest.mock('../use_api_client', () => ({ useApiClient: () => ({ chat: { patch: mockPatch } }) }))
|
|
10
|
+
jest.mock('../use_upload_client', () => ({
|
|
11
|
+
useUploadClient: () => ({
|
|
12
|
+
uploadFile: () => new Promise(resolve => (finishUpload = () => resolve({ id: 'upload-1' }))),
|
|
13
|
+
}),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('useConversationAvatarUpdate', () => {
|
|
17
|
+
it('saves only the newest pick when an icon is chosen during a photo upload', async () => {
|
|
18
|
+
const queryClient = buildTestQueryClient({
|
|
19
|
+
defaultOptions: { mutations: { gcTime: Infinity } },
|
|
20
|
+
})
|
|
21
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
22
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
23
|
+
)
|
|
24
|
+
const { result } = renderHook(() => useConversationAvatarUpdate({ conversationId: 7 }), {
|
|
25
|
+
wrapper,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const photoSave = result.current.mutateAsync({
|
|
29
|
+
kind: 'image',
|
|
30
|
+
color: 'cosmic',
|
|
31
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
32
|
+
})
|
|
33
|
+
await act(() => result.current.mutateAsync({ kind: 'icon', key: 'star', color: 'cosmic' }))
|
|
34
|
+
finishUpload()
|
|
35
|
+
await act(() => photoSave)
|
|
36
|
+
|
|
37
|
+
expect(mockPatch).toHaveBeenCalledTimes(1)
|
|
38
|
+
expect(mockPatch.mock.calls[0][0].data.data.attributes.custom_avatar_type).toBe('icon')
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { Alert } from 'react-native'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import { InfiniteData, useMutation, useMutationState, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert, Image } from 'react-native'
|
|
3
|
+
import type {
|
|
4
|
+
ApiCollection,
|
|
5
|
+
ApiResource,
|
|
6
|
+
ConversationAvatarData,
|
|
7
|
+
ConversationResource,
|
|
8
|
+
} from '../types'
|
|
9
|
+
import { updateAllRecordsInPagesData } from '../utils/cache/page_mutations'
|
|
5
10
|
import { transformGetToPost } from '../utils/client/request_helpers'
|
|
6
11
|
import type { ImagePickerAsset } from '../utils/native_adapters/image_picker'
|
|
7
12
|
import { ApiClient, useApiClient } from './use_api_client'
|
|
@@ -16,6 +21,18 @@ export type AvatarUpdatePayload =
|
|
|
16
21
|
| { kind: Extract<AvatarType, 'image'>; imageAsset: ImagePickerAsset; color: string }
|
|
17
22
|
| { kind: 'clear' }
|
|
18
23
|
|
|
24
|
+
const MUTATION_KEY = 'updateConversationAvatar'
|
|
25
|
+
|
|
26
|
+
export const usePendingConversationAvatarUpdate = (conversationId: number | undefined) => {
|
|
27
|
+
const newest = useMutationState({
|
|
28
|
+
filters: { mutationKey: [MUTATION_KEY, conversationId], exact: true },
|
|
29
|
+
select: mutation => mutation.state,
|
|
30
|
+
}).at(-1)
|
|
31
|
+
|
|
32
|
+
if (conversationId === undefined || newest?.status !== 'pending') return undefined
|
|
33
|
+
return newest.variables as AvatarUpdatePayload
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
export const useConversationAvatarUpdate = ({ conversationId }: { conversationId: number }) => {
|
|
20
37
|
const apiClient = useApiClient()
|
|
21
38
|
const uploadClient = useUploadClient()
|
|
@@ -23,11 +40,18 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
23
40
|
const requestArgs = getConversationRequestArgs({ conversation_id: conversationId })
|
|
24
41
|
const queryKey = getRequestQueryKey(requestArgs)
|
|
25
42
|
|
|
43
|
+
const isSuperseded = (payload: AvatarUpdatePayload) =>
|
|
44
|
+
queryClient
|
|
45
|
+
.getMutationCache()
|
|
46
|
+
.findAll({ mutationKey: [MUTATION_KEY, conversationId], exact: true })
|
|
47
|
+
.at(-1)?.state.variables !== payload
|
|
48
|
+
|
|
26
49
|
return useMutation({
|
|
27
|
-
mutationKey: [
|
|
50
|
+
mutationKey: [MUTATION_KEY, conversationId],
|
|
28
51
|
mutationFn: async (payload: AvatarUpdatePayload) => {
|
|
29
52
|
const postArgs = transformGetToPost(requestArgs).data
|
|
30
53
|
const attributes = await buildAttributes(payload, uploadClient)
|
|
54
|
+
if (isSuperseded(payload)) return null
|
|
31
55
|
|
|
32
56
|
return apiClient.chat.patch<ApiResource<ConversationResource>>({
|
|
33
57
|
url: `/me/conversations/${conversationId}/`,
|
|
@@ -41,16 +65,35 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
41
65
|
|
|
42
66
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, prev => {
|
|
43
67
|
if (!prev?.data) return prev
|
|
44
|
-
return { ...prev, data:
|
|
68
|
+
return { ...prev, data: applyAvatarUpdate(prev.data, payload) }
|
|
45
69
|
})
|
|
46
70
|
|
|
47
71
|
return { previous }
|
|
48
72
|
},
|
|
49
|
-
onSuccess: (response, _payload, _context) => {
|
|
73
|
+
onSuccess: async (response, _payload, _context) => {
|
|
74
|
+
if (!response) return
|
|
75
|
+
|
|
50
76
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, () => response)
|
|
77
|
+
queryClient.setQueriesData<InfiniteData<ApiCollection<ConversationResource>>>(
|
|
78
|
+
{ queryKey: ['/me/conversations'] },
|
|
79
|
+
prev => {
|
|
80
|
+
if (!prev?.pages) return prev
|
|
81
|
+
|
|
82
|
+
return updateAllRecordsInPagesData({
|
|
83
|
+
data: prev,
|
|
84
|
+
processRecord: record =>
|
|
85
|
+
record.id === conversationId ? applySavedAvatar(record, response.data) : record,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
)
|
|
51
89
|
queryClient.invalidateQueries({ queryKey: ['/me/conversations'] })
|
|
90
|
+
|
|
91
|
+
const imageUrl = response.data.customAvatarImageUrl
|
|
92
|
+
if (imageUrl) await Image.prefetch(imageUrl).catch(() => false)
|
|
52
93
|
},
|
|
53
|
-
onError: (_error,
|
|
94
|
+
onError: (_error, payload, context) => {
|
|
95
|
+
if (isSuperseded(payload)) return
|
|
96
|
+
|
|
54
97
|
if (context?.previous) {
|
|
55
98
|
queryClient.setQueryData(queryKey, context.previous)
|
|
56
99
|
}
|
|
@@ -83,10 +126,23 @@ export async function patchConversationAvatar(
|
|
|
83
126
|
}
|
|
84
127
|
}
|
|
85
128
|
|
|
86
|
-
function
|
|
87
|
-
data:
|
|
129
|
+
function applySavedAvatar<T extends ConversationAvatarData>(
|
|
130
|
+
data: T,
|
|
131
|
+
saved: ConversationAvatarData
|
|
132
|
+
): T {
|
|
133
|
+
return {
|
|
134
|
+
...data,
|
|
135
|
+
customAvatarType: saved.customAvatarType,
|
|
136
|
+
customAvatarKey: saved.customAvatarKey,
|
|
137
|
+
customAvatarColor: saved.customAvatarColor,
|
|
138
|
+
customAvatarImageUrl: saved.customAvatarImageUrl,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function applyAvatarUpdate<T extends ConversationAvatarData>(
|
|
143
|
+
data: T,
|
|
88
144
|
payload: AvatarUpdatePayload
|
|
89
|
-
):
|
|
145
|
+
): T {
|
|
90
146
|
switch (payload.kind) {
|
|
91
147
|
case 'icon':
|
|
92
148
|
return {
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
faChurch,
|
|
6
6
|
faCross,
|
|
7
7
|
faDove,
|
|
8
|
-
|
|
8
|
+
faHandsHoldingHeart,
|
|
9
9
|
faPersonRays,
|
|
10
|
-
|
|
10
|
+
faHandsPraying,
|
|
11
11
|
faPodium,
|
|
12
12
|
faDroplet,
|
|
13
13
|
faPersonDrowning,
|
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
faBaby,
|
|
23
23
|
faChildren,
|
|
24
24
|
faMugHot,
|
|
25
|
-
|
|
25
|
+
faVideo,
|
|
26
26
|
faMusic,
|
|
27
27
|
faPianoKeyboard,
|
|
28
28
|
faDrum,
|
|
29
29
|
faUserGraduate,
|
|
30
30
|
faCommentsQuestion,
|
|
31
|
-
|
|
31
|
+
faPresentationScreen,
|
|
32
32
|
faMicrophoneStand,
|
|
33
33
|
faIdBadge,
|
|
34
34
|
faBookUser,
|
|
@@ -44,10 +44,10 @@ import {
|
|
|
44
44
|
faPersonDress,
|
|
45
45
|
faPerson,
|
|
46
46
|
faSeedling,
|
|
47
|
-
|
|
47
|
+
faMessages,
|
|
48
48
|
faGlobe,
|
|
49
49
|
faBookOpenReader,
|
|
50
|
-
|
|
50
|
+
faPersonRunning,
|
|
51
51
|
faLeaf,
|
|
52
52
|
// General
|
|
53
53
|
faPlateUtensils,
|
|
@@ -62,9 +62,9 @@ library.add(
|
|
|
62
62
|
faChurch,
|
|
63
63
|
faCross,
|
|
64
64
|
faDove,
|
|
65
|
-
|
|
65
|
+
faHandsHoldingHeart,
|
|
66
66
|
faPersonRays,
|
|
67
|
-
|
|
67
|
+
faHandsPraying,
|
|
68
68
|
faPodium,
|
|
69
69
|
faDroplet,
|
|
70
70
|
faPersonDrowning,
|
|
@@ -79,13 +79,13 @@ library.add(
|
|
|
79
79
|
faBaby,
|
|
80
80
|
faChildren,
|
|
81
81
|
faMugHot,
|
|
82
|
-
|
|
82
|
+
faVideo,
|
|
83
83
|
faMusic,
|
|
84
84
|
faPianoKeyboard,
|
|
85
85
|
faDrum,
|
|
86
86
|
faUserGraduate,
|
|
87
87
|
faCommentsQuestion,
|
|
88
|
-
|
|
88
|
+
faPresentationScreen,
|
|
89
89
|
faMicrophoneStand,
|
|
90
90
|
faIdBadge,
|
|
91
91
|
faBookUser,
|
|
@@ -101,10 +101,10 @@ library.add(
|
|
|
101
101
|
faPersonDress,
|
|
102
102
|
faPerson,
|
|
103
103
|
faSeedling,
|
|
104
|
-
|
|
104
|
+
faMessages,
|
|
105
105
|
faGlobe,
|
|
106
106
|
faBookOpenReader,
|
|
107
|
-
|
|
107
|
+
faPersonRunning,
|
|
108
108
|
faLeaf,
|
|
109
109
|
// General
|
|
110
110
|
faPlateUtensils,
|
package/src/navigation/index.tsx
CHANGED
|
@@ -85,7 +85,9 @@ import { ScreenLayoutWithChatAccessGate } from './screenLayout'
|
|
|
85
85
|
|
|
86
86
|
const globalScreenOptions: () => NativeStackNavigationOptions = () => ({
|
|
87
87
|
headerBackButtonDisplayMode: 'minimal',
|
|
88
|
-
...(isLiquidGlassEnabled()
|
|
88
|
+
...(isLiquidGlassEnabled()
|
|
89
|
+
? { headerShadowVisible: false, headerTransparent: true, headerBlurEffect: 'regular' }
|
|
90
|
+
: {}),
|
|
89
91
|
})
|
|
90
92
|
|
|
91
93
|
export const NewConversationStack = createNativeStackNavigator({
|
|
@@ -232,7 +234,9 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
232
234
|
screen: ConversationScreen,
|
|
233
235
|
options: ({ route, navigation }) =>
|
|
234
236
|
composeOptions(
|
|
235
|
-
{
|
|
237
|
+
{
|
|
238
|
+
title: (route.params as ConversationRouteProps)?.title ?? 'Reply',
|
|
239
|
+
},
|
|
236
240
|
withMinimalBack({ onPress: navigation.goBack })
|
|
237
241
|
),
|
|
238
242
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StaticParamList } from '@react-navigation/native'
|
|
2
|
+
import type { PageErrorFallback } from '../components/page/page_error_boundary'
|
|
3
|
+
import type { NewConversationStack } from './index'
|
|
4
|
+
|
|
5
|
+
type RouteName =
|
|
6
|
+
| keyof ReactNavigation.RootParamList
|
|
7
|
+
| keyof StaticParamList<typeof NewConversationStack>
|
|
8
|
+
|
|
9
|
+
export const PAGE_ERROR_FALLBACKS: Partial<Record<RouteName, PageErrorFallback>> = {
|
|
10
|
+
ConversationSelectDirectMessageRecipients: {
|
|
11
|
+
heading: "Couldn't load people right now",
|
|
12
|
+
body: 'Try again.',
|
|
13
|
+
},
|
|
14
|
+
}
|
|
@@ -6,14 +6,16 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
|
6
6
|
import { DefaultLoading } from '../components/page/loading'
|
|
7
7
|
import { PageErrorBoundary } from '../components/page/page_error_boundary'
|
|
8
8
|
import { ChatAccessGate } from './chat_access_gate'
|
|
9
|
+
import { PAGE_ERROR_FALLBACKS } from './page_error_fallbacks'
|
|
9
10
|
|
|
10
11
|
export function ScreenLayout({ children }: { children: React.ReactElement }) {
|
|
11
12
|
const route = useRoute()
|
|
12
13
|
const styles = useStyles()
|
|
13
14
|
const { fontScale } = useWindowDimensions()
|
|
15
|
+
const genericFallback = PAGE_ERROR_FALLBACKS[route.name as keyof typeof PAGE_ERROR_FALLBACKS]
|
|
14
16
|
|
|
15
17
|
return (
|
|
16
|
-
<PageErrorBoundary screenName={route.name}>
|
|
18
|
+
<PageErrorBoundary screenName={route.name} genericFallback={genericFallback}>
|
|
17
19
|
<View key={fontScale} style={styles.screen}>
|
|
18
20
|
<Suspense fallback={<DefaultLoading />}>{children}</Suspense>
|
|
19
21
|
</View>
|
|
@@ -58,7 +58,11 @@ export function AgeCheckRequiredScreen() {
|
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<>
|
|
61
|
-
<ScrollView
|
|
61
|
+
<ScrollView
|
|
62
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
63
|
+
style={styles.scrollView}
|
|
64
|
+
contentContainerStyle={styles.container}
|
|
65
|
+
>
|
|
62
66
|
<View style={styles.header}>
|
|
63
67
|
<View style={styles.heading}>
|
|
64
68
|
<Icon name="general.exclamationTriangle" size={20} style={styles.warningIcon} />
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useRoute, RouteProp } from '@react-navigation/native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View, ScrollView } from 'react-native'
|
|
4
4
|
import { Heading } from '../../components'
|
|
5
5
|
import { Icon, Text, TextInlineButton } from '../../components/display'
|
|
6
6
|
import { useTheme } from '../../hooks'
|
|
7
|
+
import { Linking } from '../../utils'
|
|
7
8
|
import type { AgeCheckParams } from './screen_props'
|
|
8
9
|
|
|
9
10
|
export interface AgeCheckUnderageScreenProps {
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { HeaderHeightContext } from '@react-navigation/elements'
|
|
2
2
|
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
3
|
-
import { render } from '@testing-library/react-native'
|
|
3
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
6
6
|
import type { ConversationResource } from '../../../types'
|
|
7
|
+
import {
|
|
8
|
+
AudioAdapter,
|
|
9
|
+
ChatAdapters,
|
|
10
|
+
ClipboardAdapter,
|
|
11
|
+
ImagePickerAdapter,
|
|
12
|
+
LinkingAdapter,
|
|
13
|
+
VideoAdapter,
|
|
14
|
+
} from '../../../utils/native_adapters'
|
|
7
15
|
import { AttachmentActionsScreen, AttachmentActionsScreenProps } from '../attachment_actions_screen'
|
|
8
16
|
|
|
9
17
|
let mockConversation = { id: 1, disabled: false } as ConversationResource
|
|
@@ -19,6 +27,8 @@ jest.mock('../hooks/useDeleteAttachment', () => ({
|
|
|
19
27
|
useDeleteAttachment: () => ({ handleDeleteAttachment: jest.fn() }),
|
|
20
28
|
}))
|
|
21
29
|
|
|
30
|
+
const hostOpenURL = jest.fn(async (_url: string, _options?: object) => {})
|
|
31
|
+
|
|
22
32
|
const safeAreaMetrics = {
|
|
23
33
|
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
24
34
|
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
@@ -51,6 +61,22 @@ const renderScreen = (params: Partial<AttachmentActionsScreenProps['route']['par
|
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
describe('AttachmentActionsScreen', () => {
|
|
64
|
+
beforeAll(() => {
|
|
65
|
+
ChatAdapters.configure({
|
|
66
|
+
clipboard: new ClipboardAdapter({
|
|
67
|
+
getStringAsync: async () => '',
|
|
68
|
+
setStringAsync: async () => {},
|
|
69
|
+
}),
|
|
70
|
+
audio: new AudioAdapter({ useAudio: () => ({}) as any }),
|
|
71
|
+
video: new VideoAdapter({ Player: React.forwardRef(() => null) }),
|
|
72
|
+
imagePicker: new ImagePickerAdapter({
|
|
73
|
+
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
74
|
+
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
75
|
+
}),
|
|
76
|
+
linking: new LinkingAdapter({ openURL: hostOpenURL, canOpenURL: async () => true }),
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
54
80
|
beforeEach(() => {
|
|
55
81
|
mockConversation = { id: 1, disabled: false } as ConversationResource
|
|
56
82
|
})
|
|
@@ -69,4 +95,14 @@ describe('AttachmentActionsScreen', () => {
|
|
|
69
95
|
expect(queryByText('Delete image')).toBeNull()
|
|
70
96
|
expect(getByText('Open in browser')).toBeTruthy()
|
|
71
97
|
})
|
|
98
|
+
|
|
99
|
+
it('asks the host app to open the attachment in the browser', () => {
|
|
100
|
+
const { getByText } = renderScreen()
|
|
101
|
+
|
|
102
|
+
fireEvent.press(getByText('Open in browser'))
|
|
103
|
+
|
|
104
|
+
expect(hostOpenURL).toHaveBeenCalledWith('https://example.com/a1.png', {
|
|
105
|
+
forceOpenInBrowser: true,
|
|
106
|
+
})
|
|
107
|
+
})
|
|
72
108
|
})
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import React, { useCallback } from 'react'
|
|
3
|
-
import { Alert,
|
|
3
|
+
import { Alert, StyleSheet } from 'react-native'
|
|
4
4
|
import FormSheet, { getFormSheetScreenOptions } from '../../components/primitive/form_sheet'
|
|
5
5
|
import { useConversation } from '../../hooks/use_conversation'
|
|
6
|
+
import { Linking } from '../../utils'
|
|
6
7
|
import { useDeleteAttachment } from './hooks/useDeleteAttachment'
|
|
7
8
|
|
|
8
9
|
export const AttachmentActionsScreenOptions = getFormSheetScreenOptions({
|
|
@@ -59,7 +60,7 @@ export function AttachmentActionsScreen({ route }: AttachmentActionsScreenProps)
|
|
|
59
60
|
}, [attachmentName, handleDeleteAttachment, navigation])
|
|
60
61
|
|
|
61
62
|
const handleOpenInBrowser = () => {
|
|
62
|
-
Linking.openURL(attachmentUrl)
|
|
63
|
+
Linking.openURL(attachmentUrl, { forceOpenInBrowser: true })
|
|
63
64
|
navigation.goBack()
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { HeaderHeightContext } from '@react-navigation/elements'
|
|
2
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
3
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { render } from '@testing-library/react-native'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { Image } from 'react-native'
|
|
7
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
8
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
9
|
+
import type { AvatarUpdatePayload } from '../../../hooks/use_conversation_avatar_update'
|
|
10
|
+
import { AvatarPickerScreen } from '../avatar_picker_screen'
|
|
11
|
+
|
|
12
|
+
jest.mock('@react-navigation/native', () => ({
|
|
13
|
+
...jest.requireActual('@react-navigation/native'),
|
|
14
|
+
useNavigation: () => ({ goBack: jest.fn(), dispatch: jest.fn() }),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../hooks/use_api_client', () => ({ useApiClient: () => ({}) }))
|
|
17
|
+
jest.mock('../../../hooks/use_upload_client', () => ({ useUploadClient: () => ({}) }))
|
|
18
|
+
jest.mock('../../../hooks/use_conversation', () => ({
|
|
19
|
+
...jest.requireActual('../../../hooks/use_conversation'),
|
|
20
|
+
useConversation: () => ({
|
|
21
|
+
data: { id: 7, customAvatarType: 'icon', customAvatarKey: 'star', customAvatarColor: 'cosmic' },
|
|
22
|
+
}),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const safeAreaMetrics = {
|
|
26
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
27
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('AvatarPickerScreen', () => {
|
|
31
|
+
it('opens on a photo that is still uploading instead of the cached avatar', async () => {
|
|
32
|
+
const queryClient = buildTestQueryClient()
|
|
33
|
+
const photo: AvatarUpdatePayload = {
|
|
34
|
+
kind: 'image',
|
|
35
|
+
color: 'cosmic',
|
|
36
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
37
|
+
}
|
|
38
|
+
let finishUpload = () => {}
|
|
39
|
+
const uploading = new Promise<void>(resolve => (finishUpload = resolve))
|
|
40
|
+
const upload = queryClient
|
|
41
|
+
.getMutationCache()
|
|
42
|
+
.build(queryClient, {
|
|
43
|
+
mutationKey: ['updateConversationAvatar', 7],
|
|
44
|
+
mutationFn: () => uploading,
|
|
45
|
+
networkMode: 'always',
|
|
46
|
+
})
|
|
47
|
+
.execute(photo)
|
|
48
|
+
|
|
49
|
+
const view = render(
|
|
50
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
51
|
+
<ThemeProvider value={DefaultTheme}>
|
|
52
|
+
<HeaderHeightContext.Provider value={0}>
|
|
53
|
+
<QueryClientProvider client={queryClient}>
|
|
54
|
+
<AvatarPickerScreen route={{ params: { conversation_id: 7 } } as never} />
|
|
55
|
+
</QueryClientProvider>
|
|
56
|
+
</HeaderHeightContext.Provider>
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
</SafeAreaProvider>
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const sources = view.UNSAFE_getAllByType(Image).map(image => image.props.source)
|
|
62
|
+
expect(sources).toContainEqual({ uri: 'file:///photo.jpg' })
|
|
63
|
+
|
|
64
|
+
finishUpload()
|
|
65
|
+
await upload
|
|
66
|
+
})
|
|
67
|
+
})
|