@planningcenter/chat-react-native 4.6.0-rc.3 → 4.6.0-rc.5
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/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/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/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 +320 -285
- 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.js +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_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 +135 -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/package.json +2 -2
- package/src/components/page/__tests__/page_error_boundary.test.tsx +33 -0
- package/src/components/page/page_error_boundary.tsx +43 -12
- package/src/navigation/page_error_fallbacks.ts +14 -0
- package/src/navigation/screenLayout.tsx +3 -1
- package/src/screens/conversation_select_recipients/__tests__/conversation_select_direct_message_recipients_screen.test.tsx +100 -0
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +77 -68
- package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx +1 -1
- package/src/screens/search/__tests__/search_screen.test.tsx +5 -7
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +6 -2
- package/src/screens/search/components/search_results_list.tsx +33 -13
- package/src/screens/search/search_screen.tsx +8 -18
|
@@ -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,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>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
4
|
+
import { ScreenLayout } from '../../../navigation/screenLayout'
|
|
5
|
+
import { Log } from '../../../utils/native_adapters/configuration'
|
|
6
|
+
import { ResponseError } from '../../../utils/response_error'
|
|
7
|
+
import { ConversationSelectDirectMessageRecipientsScreen } from '../conversation_select_direct_message_recipients_screen'
|
|
8
|
+
|
|
9
|
+
jest.mock('@react-navigation/native', () => ({
|
|
10
|
+
...jest.requireActual('@react-navigation/native'),
|
|
11
|
+
useNavigation: () => ({ getParent: jest.fn(), goBack: jest.fn(), navigate: jest.fn() }),
|
|
12
|
+
useRoute: () => ({ name: 'ConversationSelectDirectMessageRecipients' }),
|
|
13
|
+
}))
|
|
14
|
+
jest.mock('../../../hooks/use_features', () => ({
|
|
15
|
+
...jest.requireActual('../../../hooks/use_features'),
|
|
16
|
+
useFeatures: () => ({ featureEnabled: () => false }),
|
|
17
|
+
}))
|
|
18
|
+
jest.mock('../../../hooks/use_debounced_search_term', () => ({
|
|
19
|
+
useDebouncedSearchTerm: (term: string) => term,
|
|
20
|
+
}))
|
|
21
|
+
jest.mock('../../../hooks/direct_messages/use_direct_message_conversation_validate', () => ({
|
|
22
|
+
useDirectMessageConversationValidate: () => ({ warnings: [], validationPending: false }),
|
|
23
|
+
}))
|
|
24
|
+
jest.mock('../../../hooks/direct_messages/use_find_or_create_direct_message_conversation', () => ({
|
|
25
|
+
useFindOrCreateDirectMessageConversation: () => ({
|
|
26
|
+
findOrCreateConversation: jest.fn(),
|
|
27
|
+
directMessageExists: false,
|
|
28
|
+
isFinding: false,
|
|
29
|
+
isError: false,
|
|
30
|
+
}),
|
|
31
|
+
}))
|
|
32
|
+
jest.mock('../../../hooks/direct_messages/use_direct_message_affiliations', () => ({
|
|
33
|
+
useDirectMessageAffiliations: () => ({
|
|
34
|
+
groups: new Map(),
|
|
35
|
+
teams: new Map(),
|
|
36
|
+
resultsDescription: null,
|
|
37
|
+
}),
|
|
38
|
+
}))
|
|
39
|
+
let mockSearchFailure: Error = new TypeError('Network request failed')
|
|
40
|
+
jest.mock('../../../hooks/direct_messages/use_direct_message_candidates', () => ({
|
|
41
|
+
useDirectMessageCandidates: (term: string) => {
|
|
42
|
+
if (term) throw mockSearchFailure
|
|
43
|
+
return { data: undefined, isFetching: false }
|
|
44
|
+
},
|
|
45
|
+
}))
|
|
46
|
+
jest.mock('../../../components/display/action_button', () => ({ ActionButton: () => null }))
|
|
47
|
+
jest.mock('../../../components/display/keyboard_view', () => ({
|
|
48
|
+
...jest.requireActual('../../../components/display/keyboard_view'),
|
|
49
|
+
KeyboardView: ({ children }: { children: React.ReactNode }) => children,
|
|
50
|
+
}))
|
|
51
|
+
|
|
52
|
+
const renderScreen = () =>
|
|
53
|
+
render(
|
|
54
|
+
<SafeAreaProvider
|
|
55
|
+
initialMetrics={{
|
|
56
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
57
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
<ScreenLayout>
|
|
61
|
+
<ConversationSelectDirectMessageRecipientsScreen route={{ params: {} } as never} />
|
|
62
|
+
</ScreenLayout>
|
|
63
|
+
</SafeAreaProvider>
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
describe('ConversationSelectDirectMessageRecipientsScreen', () => {
|
|
67
|
+
let reportError: jest.SpyInstance
|
|
68
|
+
let consoleError: jest.SpyInstance
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
reportError = jest.spyOn(Log, 'reportError').mockImplementation(() => {})
|
|
72
|
+
consoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
reportError.mockRestore()
|
|
77
|
+
consoleError.mockRestore()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('hands a failed search to the page error view', () => {
|
|
81
|
+
mockSearchFailure = new TypeError('Network request failed')
|
|
82
|
+
const view = renderScreen()
|
|
83
|
+
|
|
84
|
+
fireEvent.changeText(view.getByPlaceholderText('Search'), 'pi')
|
|
85
|
+
|
|
86
|
+
expect(view.getByText('Problem connecting!')).toBeTruthy()
|
|
87
|
+
expect(view.queryByPlaceholderText('Search')).toBeNull()
|
|
88
|
+
expect(reportError).toHaveBeenCalledTimes(1)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("uses the screen's own wording when the search fails for no known reason", () => {
|
|
92
|
+
mockSearchFailure = new ResponseError({ status: 500, statusText: 'x', errors: [] } as never)
|
|
93
|
+
const view = renderScreen()
|
|
94
|
+
|
|
95
|
+
fireEvent.changeText(view.getByPlaceholderText('Search'), 'pi')
|
|
96
|
+
|
|
97
|
+
expect(view.getByText("Couldn't load people right now")).toBeTruthy()
|
|
98
|
+
expect(view.queryByText('Oops!')).toBeNull()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StackActions, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { RefObject, useRef, useState } from 'react'
|
|
3
|
+
import { ReactElement, 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'
|
|
7
7
|
import { AutoFocusAwareTextInput } from '../../components/display/text_input'
|
|
8
|
-
import { ComponentErrorBoundary } from '../../components/page/component_error_boundary'
|
|
9
8
|
import { useTheme } from '../../hooks'
|
|
10
9
|
import { useDirectMessageAffiliations } from '../../hooks/direct_messages/use_direct_message_affiliations'
|
|
11
10
|
import { useDirectMessageCandidates } from '../../hooks/direct_messages/use_direct_message_candidates'
|
|
@@ -92,38 +91,31 @@ export function ConversationSelectDirectMessageRecipientsScreen({
|
|
|
92
91
|
|
|
93
92
|
return (
|
|
94
93
|
<KeyboardView>
|
|
95
|
-
{isError && (
|
|
96
|
-
<Banner
|
|
97
|
-
appearance="error"
|
|
98
|
-
description="There was an issue starting the conversation. Please try again."
|
|
99
|
-
style={styles.errorBanner}
|
|
100
|
-
/>
|
|
101
|
-
)}
|
|
102
|
-
<ToField
|
|
103
|
-
selectedPeople={selectedPeople}
|
|
104
|
-
searchTerm={searchTerm}
|
|
105
|
-
onSearchChange={setSearchTerm}
|
|
106
|
-
onRemove={removePerson}
|
|
107
|
-
onClear={() => setSelectedPeople(new Map())}
|
|
108
|
-
searchInputRef={searchInputRef}
|
|
109
|
-
/>
|
|
110
94
|
<View style={styles.candidateResultsContainer}>
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
95
|
+
<CandidateResults
|
|
96
|
+
term={debouncedTerm}
|
|
97
|
+
selectedPeople={selectedPeople}
|
|
98
|
+
onSelect={selectPerson}
|
|
99
|
+
header={
|
|
100
|
+
<>
|
|
101
|
+
{isError && (
|
|
102
|
+
<Banner
|
|
103
|
+
appearance="error"
|
|
104
|
+
description="There was an issue starting the conversation. Please try again."
|
|
105
|
+
style={styles.errorBanner}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
<ToField
|
|
109
|
+
selectedPeople={selectedPeople}
|
|
110
|
+
searchTerm={searchTerm}
|
|
111
|
+
onSearchChange={setSearchTerm}
|
|
112
|
+
onRemove={removePerson}
|
|
113
|
+
onClear={() => setSelectedPeople(new Map())}
|
|
114
|
+
searchInputRef={searchInputRef}
|
|
115
|
+
/>
|
|
116
|
+
</>
|
|
119
117
|
}
|
|
120
|
-
|
|
121
|
-
<CandidateResults
|
|
122
|
-
term={debouncedTerm}
|
|
123
|
-
selectedPeople={selectedPeople}
|
|
124
|
-
onSelect={selectPerson}
|
|
125
|
-
/>
|
|
126
|
-
</ComponentErrorBoundary>
|
|
118
|
+
/>
|
|
127
119
|
</View>
|
|
128
120
|
<ActionButton
|
|
129
121
|
title={buttonText}
|
|
@@ -214,53 +206,57 @@ function CandidateResults({
|
|
|
214
206
|
term,
|
|
215
207
|
selectedPeople,
|
|
216
208
|
onSelect,
|
|
209
|
+
header,
|
|
217
210
|
}: {
|
|
218
211
|
term: string
|
|
219
212
|
selectedPeople: Map<string, DirectMessageCandidateResource>
|
|
220
213
|
onSelect: (candidate: DirectMessageCandidateResource) => void
|
|
214
|
+
header: ReactElement
|
|
221
215
|
}) {
|
|
222
216
|
const styles = useStyles()
|
|
223
217
|
const { data, isFetching } = useDirectMessageCandidates(term)
|
|
224
218
|
const { groups, teams, resultsDescription } = useDirectMessageAffiliations()
|
|
225
219
|
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
const unselectedCandidates = (data?.data ?? []).filter(c => !selectedPeople.has(c.id))
|
|
221
|
+
const hasTruncated = (data?.meta.totalCount ?? 0) > (data?.data.length ?? 0)
|
|
222
|
+
const isAtLimit = selectedPeople.size >= MAX_RECIPIENTS
|
|
223
|
+
const showsResults = term.length >= 1 && !isAtLimit && unselectedCandidates.length > 0
|
|
228
224
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
<Icon name="churchCenter.people" size={40} style={styles.emptyStateIcon} />
|
|
232
|
-
<Text style={styles.emptyStateTitle}>Search for people to direct message</Text>
|
|
233
|
-
<Text variant="secondary" style={styles.emptyStateSubtitle}>
|
|
234
|
-
Start a conversation with people in your groups and teams.
|
|
235
|
-
</Text>
|
|
236
|
-
</View>
|
|
237
|
-
)
|
|
238
|
-
}
|
|
225
|
+
const emptyState = (() => {
|
|
226
|
+
if (showsResults) return null
|
|
239
227
|
|
|
240
|
-
|
|
228
|
+
if (term.length < 1) {
|
|
229
|
+
if (selectedPeople.size > 0) return null
|
|
241
230
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
231
|
+
return (
|
|
232
|
+
<View style={styles.emptyState}>
|
|
233
|
+
<Icon name="churchCenter.people" size={40} style={styles.emptyStateIcon} />
|
|
234
|
+
<Text style={styles.emptyStateTitle}>Search for people to direct message</Text>
|
|
235
|
+
<Text variant="secondary" style={styles.emptyStateSubtitle}>
|
|
236
|
+
Start a conversation with people in your groups and teams.
|
|
237
|
+
</Text>
|
|
238
|
+
</View>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
251
241
|
|
|
252
|
-
|
|
253
|
-
|
|
242
|
+
if (isAtLimit) {
|
|
243
|
+
return (
|
|
244
|
+
<View style={styles.emptyState}>
|
|
245
|
+
<Text variant="secondary" style={styles.emptyStateSubtitle}>
|
|
246
|
+
You can add up to {MAX_RECIPIENTS} people to a direct message.
|
|
247
|
+
</Text>
|
|
248
|
+
</View>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
254
251
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
252
|
+
if (isFetching) {
|
|
253
|
+
return (
|
|
254
|
+
<View style={styles.emptyState}>
|
|
255
|
+
<Spinner />
|
|
256
|
+
</View>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
262
259
|
|
|
263
|
-
if (!isFetching && unselectedCandidates.length === 0) {
|
|
264
260
|
return (
|
|
265
261
|
<View style={styles.emptyState}>
|
|
266
262
|
<Icon name="general.search" size={32} style={styles.emptyStateIcon} />
|
|
@@ -270,13 +266,15 @@ function CandidateResults({
|
|
|
270
266
|
</Text>
|
|
271
267
|
</View>
|
|
272
268
|
)
|
|
273
|
-
}
|
|
269
|
+
})()
|
|
274
270
|
|
|
275
271
|
return (
|
|
276
272
|
<CandidateList
|
|
277
|
-
|
|
273
|
+
header={header}
|
|
274
|
+
candidates={showsResults ? unselectedCandidates : []}
|
|
278
275
|
hasTruncated={hasTruncated}
|
|
279
276
|
description={resultsDescription}
|
|
277
|
+
emptyState={emptyState}
|
|
280
278
|
groups={groups}
|
|
281
279
|
teams={teams}
|
|
282
280
|
onSelect={onSelect}
|
|
@@ -309,21 +307,26 @@ function candidateAffiliationNames(
|
|
|
309
307
|
}
|
|
310
308
|
|
|
311
309
|
function CandidateList({
|
|
310
|
+
header,
|
|
312
311
|
candidates,
|
|
313
312
|
hasTruncated,
|
|
314
313
|
description,
|
|
314
|
+
emptyState,
|
|
315
315
|
groups,
|
|
316
316
|
teams,
|
|
317
317
|
onSelect,
|
|
318
318
|
}: {
|
|
319
|
+
header: ReactElement
|
|
319
320
|
candidates: DirectMessageCandidateResource[]
|
|
320
321
|
hasTruncated: boolean
|
|
321
322
|
description: string | null
|
|
323
|
+
emptyState: ReactElement | null
|
|
322
324
|
groups: Map<number, string>
|
|
323
325
|
teams: Map<number, string>
|
|
324
326
|
onSelect: (candidate: DirectMessageCandidateResource) => void
|
|
325
327
|
}) {
|
|
326
328
|
const styles = useStyles()
|
|
329
|
+
const hasCandidates = candidates.length > 0
|
|
327
330
|
const available = candidates.filter(c => !c.directMessagesDisabled)
|
|
328
331
|
const dmDisabled = candidates.filter(c => c.directMessagesDisabled)
|
|
329
332
|
|
|
@@ -340,7 +343,13 @@ function CandidateList({
|
|
|
340
343
|
onSelect={() => onSelect(item)}
|
|
341
344
|
/>
|
|
342
345
|
)}
|
|
343
|
-
ListHeaderComponent={
|
|
346
|
+
ListHeaderComponent={
|
|
347
|
+
<>
|
|
348
|
+
{header}
|
|
349
|
+
{hasCandidates && <ResultsHeading description={description} />}
|
|
350
|
+
</>
|
|
351
|
+
}
|
|
352
|
+
ListEmptyComponent={emptyState}
|
|
344
353
|
ListFooterComponent={
|
|
345
354
|
<>
|
|
346
355
|
{dmDisabled.length > 0 && (
|
|
@@ -361,7 +370,7 @@ function CandidateList({
|
|
|
361
370
|
))}
|
|
362
371
|
</>
|
|
363
372
|
)}
|
|
364
|
-
{hasTruncated && (
|
|
373
|
+
{hasCandidates && hasTruncated && (
|
|
365
374
|
<View style={styles.truncatedFooter}>
|
|
366
375
|
<Text variant="secondary" style={styles.truncatedText}>
|
|
367
376
|
Keep typing to narrow your results.
|
package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx
CHANGED
|
@@ -23,7 +23,7 @@ const SECTION_CONFIG = {
|
|
|
23
23
|
},
|
|
24
24
|
[SectionKey.more]: {
|
|
25
25
|
title: 'More groups',
|
|
26
|
-
subtitle:
|
|
26
|
+
subtitle: "You can't start a new conversation in these groups",
|
|
27
27
|
ListItemComponent: RestrictedGroupRow,
|
|
28
28
|
},
|
|
29
29
|
}
|
|
@@ -106,12 +106,13 @@ describe('SearchScreen', () => {
|
|
|
106
106
|
fireEvent.changeText(input, ' budget ')
|
|
107
107
|
|
|
108
108
|
expect(view.getByText('Search chat')).toBeTruthy()
|
|
109
|
-
|
|
109
|
+
const searchedTerms = () =>
|
|
110
|
+
new Set(mockUseSearchResults.mock.calls.map(([term]) => term).filter(term => term.trim()))
|
|
111
|
+
expect([...searchedTerms()]).toEqual([])
|
|
110
112
|
|
|
111
113
|
act(() => jest.advanceTimersByTime(200))
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
expect([...searchedTerms]).toEqual(['budget'])
|
|
115
|
+
expect([...searchedTerms()]).toEqual(['budget'])
|
|
115
116
|
expect(view.queryByText('Search chat')).toBeNull()
|
|
116
117
|
expect(view.getByLabelText('Loading results')).toBeTruthy()
|
|
117
118
|
})
|
|
@@ -121,10 +122,7 @@ describe('SearchScreen', () => {
|
|
|
121
122
|
|
|
122
123
|
const scrollView = view.UNSAFE_getByType(ScrollView)
|
|
123
124
|
expect(scrollView.props.keyboardShouldPersistTaps).toBe('handled')
|
|
124
|
-
expect(scrollView.props.contentContainerStyle).toMatchObject({
|
|
125
|
-
flexGrow: 1,
|
|
126
|
-
justifyContent: 'center',
|
|
127
|
-
})
|
|
125
|
+
expect(scrollView.props.contentContainerStyle).toMatchObject({ flexGrow: 1 })
|
|
128
126
|
expect(view.getByText('Search chat')).toBeTruthy()
|
|
129
127
|
})
|
|
130
128
|
|
|
@@ -49,9 +49,13 @@ const messageResult = (id: string): MessageSearchResultResource => ({
|
|
|
49
49
|
},
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
+
const slots = { header: <></>, prompt: <></> }
|
|
53
|
+
|
|
52
54
|
const renderList = (state: Partial<SearchState>, onSettled = jest.fn()) => {
|
|
53
55
|
mockUseSearchResults.mockReturnValue(searchState(state))
|
|
54
|
-
const list = () =>
|
|
56
|
+
const list = () => (
|
|
57
|
+
<SearchResultsList term="potluck" onSelect={jest.fn()} onSettled={onSettled} {...slots} />
|
|
58
|
+
)
|
|
55
59
|
const view = render(list())
|
|
56
60
|
const rerenderWith = (next: Partial<SearchState>) => {
|
|
57
61
|
mockUseSearchResults.mockReturnValue(searchState(next))
|
|
@@ -130,7 +134,7 @@ describe('SearchResultsList', () => {
|
|
|
130
134
|
const results = [conversationResult('1'), messageResult('1'), messageResult('2')]
|
|
131
135
|
mockUseSearchResults.mockReturnValue(searchState({ results }))
|
|
132
136
|
const view = render(
|
|
133
|
-
<SearchResultsList term="potluck" onSelect={onSelect} onSettled={jest.fn()} />
|
|
137
|
+
<SearchResultsList term="potluck" onSelect={onSelect} onSettled={jest.fn()} {...slots} />
|
|
134
138
|
)
|
|
135
139
|
|
|
136
140
|
fireEvent.press(view.getByLabelText(/^Message 2/))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react'
|
|
1
|
+
import React, { ReactElement, useEffect, useRef } from 'react'
|
|
2
2
|
import { FlatList, StyleSheet, View } from 'react-native'
|
|
3
3
|
import { Banner, Spinner, Text, TextButton } from '../../../components'
|
|
4
4
|
import { useSearchResults } from '../../../hooks/use_search_results'
|
|
@@ -23,9 +23,17 @@ interface SearchResultsListProps {
|
|
|
23
23
|
term: string
|
|
24
24
|
onSelect: (result: SearchResultResource, position: number) => void
|
|
25
25
|
onSettled: (term: string, counts: SearchResultCounts) => void
|
|
26
|
+
header: ReactElement
|
|
27
|
+
prompt: ReactElement
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export function SearchResultsList({
|
|
30
|
+
export function SearchResultsList({
|
|
31
|
+
term,
|
|
32
|
+
onSelect,
|
|
33
|
+
onSettled,
|
|
34
|
+
header,
|
|
35
|
+
prompt,
|
|
36
|
+
}: SearchResultsListProps) {
|
|
29
37
|
const {
|
|
30
38
|
results,
|
|
31
39
|
failedTypes,
|
|
@@ -36,9 +44,10 @@ export function SearchResultsList({ term, onSelect, onSettled }: SearchResultsLi
|
|
|
36
44
|
hasNextPage,
|
|
37
45
|
isFetchingNextPage,
|
|
38
46
|
} = useSearchResults(term)
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
47
|
+
const searching = term.trim().length > 0
|
|
48
|
+
const conversationResults = searching ? results.filter(isConversationResult) : []
|
|
49
|
+
const messageResults = searching ? results.filter(isMessageResult) : []
|
|
50
|
+
const settled = searching && !isPending && !isError
|
|
42
51
|
|
|
43
52
|
const settledTermRef = useRef<string | undefined>(undefined)
|
|
44
53
|
|
|
@@ -64,20 +73,27 @@ export function SearchResultsList({ term, onSelect, onSettled }: SearchResultsLi
|
|
|
64
73
|
)}
|
|
65
74
|
ListHeaderComponent={
|
|
66
75
|
<>
|
|
76
|
+
{header}
|
|
67
77
|
{conversationResults.length > 0 && (
|
|
68
78
|
<ConversationResults results={conversationResults} onSelect={onSelect} />
|
|
69
79
|
)}
|
|
70
|
-
{failedTypes.includes('conversation') &&
|
|
80
|
+
{searching && failedTypes.includes('conversation') && (
|
|
81
|
+
<SectionFailure type="conversation" />
|
|
82
|
+
)}
|
|
71
83
|
{messageResults.length > 0 && <ResultsSection title="Messages" />}
|
|
72
84
|
</>
|
|
73
85
|
}
|
|
74
86
|
ListEmptyComponent={
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
searching ? (
|
|
88
|
+
<ListEmpty
|
|
89
|
+
term={term}
|
|
90
|
+
isError={isError}
|
|
91
|
+
isPending={isPending}
|
|
92
|
+
noResults={results.length === 0 && failedTypes.length === 0}
|
|
93
|
+
/>
|
|
94
|
+
) : (
|
|
95
|
+
<View style={styles.prompt}>{prompt}</View>
|
|
96
|
+
)
|
|
81
97
|
}
|
|
82
98
|
ListFooterComponent={
|
|
83
99
|
<>
|
|
@@ -91,7 +107,7 @@ export function SearchResultsList({ term, onSelect, onSettled }: SearchResultsLi
|
|
|
91
107
|
Try again
|
|
92
108
|
</TextButton>
|
|
93
109
|
)}
|
|
94
|
-
{failedTypes.includes('message') && <SectionFailure type="message" />}
|
|
110
|
+
{searching && failedTypes.includes('message') && <SectionFailure type="message" />}
|
|
95
111
|
</>
|
|
96
112
|
}
|
|
97
113
|
onEndReached={() => {
|
|
@@ -149,6 +165,10 @@ const styles = StyleSheet.create({
|
|
|
149
165
|
content: {
|
|
150
166
|
flexGrow: 1,
|
|
151
167
|
},
|
|
168
|
+
prompt: {
|
|
169
|
+
flexGrow: 1,
|
|
170
|
+
justifyContent: 'center',
|
|
171
|
+
},
|
|
152
172
|
banner: {
|
|
153
173
|
margin: 16,
|
|
154
174
|
},
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
NativeStackScreenProps,
|
|
5
5
|
} from '@react-navigation/native-stack'
|
|
6
6
|
import React, { useRef, useState } from 'react'
|
|
7
|
-
import { Keyboard,
|
|
7
|
+
import { Keyboard, StyleSheet, View } from 'react-native'
|
|
8
8
|
import { KeyboardView } from '../../components'
|
|
9
9
|
import {
|
|
10
10
|
composeOptions,
|
|
@@ -64,19 +64,13 @@ export function SearchScreen() {
|
|
|
64
64
|
return (
|
|
65
65
|
<KeyboardView>
|
|
66
66
|
<View style={styles.container} testID="search-screen">
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/>
|
|
75
|
-
) : (
|
|
76
|
-
<ScrollView contentContainerStyle={styles.prompt} keyboardShouldPersistTaps="handled">
|
|
77
|
-
<SearchPromptBlankState />
|
|
78
|
-
</ScrollView>
|
|
79
|
-
)}
|
|
67
|
+
<SearchResultsList
|
|
68
|
+
term={debouncedTerm}
|
|
69
|
+
onSelect={openResult}
|
|
70
|
+
onSettled={publishSearch}
|
|
71
|
+
header={<SearchField term={term} onChange={setTerm} />}
|
|
72
|
+
prompt={<SearchPromptBlankState />}
|
|
73
|
+
/>
|
|
80
74
|
</View>
|
|
81
75
|
</KeyboardView>
|
|
82
76
|
)
|
|
@@ -86,8 +80,4 @@ const styles = StyleSheet.create({
|
|
|
86
80
|
container: {
|
|
87
81
|
flex: 1,
|
|
88
82
|
},
|
|
89
|
-
prompt: {
|
|
90
|
-
flexGrow: 1,
|
|
91
|
-
justifyContent: 'center',
|
|
92
|
-
},
|
|
93
83
|
})
|