@planningcenter/chat-react-native 4.2.1-qa-staging.12 → 4.2.1-qa-staging.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
  2. package/build/components/conversation/attachments/giphy_attachment.js +2 -2
  3. package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
  4. package/build/components/conversation/message_form.d.ts.map +1 -1
  5. package/build/components/conversation/message_form.js +2 -2
  6. package/build/components/conversation/message_form.js.map +1 -1
  7. package/build/components/display/conversation_avatar.d.ts +1 -2
  8. package/build/components/display/conversation_avatar.d.ts.map +1 -1
  9. package/build/components/display/conversation_avatar.js.map +1 -1
  10. package/build/navigation/index.d.ts +5 -0
  11. package/build/navigation/index.d.ts.map +1 -1
  12. package/build/navigation/index.js +5 -0
  13. package/build/navigation/index.js.map +1 -1
  14. package/build/screens/age_check/age_check_underage_screen.d.ts.map +1 -1
  15. package/build/screens/age_check/age_check_underage_screen.js +3 -2
  16. package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
  17. package/build/screens/bug_report_screen.d.ts.map +1 -1
  18. package/build/screens/bug_report_screen.js +2 -2
  19. package/build/screens/bug_report_screen.js.map +1 -1
  20. package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
  21. package/build/screens/conversations/components/search_list_header_component.js +159 -133
  22. package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
  23. package/build/screens/get_help_screen.js +4 -4
  24. package/build/screens/get_help_screen.js.map +1 -1
  25. package/build/screens/search/components/search_field.d.ts +7 -0
  26. package/build/screens/search/components/search_field.d.ts.map +1 -0
  27. package/build/screens/search/components/search_field.js +152 -0
  28. package/build/screens/search/components/search_field.js.map +1 -0
  29. package/build/screens/search/search_screen.d.ts +5 -0
  30. package/build/screens/search/search_screen.d.ts.map +1 -0
  31. package/build/screens/search/search_screen.js +43 -0
  32. package/build/screens/search/search_screen.js.map +1 -0
  33. package/build/types/resources/conversation.d.ts +1 -0
  34. package/build/types/resources/conversation.d.ts.map +1 -1
  35. package/build/types/resources/conversation.js.map +1 -1
  36. package/build/types/resources/index.d.ts +1 -0
  37. package/build/types/resources/index.d.ts.map +1 -1
  38. package/build/types/resources/index.js +1 -0
  39. package/build/types/resources/index.js.map +1 -1
  40. package/build/types/resources/search_result.d.ts +29 -0
  41. package/build/types/resources/search_result.d.ts.map +1 -0
  42. package/build/types/resources/search_result.js +2 -0
  43. package/build/types/resources/search_result.js.map +1 -0
  44. package/build/utils/request/get_search_results.d.ts +13 -0
  45. package/build/utils/request/get_search_results.d.ts.map +1 -0
  46. package/build/utils/request/get_search_results.js +20 -0
  47. package/build/utils/request/get_search_results.js.map +1 -0
  48. package/package.json +3 -3
  49. package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
  50. package/src/__tests__/screens/get_help_screen.test.ts +40 -0
  51. package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
  52. package/src/components/conversation/message_form.tsx +1 -1
  53. package/src/components/display/conversation_avatar.tsx +1 -10
  54. package/src/navigation/index.tsx +5 -0
  55. package/src/screens/age_check/age_check_underage_screen.tsx +3 -2
  56. package/src/screens/bug_report_screen.tsx +2 -10
  57. package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +62 -0
  58. package/src/screens/conversations/components/search_list_header_component.tsx +11 -0
  59. package/src/screens/get_help_screen.tsx +4 -4
  60. package/src/screens/search/components/__tests__/search_field.test.tsx +29 -0
  61. package/src/screens/search/components/search_field.tsx +81 -0
  62. package/src/screens/search/search_screen.tsx +39 -0
  63. package/src/types/resources/conversation.ts +9 -0
  64. package/src/types/resources/index.ts +1 -0
  65. package/src/types/resources/search_result.ts +32 -0
  66. package/src/utils/__tests__/get_search_results.test.ts +24 -0
  67. package/src/utils/request/get_search_results.ts +23 -0
@@ -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,
@@ -1,21 +1,12 @@
1
1
  import React from 'react'
2
2
  import type { ViewStyle } from 'react-native'
3
- import type { ConversationResource } from '../../types'
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 }
@@ -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
- Linking.openURL(`mailto:${email}`)
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
 
