@planningcenter/chat-react-native 4.2.1-qa-staging.12 → 4.2.1-qa-staging.15
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/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/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +3 -3
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/display/conversation_avatar.d.ts +1 -2
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/hooks/use_debounced_search_term.d.ts +2 -0
- package/build/hooks/use_debounced_search_term.d.ts.map +1 -0
- package/build/hooks/use_debounced_search_term.js +40 -0
- package/build/hooks/use_debounced_search_term.js.map +1 -0
- package/build/hooks/use_search_results.d.ts +19 -0
- package/build/hooks/use_search_results.d.ts.map +1 -0
- package/build/hooks/use_search_results.js +153 -0
- package/build/hooks/use_search_results.js.map +1 -0
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.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 +3 -2
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +2 -2
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts +2 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.js +39 -24
- package/build/screens/conversation_select_recipients/components/view_more_link_row.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 +142 -158
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.js +159 -133
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/get_help_screen.js +4 -4
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/search/components/conversation_result_row.d.ts +8 -0
- package/build/screens/search/components/conversation_result_row.d.ts.map +1 -0
- package/build/screens/search/components/conversation_result_row.js +80 -0
- package/build/screens/search/components/conversation_result_row.js.map +1 -0
- package/build/screens/search/components/conversation_results.d.ts +8 -0
- package/build/screens/search/components/conversation_results.d.ts.map +1 -0
- package/build/screens/search/components/conversation_results.js +77 -0
- package/build/screens/search/components/conversation_results.js.map +1 -0
- package/build/screens/search/components/message_result_row.d.ts +8 -0
- package/build/screens/search/components/message_result_row.d.ts.map +1 -0
- package/build/screens/search/components/message_result_row.js +152 -0
- package/build/screens/search/components/message_result_row.js.map +1 -0
- package/build/screens/search/components/result_row.d.ts +10 -0
- package/build/screens/search/components/result_row.d.ts.map +1 -0
- package/build/screens/search/components/result_row.js +102 -0
- package/build/screens/search/components/result_row.js.map +1 -0
- package/build/screens/search/components/results_section.d.ts +9 -0
- package/build/screens/search/components/results_section.d.ts.map +1 -0
- package/build/screens/search/components/results_section.js +51 -0
- package/build/screens/search/components/results_section.js.map +1 -0
- package/build/screens/search/components/search_blank_states.d.ts +7 -0
- package/build/screens/search/components/search_blank_states.d.ts.map +1 -0
- package/build/screens/search/components/search_blank_states.js +72 -0
- package/build/screens/search/components/search_blank_states.js.map +1 -0
- package/build/screens/search/components/search_field.d.ts +7 -0
- package/build/screens/search/components/search_field.d.ts.map +1 -0
- package/build/screens/search/components/search_field.js +152 -0
- package/build/screens/search/components/search_field.js.map +1 -0
- package/build/screens/search/components/search_results_list.d.ts +8 -0
- package/build/screens/search/components/search_results_list.d.ts.map +1 -0
- package/build/screens/search/components/search_results_list.js +314 -0
- package/build/screens/search/components/search_results_list.js.map +1 -0
- package/build/screens/search/components/snippet.d.ts +8 -0
- package/build/screens/search/components/snippet.d.ts.map +1 -0
- package/build/screens/search/components/snippet.js +68 -0
- package/build/screens/search/components/snippet.js.map +1 -0
- package/build/screens/search/search_screen.d.ts +5 -0
- package/build/screens/search/search_screen.d.ts.map +1 -0
- package/build/screens/search/search_screen.js +68 -0
- package/build/screens/search/search_screen.js.map +1 -0
- package/build/types/resources/conversation.d.ts +1 -0
- package/build/types/resources/conversation.d.ts.map +1 -1
- package/build/types/resources/conversation.js.map +1 -1
- package/build/types/resources/index.d.ts +1 -0
- package/build/types/resources/index.d.ts.map +1 -1
- package/build/types/resources/index.js +1 -0
- package/build/types/resources/index.js.map +1 -1
- package/build/types/resources/search_result.d.ts +29 -0
- package/build/types/resources/search_result.d.ts.map +1 -0
- package/build/types/resources/search_result.js +2 -0
- package/build/types/resources/search_result.js.map +1 -0
- package/build/utils/client/request_helpers.js +1 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- package/build/utils/request/get_search_results.d.ts +13 -0
- package/build/utils/request/get_search_results.d.ts.map +1 -0
- package/build/utils/request/get_search_results.js +20 -0
- package/build/utils/request/get_search_results.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/screens/get_help_screen.test.ts +40 -0
- package/src/__tests__/utils/client.ts +3 -4
- package/src/components/conversation/__tests__/message_form.test.tsx +78 -0
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- package/src/components/conversation/message_form.tsx +2 -2
- package/src/components/display/conversation_avatar.tsx +1 -10
- package/src/hooks/__tests__/use_debounced_search_term.test.tsx +38 -0
- package/src/hooks/__tests__/use_search_results.test.tsx +88 -0
- package/src/hooks/use_debounced_search_term.ts +20 -0
- package/src/hooks/use_search_results.ts +78 -0
- package/src/navigation/index.tsx +5 -0
- package/src/screens/age_check/age_check_underage_screen.tsx +3 -2
- package/src/screens/bug_report_screen.tsx +2 -10
- package/src/screens/conversation_select_recipients/components/view_more_link_row.tsx +12 -3
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +3 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +62 -0
- package/src/screens/conversations/components/search_list_header_component.tsx +11 -0
- package/src/screens/get_help_screen.tsx +4 -4
- package/src/screens/search/__tests__/search_screen.test.tsx +64 -0
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +55 -0
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +65 -0
- package/src/screens/search/components/__tests__/result_row.test.tsx +33 -0
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +20 -0
- package/src/screens/search/components/__tests__/search_field.test.tsx +29 -0
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +135 -0
- package/src/screens/search/components/conversation_result_row.tsx +36 -0
- package/src/screens/search/components/conversation_results.tsx +39 -0
- package/src/screens/search/components/message_result_row.tsx +48 -0
- package/src/screens/search/components/result_row.tsx +58 -0
- package/src/screens/search/components/results_section.tsx +34 -0
- package/src/screens/search/components/search_blank_states.tsx +34 -0
- package/src/screens/search/components/search_field.tsx +81 -0
- package/src/screens/search/components/search_results_list.tsx +147 -0
- package/src/screens/search/components/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +49 -0
- package/src/types/resources/conversation.ts +9 -0
- package/src/types/resources/index.ts +1 -0
- package/src/types/resources/search_result.ts +32 -0
- package/src/utils/__tests__/get_search_results.test.ts +24 -0
- package/src/utils/client/__tests__/request_helpers.test.ts +40 -0
- package/src/utils/client/request_helpers.ts +1 -1
- package/src/utils/request/get_search_results.ts +23 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
+
import { QueryClientProvider, notifyManager } from '@tanstack/react-query'
|
|
3
|
+
import { act, fireEvent, render, screen } from '@testing-library/react-native'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import { chatQueryClient } from '../../../contexts/api_provider'
|
|
6
|
+
import type { ConversationResource } from '../../../types'
|
|
7
|
+
import { MessageForm } from '../message_form'
|
|
8
|
+
|
|
9
|
+
jest.mock('../../../contexts/api_provider', () => {
|
|
10
|
+
const { buildTestQueryClient } = require('../../../__utils__/query_client')
|
|
11
|
+
return { chatQueryClient: buildTestQueryClient() }
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const mockPost = jest.fn()
|
|
15
|
+
jest.mock('../../../hooks/use_api_client', () => ({
|
|
16
|
+
useApiClient: () => ({ chat: { post: mockPost, patch: jest.fn() } }),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
jest.mock('../../../hooks/use_current_person', () => ({
|
|
20
|
+
useCurrentPerson: () => ({ type: 'Person', id: 1, name: 'Me', avatar: null }),
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
jest.mock('../../../hooks/use_message_draft', () => ({
|
|
24
|
+
useMessageDraft: () => ({ draft: null, saveDraft: jest.fn(), clearDraft: jest.fn() }),
|
|
25
|
+
}))
|
|
26
|
+
|
|
27
|
+
jest.mock('../../../hooks/use_attachment_uploader', () => ({
|
|
28
|
+
useAttachmentUploader: () => ({
|
|
29
|
+
attachments: [],
|
|
30
|
+
attachmentIds: [],
|
|
31
|
+
pendingUploads: false,
|
|
32
|
+
flaggedAttachmentCount: 0,
|
|
33
|
+
reset: jest.fn(),
|
|
34
|
+
}),
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
jest.mock('../../../hooks/use_broadcast_typing_status', () => ({
|
|
38
|
+
useBroadcastTypingStatus: () => jest.fn(),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
jest.mock('@react-navigation/native', () => ({
|
|
42
|
+
...jest.requireActual('@react-navigation/native'),
|
|
43
|
+
useNavigation: () => ({ navigate: jest.fn(), setParams: jest.fn() }),
|
|
44
|
+
useRoute: () => ({ params: { conversation_id: 7 } }),
|
|
45
|
+
}))
|
|
46
|
+
|
|
47
|
+
notifyManager.setNotifyFunction(fn => act(fn))
|
|
48
|
+
|
|
49
|
+
const conversation = { id: 7, disabled: false } as unknown as ConversationResource
|
|
50
|
+
|
|
51
|
+
describe('MessageForm', () => {
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
chatQueryClient.clear()
|
|
54
|
+
// Never resolves, so the send stays in flight for the assertion.
|
|
55
|
+
mockPost.mockReset().mockReturnValue(new Promise(() => {}))
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('keeps the input editable while a sent message is in flight', async () => {
|
|
59
|
+
render(
|
|
60
|
+
<QueryClientProvider client={chatQueryClient}>
|
|
61
|
+
<ThemeProvider value={DefaultTheme}>
|
|
62
|
+
<MessageForm.Root conversation={conversation}>
|
|
63
|
+
<MessageForm.TextInput />
|
|
64
|
+
<MessageForm.SubmitButton />
|
|
65
|
+
</MessageForm.Root>
|
|
66
|
+
</ThemeProvider>
|
|
67
|
+
</QueryClientProvider>
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
fireEvent.changeText(screen.getByTestId('message-composer-input'), 'hello')
|
|
71
|
+
await act(async () => {
|
|
72
|
+
fireEvent.press(screen.getByLabelText('Send message'))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
expect(mockPost).toHaveBeenCalled()
|
|
76
|
+
expect(screen.getByTestId('message-composer-input').props.editable).toBe(true)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Text, StyleSheet
|
|
3
|
+
import { Text, StyleSheet } from 'react-native'
|
|
4
4
|
import { useTheme } from '../../../hooks'
|
|
5
5
|
import { DenormalizedGiphyAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
6
|
-
import { assertKeysAreNumbers } from '../../../utils'
|
|
6
|
+
import { assertKeysAreNumbers, Linking } from '../../../utils'
|
|
7
7
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
8
8
|
import { Image } from '../../display'
|
|
9
9
|
|
|
@@ -22,7 +22,6 @@ export function GiphyAttachment({
|
|
|
22
22
|
|
|
23
23
|
function handlePress() {
|
|
24
24
|
if (titleLink) {
|
|
25
|
-
// Open Giphy link in the default web browser
|
|
26
25
|
Linking.openURL(titleLink)
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
|
|
2
2
|
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import {
|
|
4
|
-
Linking,
|
|
5
4
|
Platform,
|
|
6
5
|
Pressable,
|
|
7
6
|
ScrollView,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
FileAttachment,
|
|
35
34
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
36
35
|
import {
|
|
36
|
+
Linking,
|
|
37
37
|
Log,
|
|
38
38
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
39
39
|
platformFontWeightMedium,
|
|
@@ -276,8 +276,8 @@ function MessageFormRoot({
|
|
|
276
276
|
// added earlier.
|
|
277
277
|
if (!(await catchUpBeforeSend())) return
|
|
278
278
|
|
|
279
|
-
reset()
|
|
280
279
|
mutateAsync({ text: messageText, attachments: attachmentsForSubmit })
|
|
280
|
+
reset()
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { ViewStyle } from 'react-native'
|
|
3
|
-
import type {
|
|
3
|
+
import type { ConversationAvatarData } from '../../types'
|
|
4
4
|
import AvatarPrimitive, { type AvatarRootProps } from '../primitive/avatar_primitive'
|
|
5
5
|
import { AvatarGroup } from './avatar_group'
|
|
6
6
|
import { EmojiAvatar } from './emoji_avatar'
|
|
7
7
|
import { type IconString } from './icon'
|
|
8
8
|
import { IconAvatar } from './icon_avatar'
|
|
9
9
|
|
|
10
|
-
type ConversationAvatarData = Pick<
|
|
11
|
-
ConversationResource,
|
|
12
|
-
| 'customAvatarType'
|
|
13
|
-
| 'customAvatarKey'
|
|
14
|
-
| 'customAvatarColor'
|
|
15
|
-
| 'customAvatarImageUrl'
|
|
16
|
-
| 'previewAvatarUrls'
|
|
17
|
-
>
|
|
18
|
-
|
|
19
10
|
type ResolvedAvatar =
|
|
20
11
|
| { kind: 'image'; url: string }
|
|
21
12
|
| { kind: 'icon'; iconKey: string; color: string | null }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
2
|
+
import { useDebouncedSearchTerm } from '../use_debounced_search_term'
|
|
3
|
+
|
|
4
|
+
beforeEach(() => jest.useFakeTimers())
|
|
5
|
+
afterEach(() => jest.useRealTimers())
|
|
6
|
+
|
|
7
|
+
describe('useDebouncedSearchTerm', () => {
|
|
8
|
+
it('settles on the trimmed term once typing pauses', () => {
|
|
9
|
+
const { result, rerender } = renderHook(
|
|
10
|
+
({ term }: { term: string }) => useDebouncedSearchTerm(term),
|
|
11
|
+
{
|
|
12
|
+
initialProps: { term: 'bud' },
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
rerender({ term: ' budget ' })
|
|
17
|
+
act(() => jest.advanceTimersByTime(199))
|
|
18
|
+
expect(result.current).toBe('')
|
|
19
|
+
|
|
20
|
+
act(() => jest.advanceTimersByTime(1))
|
|
21
|
+
expect(result.current).toBe('budget')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('clears immediately when the term empties', () => {
|
|
25
|
+
const { result, rerender } = renderHook(
|
|
26
|
+
({ term }: { term: string }) => useDebouncedSearchTerm(term),
|
|
27
|
+
{
|
|
28
|
+
initialProps: { term: 'budget' },
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
act(() => jest.advanceTimersByTime(200))
|
|
32
|
+
expect(result.current).toBe('budget')
|
|
33
|
+
|
|
34
|
+
rerender({ term: ' ' })
|
|
35
|
+
|
|
36
|
+
expect(result.current).toBe('')
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook, waitFor } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
+
import type { SearchResultResource } from '../../types/resources/search_result'
|
|
6
|
+
import { NO_FAILED_TYPES, useSearchResults } from '../use_search_results'
|
|
7
|
+
|
|
8
|
+
const mockGet = jest.fn()
|
|
9
|
+
jest.mock('../use_api_client', () => ({ useApiClient: () => ({ chat: { get: mockGet } }) }))
|
|
10
|
+
|
|
11
|
+
const result = (type: SearchResultResource['type'], id: string) =>
|
|
12
|
+
({ type, id, title: `${type} ${id}`, url: `/${type}s/${id}` }) as SearchResultResource
|
|
13
|
+
|
|
14
|
+
const page = (data: SearchResultResource[], meta: Record<string, unknown> = {}) => ({
|
|
15
|
+
data,
|
|
16
|
+
links: {},
|
|
17
|
+
meta: { count: data.length, totalCount: data.length, ...meta },
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
21
|
+
<QueryClientProvider client={buildTestQueryClient()}>{children}</QueryClientProvider>
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
beforeEach(() => mockGet.mockReset())
|
|
25
|
+
|
|
26
|
+
describe('useSearchResults', () => {
|
|
27
|
+
it('flattens pages into one list without repeating a result', async () => {
|
|
28
|
+
mockGet
|
|
29
|
+
.mockResolvedValueOnce(
|
|
30
|
+
page([result('conversation', '1'), result('message', '1')], { next: { offset: '20' } })
|
|
31
|
+
)
|
|
32
|
+
.mockResolvedValueOnce(page([result('message', '1'), result('message', '2')]))
|
|
33
|
+
|
|
34
|
+
const { result: hook } = renderHook(() => useSearchResults('potluck'), { wrapper })
|
|
35
|
+
await waitFor(() => expect(hook.current.hasNextPage).toBe(true))
|
|
36
|
+
|
|
37
|
+
act(() => {
|
|
38
|
+
hook.current.loadMore()
|
|
39
|
+
})
|
|
40
|
+
await waitFor(() => expect(hook.current.hasNextPage).toBe(false))
|
|
41
|
+
|
|
42
|
+
expect(hook.current.results.map(({ type, id }) => `${type}:${id}`)).toEqual([
|
|
43
|
+
'conversation:1',
|
|
44
|
+
'message:1',
|
|
45
|
+
'message:2',
|
|
46
|
+
])
|
|
47
|
+
expect(mockGet).toHaveBeenLastCalledWith({
|
|
48
|
+
url: '/search_results',
|
|
49
|
+
data: expect.objectContaining({ q: 'potluck', offset: 20 }),
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('reads failedTypes from the first page', async () => {
|
|
54
|
+
mockGet
|
|
55
|
+
.mockResolvedValueOnce(page([], { failedTypes: ['message'], next: { offset: '20' } }))
|
|
56
|
+
.mockResolvedValueOnce(page([], { failedTypes: ['conversation'] }))
|
|
57
|
+
|
|
58
|
+
const { result: hook } = renderHook(() => useSearchResults('potluck'), { wrapper })
|
|
59
|
+
await waitFor(() => expect(hook.current.hasNextPage).toBe(true))
|
|
60
|
+
|
|
61
|
+
act(() => {
|
|
62
|
+
hook.current.loadMore()
|
|
63
|
+
})
|
|
64
|
+
await waitFor(() => expect(hook.current.hasNextPage).toBe(false))
|
|
65
|
+
|
|
66
|
+
expect(hook.current.failedTypes).toEqual(['message'])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('makes no request for an empty or whitespace-only term', () => {
|
|
70
|
+
const { result: hook } = renderHook(() => useSearchResults(' '), { wrapper })
|
|
71
|
+
|
|
72
|
+
expect(mockGet).not.toHaveBeenCalled()
|
|
73
|
+
expect(hook.current.results).toEqual([])
|
|
74
|
+
expect(hook.current.failedTypes).toBe(NO_FAILED_TYPES)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('searches with the trimmed term', async () => {
|
|
78
|
+
mockGet.mockResolvedValueOnce(page([]))
|
|
79
|
+
|
|
80
|
+
const { result: hook } = renderHook(() => useSearchResults(' potluck '), { wrapper })
|
|
81
|
+
await waitFor(() => expect(hook.current.isPending).toBe(false))
|
|
82
|
+
|
|
83
|
+
expect(mockGet).toHaveBeenCalledWith({
|
|
84
|
+
url: '/search_results',
|
|
85
|
+
data: expect.objectContaining({ q: 'potluck' }),
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const DEFAULT_DELAY_MS = 200
|
|
4
|
+
|
|
5
|
+
export function useDebouncedSearchTerm(term: string, delayMs = DEFAULT_DELAY_MS) {
|
|
6
|
+
const [debouncedTerm, setDebouncedTerm] = useState('')
|
|
7
|
+
const trimmedTerm = term.trim()
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (trimmedTerm.length === 0) {
|
|
11
|
+
setDebouncedTerm('')
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const timer = setTimeout(() => setDebouncedTerm(trimmedTerm), delayMs)
|
|
16
|
+
return () => clearTimeout(timer)
|
|
17
|
+
}, [trimmedTerm, delayMs])
|
|
18
|
+
|
|
19
|
+
return debouncedTerm
|
|
20
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
2
|
+
import { useCallback, useMemo } from 'react'
|
|
3
|
+
import type { ApiCollection } from '../types'
|
|
4
|
+
import type { SearchResultResource } from '../types/resources/search_result'
|
|
5
|
+
import {
|
|
6
|
+
getSearchResultsQueryKey,
|
|
7
|
+
getSearchResultsRequestArgs,
|
|
8
|
+
} from '../utils/request/get_search_results'
|
|
9
|
+
import { ONE_MINUTE } from '../utils/time'
|
|
10
|
+
import { useApiClient } from './use_api_client'
|
|
11
|
+
|
|
12
|
+
export type SearchResultsCollection = ApiCollection<SearchResultResource> & {
|
|
13
|
+
meta: { failedTypes?: SearchResultResource['type'][] }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type SearchResultsPageParam = { offset?: number }
|
|
17
|
+
|
|
18
|
+
export const NO_FAILED_TYPES: SearchResultResource['type'][] = []
|
|
19
|
+
|
|
20
|
+
export function useSearchResults(term: string) {
|
|
21
|
+
const apiClient = useApiClient()
|
|
22
|
+
const trimmedTerm = term.trim()
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
data,
|
|
26
|
+
isPending,
|
|
27
|
+
isError,
|
|
28
|
+
isFetchNextPageError,
|
|
29
|
+
fetchNextPage,
|
|
30
|
+
hasNextPage,
|
|
31
|
+
isFetchingNextPage,
|
|
32
|
+
} = useInfiniteQuery({
|
|
33
|
+
queryKey: getSearchResultsQueryKey(trimmedTerm),
|
|
34
|
+
queryFn: ({ pageParam }) => {
|
|
35
|
+
const requestArgs = getSearchResultsRequestArgs(trimmedTerm)
|
|
36
|
+
return apiClient.chat.get<SearchResultsCollection>({
|
|
37
|
+
url: requestArgs.url,
|
|
38
|
+
data: { ...requestArgs.data, ...pageParam },
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
initialPageParam: {} as SearchResultsPageParam,
|
|
42
|
+
getNextPageParam: lastPage => nextPageParam(lastPage.meta.next?.offset),
|
|
43
|
+
enabled: trimmedTerm.length >= 1,
|
|
44
|
+
staleTime: ONE_MINUTE,
|
|
45
|
+
refetchOnWindowFocus: false,
|
|
46
|
+
refetchOnMount: false,
|
|
47
|
+
retry: 1,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const results = useMemo(() => uniqueResults(data?.pages.flatMap(page => page.data) ?? []), [data])
|
|
51
|
+
const failedTypes = data?.pages[0]?.meta.failedTypes ?? NO_FAILED_TYPES
|
|
52
|
+
const loadMore = useCallback(() => fetchNextPage({ cancelRefetch: false }), [fetchNextPage])
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
results,
|
|
56
|
+
failedTypes,
|
|
57
|
+
isPending,
|
|
58
|
+
isError: isError && !isFetchNextPageError,
|
|
59
|
+
isFetchNextPageError,
|
|
60
|
+
loadMore,
|
|
61
|
+
hasNextPage,
|
|
62
|
+
isFetchingNextPage,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function nextPageParam(offset?: string): SearchResultsPageParam | undefined {
|
|
67
|
+
return offset ? { offset: Number(offset) } : undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function uniqueResults(results: SearchResultResource[]) {
|
|
71
|
+
const seen = new Set<string>()
|
|
72
|
+
return results.filter(result => {
|
|
73
|
+
const key = `${result.type}:${result.id}`
|
|
74
|
+
if (seen.has(key)) return false
|
|
75
|
+
seen.add(key)
|
|
76
|
+
return true
|
|
77
|
+
})
|
|
78
|
+
}
|
package/src/navigation/index.tsx
CHANGED
|
@@ -72,6 +72,7 @@ import { NotFound } from '../screens/not_found'
|
|
|
72
72
|
import { NotificationSettingsScreen } from '../screens/notification_settings_screen'
|
|
73
73
|
import { PreferredAppSelectionScreen } from '../screens/preferred_app_selection_screen'
|
|
74
74
|
import { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen'
|
|
75
|
+
import { SearchScreen, SearchScreenOptions } from '../screens/search/search_screen'
|
|
75
76
|
import { SendGiphyScreen, SendGiphyScreenOptions } from '../screens/send_giphy_screen'
|
|
76
77
|
import { SettingsScreen } from '../screens/settings_screen'
|
|
77
78
|
import {
|
|
@@ -186,6 +187,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
186
187
|
screen: ConversationFiltersScreen,
|
|
187
188
|
options: ConversationFiltersScreenOptions,
|
|
188
189
|
},
|
|
190
|
+
Search: {
|
|
191
|
+
screen: SearchScreen,
|
|
192
|
+
options: SearchScreenOptions,
|
|
193
|
+
},
|
|
189
194
|
Conversation: {
|
|
190
195
|
screen: ConversationScreen,
|
|
191
196
|
options: ({ route, navigation }) =>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useRoute, RouteProp } from '@react-navigation/native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Linking, StyleSheet, View, ScrollView } from 'react-native'
|
|
3
|
+
import { Linking as RNLinking, 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 {
|
|
@@ -18,7 +19,7 @@ export function AgeCheckUnderageScreen({ contactEmail }: AgeCheckUnderageScreenP
|
|
|
18
19
|
|
|
19
20
|
const openChurchAdminHelp = () => {
|
|
20
21
|
if (!email) return
|
|
21
|
-
|
|
22
|
+
RNLinking.openURL(`mailto:${email}`)
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const openTerms = () => {
|
|
@@ -5,15 +5,7 @@ import type {
|
|
|
5
5
|
} from '@react-navigation/native-stack'
|
|
6
6
|
import { startsWith } from 'lodash'
|
|
7
7
|
import React, { useCallback, useState } from 'react'
|
|
8
|
-
import {
|
|
9
|
-
View,
|
|
10
|
-
StyleSheet,
|
|
11
|
-
TextInput,
|
|
12
|
-
Linking,
|
|
13
|
-
ScrollView,
|
|
14
|
-
TouchableOpacity,
|
|
15
|
-
Platform,
|
|
16
|
-
} from 'react-native'
|
|
8
|
+
import { View, StyleSheet, TextInput, ScrollView, TouchableOpacity, Platform } from 'react-native'
|
|
17
9
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
18
10
|
import {
|
|
19
11
|
Button,
|
|
@@ -38,7 +30,7 @@ import { useTheme } from '../hooks'
|
|
|
38
30
|
import { useAppName } from '../hooks/use_app_name'
|
|
39
31
|
import { useReportBugAction } from '../hooks/use_report_bug_action'
|
|
40
32
|
import { useUploadClient } from '../hooks/use_upload_client'
|
|
41
|
-
import { ImagePicker, ImagePickerResult, platformFontWeightBold } from '../utils'
|
|
33
|
+
import { ImagePicker, ImagePickerResult, Linking, platformFontWeightBold } from '../utils'
|
|
42
34
|
|
|
43
35
|
const MAX_DESCRIPTION_LENGTH = 2000
|
|
44
36
|
|
|
@@ -4,15 +4,24 @@ import { TextButton } from '../../../components'
|
|
|
4
4
|
interface ViewMoreLinkRowProps {
|
|
5
5
|
onPress: () => void
|
|
6
6
|
accessibilityHint: string
|
|
7
|
+
expanded?: boolean
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const ViewMoreLinkRow = ({
|
|
10
|
+
export const ViewMoreLinkRow = ({
|
|
11
|
+
accessibilityHint,
|
|
12
|
+
expanded = false,
|
|
13
|
+
onPress,
|
|
14
|
+
}: ViewMoreLinkRowProps) => {
|
|
10
15
|
const styles = useRowStyles()
|
|
11
16
|
|
|
12
17
|
return (
|
|
13
18
|
<View style={[styles.row]}>
|
|
14
|
-
<TextButton
|
|
15
|
-
|
|
19
|
+
<TextButton
|
|
20
|
+
onPress={onPress}
|
|
21
|
+
accessibilityHint={accessibilityHint}
|
|
22
|
+
accessibilityState={{ expanded }}
|
|
23
|
+
>
|
|
24
|
+
{expanded ? 'View less' : 'View more'}
|
|
16
25
|
</TextButton>
|
|
17
26
|
</View>
|
|
18
27
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StackActions, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { RefObject,
|
|
3
|
+
import { RefObject, useRef, useState } from 'react'
|
|
4
4
|
import { FlatList, Pressable, StyleSheet, TextInput, View } from 'react-native'
|
|
5
5
|
import { Avatar, Badge, Banner, Icon, KeyboardView, Spinner, Text } from '../../components'
|
|
6
6
|
import { ActionButton } from '../../components/display/action_button'
|
|
@@ -11,6 +11,7 @@ import { useDirectMessageAffiliations } from '../../hooks/direct_messages/use_di
|
|
|
11
11
|
import { useDirectMessageCandidates } from '../../hooks/direct_messages/use_direct_message_candidates'
|
|
12
12
|
import { useDirectMessageConversationValidate } from '../../hooks/direct_messages/use_direct_message_conversation_validate'
|
|
13
13
|
import { useFindOrCreateDirectMessageConversation } from '../../hooks/direct_messages/use_find_or_create_direct_message_conversation'
|
|
14
|
+
import { useDebouncedSearchTerm } from '../../hooks/use_debounced_search_term'
|
|
14
15
|
import { availableFeatures, useFeatures } from '../../hooks/use_features'
|
|
15
16
|
import { DirectMessageCandidateResource } from '../../types/resources/direct_message_candidate'
|
|
16
17
|
import { ResultsHeading } from './components/results_heading'
|
|
@@ -26,7 +27,7 @@ export function ConversationSelectDirectMessageRecipientsScreen({
|
|
|
26
27
|
const navigation = useNavigation()
|
|
27
28
|
const { featureEnabled } = useFeatures()
|
|
28
29
|
const [searchTerm, setSearchTerm] = useState('')
|
|
29
|
-
const
|
|
30
|
+
const debouncedTerm = useDebouncedSearchTerm(searchTerm)
|
|
30
31
|
const [selectedPeople, setSelectedPeople] = useState<Map<string, DirectMessageCandidateResource>>(
|
|
31
32
|
() =>
|
|
32
33
|
new Map(
|
|
@@ -45,16 +46,10 @@ export function ConversationSelectDirectMessageRecipientsScreen({
|
|
|
45
46
|
)
|
|
46
47
|
const searchInputRef = useRef<TextInput>(null)
|
|
47
48
|
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const timer = setTimeout(() => setDebouncedTerm(searchTerm), 200)
|
|
50
|
-
return () => clearTimeout(timer)
|
|
51
|
-
}, [searchTerm])
|
|
52
|
-
|
|
53
49
|
const selectPerson = (person: DirectMessageCandidateResource) => {
|
|
54
50
|
if (selectedPeople.size >= MAX_RECIPIENTS) return
|
|
55
51
|
setSelectedPeople(prev => new Map(prev).set(person.id, person))
|
|
56
52
|
setSearchTerm('')
|
|
57
|
-
setDebouncedTerm('')
|
|
58
53
|
// Controlled TextInput can retain stale native text on iOS when the value
|
|
59
54
|
// is cleared while it stays focused (keyboardShouldPersistTaps keeps it
|
|
60
55
|
// focused through the tap) — clear() forces the native view to sync. Gated
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SearchListHeaderComponent } from '../search_list_header_component'
|
|
4
|
+
|
|
5
|
+
const mockNavigate = jest.fn()
|
|
6
|
+
|
|
7
|
+
jest.mock('@react-navigation/native', () => ({
|
|
8
|
+
...jest.requireActual('@react-navigation/native'),
|
|
9
|
+
useNavigation: () => ({ setParams: jest.fn(), navigate: mockNavigate }),
|
|
10
|
+
useRoute: () => ({ params: {} }),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
jest.mock('../../../../hooks/use_groups', () => ({
|
|
14
|
+
useCanDisplayGroups: () => true,
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../../hooks/use_direct_messages_eligible', () => ({
|
|
17
|
+
useDirectMessagesEligible: () => true,
|
|
18
|
+
}))
|
|
19
|
+
jest.mock('../../../../hooks/use_has_direct_messages', () => ({
|
|
20
|
+
useHasDirectMessages: () => true,
|
|
21
|
+
}))
|
|
22
|
+
jest.mock('../../../../hooks/use_chat_permissions', () => ({
|
|
23
|
+
useCanCreateConversations: () => true,
|
|
24
|
+
}))
|
|
25
|
+
jest.mock('../../../../hooks/use_new_conversation_entry', () => ({
|
|
26
|
+
useNewConversationEntry: () => 'select_type',
|
|
27
|
+
}))
|
|
28
|
+
jest.mock('../../../../hooks/use_current_person', () => ({
|
|
29
|
+
useCurrentPersonCache: () => ({ update: jest.fn() }),
|
|
30
|
+
}))
|
|
31
|
+
jest.mock('../../../../hooks/use_conversations_actions', () => ({
|
|
32
|
+
useMarkAllRead: () => ({ markAllRead: jest.fn(), isPending: false }),
|
|
33
|
+
}))
|
|
34
|
+
jest.mock('../../../../hooks/use_new_conversation_from_filter', () => ({
|
|
35
|
+
useNewConversationFromFilter: () => undefined,
|
|
36
|
+
}))
|
|
37
|
+
jest.mock('../../../../hooks/use_api', () => ({
|
|
38
|
+
useApiGet: () => ({ data: undefined }),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
describe('SearchListHeaderComponent search button', () => {
|
|
42
|
+
beforeEach(() => mockNavigate.mockClear())
|
|
43
|
+
|
|
44
|
+
it('navigates to Search on press', () => {
|
|
45
|
+
const view = render(<SearchListHeaderComponent />)
|
|
46
|
+
|
|
47
|
+
fireEvent.press(view.getByTestId('conversations-search-button'))
|
|
48
|
+
|
|
49
|
+
expect(mockNavigate).toHaveBeenCalledTimes(1)
|
|
50
|
+
expect(mockNavigate).toHaveBeenCalledWith('Search')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders the search button after the other actions', () => {
|
|
54
|
+
const view = render(<SearchListHeaderComponent />)
|
|
55
|
+
|
|
56
|
+
const buttons = view.getAllByRole('button').map(button => button.props.accessibilityLabel)
|
|
57
|
+
|
|
58
|
+
expect(buttons.indexOf('Search')).toBeGreaterThanOrEqual(0)
|
|
59
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('Chat settings'))
|
|
60
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('New conversation'))
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -110,6 +110,10 @@ export const SearchListHeaderComponent = () => {
|
|
|
110
110
|
[navigation]
|
|
111
111
|
)
|
|
112
112
|
|
|
113
|
+
const handleSearch = useCallback(() => {
|
|
114
|
+
navigation.navigate('Search')
|
|
115
|
+
}, [navigation])
|
|
116
|
+
|
|
113
117
|
const handleChatSettings = useCallback(() => {
|
|
114
118
|
navigation.navigate('ChatSettings', {})
|
|
115
119
|
}, [navigation])
|
|
@@ -188,6 +192,13 @@ export const SearchListHeaderComponent = () => {
|
|
|
188
192
|
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
189
193
|
/>
|
|
190
194
|
)}
|
|
195
|
+
<ListHeaderActionButton
|
|
196
|
+
name="general.search"
|
|
197
|
+
onPress={handleSearch}
|
|
198
|
+
accessibilityLabel="Search"
|
|
199
|
+
testID="conversations-search-button"
|
|
200
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
201
|
+
/>
|
|
191
202
|
{shouldShowHeaderFiltersButton && <ToggleButton {...moreFiltersButtonProps} />}
|
|
192
203
|
</View>
|
|
193
204
|
</View>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import { useCallback, useMemo } from 'react'
|
|
3
|
-
import { Alert, Linking, StyleSheet, View } from 'react-native'
|
|
3
|
+
import { Alert, Linking as RNLinking, StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Heading, PressableRow, Text, TextInlineButton } from '../components'
|
|
5
5
|
import { useApiGet, useTheme } from '../hooks'
|
|
6
6
|
import { useAppName } from '../hooks/use_app_name'
|
|
7
7
|
import { useOrganization } from '../hooks/use_organization'
|
|
8
8
|
import { ResourceObject } from '../types'
|
|
9
|
-
import { Clipboard } from '../utils'
|
|
9
|
+
import { Clipboard, Linking } from '../utils'
|
|
10
10
|
|
|
11
11
|
type GetHelpScreenRouteProps = {
|
|
12
12
|
type?: 'chat' | 'general'
|
|
@@ -119,7 +119,7 @@ export function sendEmail(email: string) {
|
|
|
119
119
|
|
|
120
120
|
const url = encodeURI(`mailto:${email}`)
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
RNLinking.openURL(url).catch(() => {
|
|
123
123
|
Alert.alert('Oops', `Unable to open: ${email}`, [
|
|
124
124
|
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(email) },
|
|
125
125
|
{ text: 'OK' },
|
|
@@ -132,7 +132,7 @@ export function placePhoneCall(phoneNumber: string) {
|
|
|
132
132
|
|
|
133
133
|
const url = encodeURI(`tel:${phoneNumber}`)
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
RNLinking.openURL(url).catch(() => {
|
|
136
136
|
Alert.alert('Oops', `Unable to open: ${phoneNumber}`, [
|
|
137
137
|
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(phoneNumber) },
|
|
138
138
|
{ text: 'OK' },
|