@@ -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
- Linking.openURL(url).catch(() => {
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
- Linking.openURL(url).catch(() => {
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' },
@@ -0,0 +1,29 @@
1
+ import { fireEvent, render } from '@testing-library/react-native'
2
+ import React from 'react'
3
+ import { SearchField } from '../search_field'
4
+
5
+ const inputLabel = 'Search titles and messages'
6
+ const clearLabel = 'Clear search'
7
+
8
+ describe('SearchField', () => {
9
+ it('reports typed text through onChange', () => {
10
+ const onChange = jest.fn()
11
+ const view = render(<SearchField term="" onChange={onChange} />)
12
+
13
+ fireEvent.changeText(view.getByLabelText(inputLabel), 'budget')
14
+
15
+ expect(onChange).toHaveBeenCalledWith('budget')
16
+ })
17
+
18
+ it('shows the clear button only for a non-empty term and clears on press', () => {
19
+ const onChange = jest.fn()
20
+ const view = render(<SearchField term="" onChange={onChange} />)
21
+
22
+ expect(view.queryByLabelText(clearLabel)).toBeNull()
23
+
24
+ view.rerender(<SearchField term="budget" onChange={onChange} />)
25
+ fireEvent.press(view.getByLabelText(clearLabel))
26
+
27
+ expect(onChange).toHaveBeenCalledWith('')
28
+ })
29
+ })
@@ -0,0 +1,81 @@
1
+ import { useRef } from 'react'
2
+ import { Pressable, StyleSheet, TextInput, View } from 'react-native'
3
+ import { Icon } from '../../../components'
4
+ import { AutoFocusAwareTextInput } from '../../../components/display/text_input'
5
+ import { useTheme } from '../../../hooks'
6
+
7
+ const PLACEHOLDER = 'Search titles and messages'
8
+
9
+ interface SearchFieldProps {
10
+ term: string
11
+ onChange: (term: string) => void
12
+ }
13
+
14
+ export function SearchField({ term, onChange }: SearchFieldProps) {
15
+ const styles = useStyles()
16
+ const { colors } = useTheme()
17
+ const inputRef = useRef<TextInput>(null)
18
+
19
+ const clear = () => {
20
+ onChange('')
21
+ inputRef.current?.clear()
22
+ inputRef.current?.focus()
23
+ }
24
+
25
+ return (
26
+ <View style={styles.container}>
27
+ <View style={styles.field}>
28
+ <Icon name="general.search" size={16} color={colors.iconColorDefaultSecondary} />
29
+ <AutoFocusAwareTextInput
30
+ autoFocus
31
+ autoCorrect={false}
32
+ inputRef={inputRef}
33
+ placeholder={PLACEHOLDER}
34
+ placeholderTextColor={colors.textColorDefaultPlaceholder}
35
+ accessibilityLabel={PLACEHOLDER}
36
+ value={term}
37
+ onChangeText={onChange}
38
+ returnKeyType="search"
39
+ style={styles.input}
40
+ />
41
+ {term.length > 0 && (
42
+ <Pressable
43
+ onPress={clear}
44
+ hitSlop={8}
45
+ accessibilityRole="button"
46
+ accessibilityLabel="Clear search"
47
+ >
48
+ <Icon name="general.x" size={12} color={colors.iconColorDefaultSecondary} />
49
+ </Pressable>
50
+ )}
51
+ </View>
52
+ </View>
53
+ )
54
+ }
55
+
56
+ const useStyles = () => {
57
+ const { colors } = useTheme()
58
+
59
+ return StyleSheet.create({
60
+ container: {
61
+ paddingHorizontal: 16,
62
+ paddingVertical: 8,
63
+ },
64
+ field: {
65
+ flexDirection: 'row',
66
+ alignItems: 'center',
67
+ gap: 8,
68
+ borderWidth: 1,
69
+ borderColor: colors.borderColorDefaultBase,
70
+ borderRadius: 8,
71
+ paddingHorizontal: 12,
72
+ paddingVertical: 8,
73
+ },
74
+ input: {
75
+ flex: 1,
76
+ color: colors.textColorDefaultPrimary,
77
+ fontSize: 16,
78
+ paddingVertical: 2,
79
+ },
80
+ })
81
+ }
@@ -0,0 +1,39 @@
1
+ import { ParamListBase } from '@react-navigation/native'
2
+ import {
3
+ NativeStackNavigationOptions,
4
+ NativeStackScreenProps,
5
+ } from '@react-navigation/native-stack'
6
+ import React, { useState } from 'react'
7
+ import { StyleSheet, View } from 'react-native'
8
+ import { KeyboardView } from '../../components'
9
+ import {
10
+ composeOptions,
11
+ withMinimalBack,
12
+ } from '../../components/display/platform_modal_header_buttons'
13
+ import { SearchField } from './components/search_field'
14
+
15
+ export const SearchScreenOptions = ({
16
+ navigation,
17
+ }: NativeStackScreenProps<ParamListBase>): NativeStackNavigationOptions =>
18
+ composeOptions(
19
+ { title: 'Search', animation: 'fade' },
20
+ withMinimalBack({ onPress: () => navigation.goBack() })
21
+ )
22
+
23
+ export function SearchScreen() {
24
+ const [term, setTerm] = useState('')
25
+
26
+ return (
27
+ <KeyboardView>
28
+ <View style={styles.container} testID="search-screen">
29
+ <SearchField term={term} onChange={setTerm} />
30
+ </View>
31
+ </KeyboardView>
32
+ )
33
+ }
34
+
35
+ const styles = StyleSheet.create({
36
+ container: {
37
+ flex: 1,
38
+ },
39
+ })
@@ -46,3 +46,12 @@ export interface ConversationResource {
46
46
  unreadReaction: boolean
47
47
  updatedAt: string
48
48
  }
49
+
50
+ export type ConversationAvatarData = Pick<
51
+ ConversationResource,
52
+ | 'customAvatarType'
53
+ | 'customAvatarKey'
54
+ | 'customAvatarColor'
55
+ | 'customAvatarImageUrl'
56
+ | 'previewAvatarUrls'
57
+ >
@@ -14,3 +14,4 @@ export * from './services'
14
14
  export * from './organization'
15
15
  export * from './group_membership'
16
16
  export * from './group_resource'
17
+ export * from './search_result'
@@ -0,0 +1,32 @@
1
+ import type { ConversationAvatarData } from './conversation'
2
+
3
+ interface BaseSearchResultResource {
4
+ id: string
5
+ title: string
6
+ url: string
7
+ }
8
+
9
+ export interface SnippetSegment {
10
+ text: string
11
+ match: boolean
12
+ }
13
+
14
+ export interface ConversationSearchResultResource extends BaseSearchResultResource {
15
+ type: 'conversation'
16
+ extra: {
17
+ avatar: ConversationAvatarData
18
+ }
19
+ }
20
+
21
+ export interface MessageSearchResultResource extends BaseSearchResultResource {
22
+ type: 'message'
23
+ extra: {
24
+ conversationId: number
25
+ authorName: string
26
+ snippet: SnippetSegment[]
27
+ createdAt: string
28
+ avatar: ConversationAvatarData
29
+ }
30
+ }
31
+
32
+ export type SearchResultResource = ConversationSearchResultResource | MessageSearchResultResource
@@ -0,0 +1,24 @@
1
+ import {
2
+ getSearchResultsQueryKey,
3
+ getSearchResultsRequestArgs,
4
+ } from '../request/get_search_results'
5
+
6
+ describe('getSearchResultsRequestArgs', () => {
7
+ it('requests the first page of search results for the term', () => {
8
+ expect(getSearchResultsRequestArgs('potluck')).toEqual({
9
+ url: '/search_results',
10
+ data: {
11
+ q: 'potluck',
12
+ perPage: 20,
13
+ fields: { SearchResult: ['type', 'title', 'url', 'extra'] },
14
+ },
15
+ })
16
+ })
17
+ })
18
+
19
+ describe('getSearchResultsQueryKey', () => {
20
+ it('changes with the term', () => {
21
+ expect(getSearchResultsQueryKey('potluck')).not.toEqual(getSearchResultsQueryKey('picnic'))
22
+ expect(getSearchResultsQueryKey('potluck')).toEqual(getSearchResultsQueryKey('potluck'))
23
+ })
24
+ })
@@ -0,0 +1,23 @@
1
+ import { getRequestQueryKey } from '../../hooks/use_suspense_api'
2
+
3
+ export const SEARCH_RESULTS_PAGE_SIZE = 20
4
+
5
+ export const getSearchResultsRequestArgs = (term: string) => {
6
+ const url = '/search_results'
7
+
8
+ return {
9
+ url,
10
+ data: {
11
+ q: term,
12
+ perPage: SEARCH_RESULTS_PAGE_SIZE,
13
+ fields: {
14
+ SearchResult: ['type', 'title', 'url', 'extra'],
15
+ },
16
+ },
17
+ }
18
+ }
19
+
20
+ export const getSearchResultsQueryKey = (term: string) => {
21
+ const requestArgs = getSearchResultsRequestArgs(term)
22
+ return getRequestQueryKey(requestArgs)
23
+ }