@planningcenter/chat-react-native 4.3.0-rc.1 → 4.3.0-rc.11
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/message_form.d.ts +2 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +167 -370
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts +5 -2
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +187 -67
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/missing_message.d.ts +2 -0
- package/build/components/conversation/missing_message.d.ts.map +1 -0
- package/build/components/conversation/missing_message.js +139 -0
- package/build/components/conversation/missing_message.js.map +1 -0
- 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/groups/use_group_members_for_new_conversation.d.ts +4 -3
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +14 -5
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +218 -42
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +58 -42
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_features.d.ts +2 -1
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +2 -1
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts +2 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +4 -3
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_read_receipts.d.ts +4 -3
- package/build/hooks/use_read_receipts.d.ts.map +1 -1
- 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 +145 -0
- package/build/hooks/use_search_results.js.map +1 -0
- package/build/hooks/use_suspense_api.d.ts +10 -6
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +83 -63
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_screen.d.ts +1 -0
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +305 -203
- package/build/screens/conversation_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/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/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +103 -92
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
- package/build/screens/notification_settings/hooks/groups.d.ts.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/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 +59 -0
- package/build/screens/search/search_screen.js.map +1 -0
- package/build/types/api_primitives.d.ts +1 -0
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- 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/cache/messages_cache.d.ts +1 -0
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +37 -1
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/cache/messages_window.d.ts +11 -0
- package/build/utils/cache/messages_window.d.ts.map +1 -0
- package/build/utils/cache/messages_window.js +51 -0
- package/build/utils/cache/messages_window.js.map +1 -0
- package/build/utils/client/types.d.ts +1 -0
- package/build/utils/client/types.d.ts.map +1 -1
- package/build/utils/client/types.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 +2 -2
- package/src/__tests__/hooks/use_features.test.ts +10 -2
- package/src/__utils__/query_client.ts +3 -0
- package/src/components/conversation/message_form.tsx +31 -3
- package/src/components/conversation/message_list.tsx +88 -4
- package/src/components/conversation/missing_message.tsx +66 -0
- package/src/components/display/conversation_avatar.tsx +1 -10
- package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
- package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
- package/src/hooks/__tests__/use_message_create_or_update.test.tsx +2 -7
- package/src/hooks/__tests__/use_search_results.test.tsx +76 -0
- package/src/hooks/use_conversation_messages.ts +103 -17
- package/src/hooks/use_conversation_messages_jolt_events.ts +12 -2
- package/src/hooks/use_features.ts +3 -2
- package/src/hooks/use_mark_latest_message_read.ts +4 -3
- package/src/hooks/use_search_results.ts +77 -0
- package/src/hooks/use_suspense_api.ts +14 -6
- package/src/navigation/index.tsx +5 -0
- package/src/screens/conversation_screen.tsx +62 -13
- package/src/screens/conversation_select_recipients/components/view_more_link_row.tsx +12 -3
- 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/message_actions_screen.tsx +12 -1
- 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/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/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +41 -0
- package/src/types/api_primitives.ts +1 -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/cache/__tests__/messages_cache.test.ts +2 -1
- package/src/utils/cache/__tests__/messages_cache_deletion.test.ts +97 -0
- package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +3 -2
- package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
- package/src/utils/cache/messages_cache.ts +45 -1
- package/src/utils/cache/messages_window.ts +55 -0
- package/src/utils/client/types.ts +1 -0
- package/src/utils/request/get_search_results.ts +23 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import type { MessageSearchResultResource } from '../../../../types/resources/search_result'
|
|
4
|
+
import { formatDatePreview } from '../../../../utils/date'
|
|
5
|
+
import { defaultTheme } from '../../../../utils/theme'
|
|
6
|
+
import { MessageResultRow } from '../message_result_row'
|
|
7
|
+
|
|
8
|
+
const result: MessageSearchResultResource = {
|
|
9
|
+
id: '42',
|
|
10
|
+
type: 'message',
|
|
11
|
+
title: 'Worship Team',
|
|
12
|
+
url: '/conversations/7?message_id=42',
|
|
13
|
+
extra: {
|
|
14
|
+
conversationId: 7,
|
|
15
|
+
authorName: 'Ada Lovelace',
|
|
16
|
+
snippet: [
|
|
17
|
+
{ text: '…planning the ', match: false },
|
|
18
|
+
{ text: 'budget', match: true },
|
|
19
|
+
{ text: ' meeting for next week', match: false },
|
|
20
|
+
],
|
|
21
|
+
createdAt: '2026-03-04T15:30:00Z',
|
|
22
|
+
avatar: {
|
|
23
|
+
customAvatarType: null,
|
|
24
|
+
customAvatarKey: null,
|
|
25
|
+
customAvatarColor: null,
|
|
26
|
+
customAvatarImageUrl: null,
|
|
27
|
+
previewAvatarUrls: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const interactionColor = defaultTheme('light').colors.interaction
|
|
33
|
+
|
|
34
|
+
describe('MessageResultRow', () => {
|
|
35
|
+
it('renders the title, author, snippet, and date', () => {
|
|
36
|
+
const view = render(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
37
|
+
|
|
38
|
+
expect(view.getByText('Worship Team')).toBeTruthy()
|
|
39
|
+
expect(view.getByText('Ada Lovelace:', { exact: false })).toBeTruthy()
|
|
40
|
+
expect(view.getByText('…planning the ')).toBeTruthy()
|
|
41
|
+
expect(view.getByText('budget')).toBeTruthy()
|
|
42
|
+
expect(view.getByText(' meeting for next week')).toBeTruthy()
|
|
43
|
+
expect(view.getByText(formatDatePreview(result.extra.createdAt))).toBeTruthy()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('colors matched segments with the interaction color', () => {
|
|
47
|
+
const view = render(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
48
|
+
|
|
49
|
+
expect(view.getByText('budget')).toHaveStyle({ color: interactionColor })
|
|
50
|
+
expect(view.getByText('…planning the ')).not.toHaveStyle({ color: interactionColor })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('exposes the row as a button with a composed label and reports presses', () => {
|
|
54
|
+
const onPress = jest.fn()
|
|
55
|
+
const date = formatDatePreview(result.extra.createdAt)
|
|
56
|
+
const view = render(<MessageResultRow result={result} onPress={onPress} />)
|
|
57
|
+
|
|
58
|
+
const row = view.getByRole('button', {
|
|
59
|
+
name: `Worship Team, Ada Lovelace: …planning the budget meeting for next week, ${date}`,
|
|
60
|
+
})
|
|
61
|
+
fireEvent.press(row)
|
|
62
|
+
|
|
63
|
+
expect(onPress).toHaveBeenCalledWith(result)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { Text } from 'react-native'
|
|
4
|
+
import { useAtFontScaleBreakpoint } from '../../../../hooks/use_at_font_scale_breakpoint'
|
|
5
|
+
import { ResultRow } from '../result_row'
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../../hooks/use_at_font_scale_breakpoint')
|
|
8
|
+
|
|
9
|
+
const mockUseAtFontScaleBreakpoint = jest.mocked(useAtFontScaleBreakpoint)
|
|
10
|
+
|
|
11
|
+
describe('ResultRow', () => {
|
|
12
|
+
it('lays children out in a row below the font scale breakpoint', () => {
|
|
13
|
+
mockUseAtFontScaleBreakpoint.mockReturnValue(false)
|
|
14
|
+
const view = render(
|
|
15
|
+
<ResultRow accessibilityLabel="Row" onPress={jest.fn()} alignItems="center">
|
|
16
|
+
<Text>child</Text>
|
|
17
|
+
</ResultRow>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
expect(view.getByRole('button')).toHaveStyle({ flexDirection: 'row', alignItems: 'center' })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('stacks children at the font scale breakpoint', () => {
|
|
24
|
+
mockUseAtFontScaleBreakpoint.mockReturnValue(true)
|
|
25
|
+
const view = render(
|
|
26
|
+
<ResultRow accessibilityLabel="Row" onPress={jest.fn()} alignItems="center">
|
|
27
|
+
<Text>child</Text>
|
|
28
|
+
</ResultRow>
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
expect(view.getByRole('button')).toHaveStyle({ flexDirection: 'column', alignItems: 'stretch' })
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { NoResultsBlankState, SearchPromptBlankState } from '../search_blank_states'
|
|
4
|
+
|
|
5
|
+
describe('SearchPromptBlankState', () => {
|
|
6
|
+
it('renders the prompt heading', () => {
|
|
7
|
+
const view = render(<SearchPromptBlankState />)
|
|
8
|
+
|
|
9
|
+
expect(view.getByText('Search chat')).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('NoResultsBlankState', () => {
|
|
14
|
+
it('renders the heading and the searched term', () => {
|
|
15
|
+
const view = render(<NoResultsBlankState term="budget" />)
|
|
16
|
+
|
|
17
|
+
expect(view.getByText('No results')).toBeTruthy()
|
|
18
|
+
expect(view.getByText(/Nothing matches “budget\.”/)).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -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,36 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native'
|
|
2
|
+
import { ConversationAvatar, Heading } from '../../../components'
|
|
3
|
+
import { useScalableNumberOfLines, useTheme } from '../../../hooks'
|
|
4
|
+
import type { ConversationSearchResultResource } from '../../../types'
|
|
5
|
+
import { ResultRow } from './result_row'
|
|
6
|
+
|
|
7
|
+
interface ConversationResultRowProps {
|
|
8
|
+
result: ConversationSearchResultResource
|
|
9
|
+
onPress: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ConversationResultRow({ result, onPress }: ConversationResultRowProps) {
|
|
13
|
+
const styles = useStyles()
|
|
14
|
+
const numberOfLines = useScalableNumberOfLines(1)
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<ResultRow accessibilityLabel={result.title} onPress={onPress} alignItems="center">
|
|
18
|
+
<ConversationAvatar conversation={result.extra.avatar} size="lg" />
|
|
19
|
+
<Heading variant="h3" numberOfLines={numberOfLines} style={styles.title}>
|
|
20
|
+
{result.title}
|
|
21
|
+
</Heading>
|
|
22
|
+
</ResultRow>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const useStyles = () => {
|
|
27
|
+
const { colors } = useTheme()
|
|
28
|
+
|
|
29
|
+
return StyleSheet.create({
|
|
30
|
+
title: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
fontSize: 16,
|
|
33
|
+
color: colors.textColorDefaultPrimary,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import type { ConversationSearchResultResource } from '../../../types'
|
|
3
|
+
import { ViewMoreLinkRow } from '../../conversation_select_recipients/components/view_more_link_row'
|
|
4
|
+
import { ConversationResultRow } from './conversation_result_row'
|
|
5
|
+
import { ResultsSection } from './results_section'
|
|
6
|
+
|
|
7
|
+
const COLLAPSED_COUNT = 5
|
|
8
|
+
|
|
9
|
+
interface ConversationResultsProps {
|
|
10
|
+
results: ConversationSearchResultResource[]
|
|
11
|
+
onSelect: (result: ConversationSearchResultResource) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ConversationResults({ results, onSelect }: ConversationResultsProps) {
|
|
15
|
+
const [expanded, setExpanded] = useState(false)
|
|
16
|
+
const visible = expanded ? results : results.slice(0, COLLAPSED_COUNT)
|
|
17
|
+
|
|
18
|
+
if (results.length === 0) return null
|
|
19
|
+
|
|
20
|
+
const footer = results.length > COLLAPSED_COUNT && (
|
|
21
|
+
<ViewMoreLinkRow
|
|
22
|
+
expanded={expanded}
|
|
23
|
+
onPress={() => setExpanded(!expanded)}
|
|
24
|
+
accessibilityHint={
|
|
25
|
+
expanded
|
|
26
|
+
? `Shows the first ${COLLAPSED_COUNT} conversation results`
|
|
27
|
+
: `Shows all ${results.length} conversation results`
|
|
28
|
+
}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ResultsSection title="Conversations" footer={footer}>
|
|
34
|
+
{visible.map(result => (
|
|
35
|
+
<ConversationResultRow key={result.id} result={result} onPress={() => onSelect(result)} />
|
|
36
|
+
))}
|
|
37
|
+
</ResultsSection>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleSheet, View } from 'react-native'
|
|
3
|
+
import { ConversationAvatar, Text } from '../../../components/display'
|
|
4
|
+
import { useScalableNumberOfLines } from '../../../hooks'
|
|
5
|
+
import type { MessageSearchResultResource } from '../../../types/resources/search_result'
|
|
6
|
+
import { platformFontWeightMedium } from '../../../utils'
|
|
7
|
+
import { formatDatePreview } from '../../../utils/date'
|
|
8
|
+
import { ResultRow } from './result_row'
|
|
9
|
+
import { plainSnippetText, Snippet } from './snippet'
|
|
10
|
+
|
|
11
|
+
interface MessageResultRowProps {
|
|
12
|
+
result: MessageSearchResultResource
|
|
13
|
+
onPress: (result: MessageSearchResultResource) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function MessageResultRow({ result, onPress }: MessageResultRowProps) {
|
|
17
|
+
const { authorName, avatar, snippet, createdAt } = result.extra
|
|
18
|
+
const titleNumberOfLines = useScalableNumberOfLines(1)
|
|
19
|
+
const previewNumberOfLines = useScalableNumberOfLines(2)
|
|
20
|
+
const date = formatDatePreview(createdAt)
|
|
21
|
+
const accessibilityLabel = `${result.title}, ${authorName}: ${plainSnippetText(snippet)}, ${date}`
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ResultRow accessibilityLabel={accessibilityLabel} onPress={() => onPress(result)}>
|
|
25
|
+
<ConversationAvatar conversation={avatar} size="lg" />
|
|
26
|
+
<View style={styles.body}>
|
|
27
|
+
<Text numberOfLines={titleNumberOfLines} style={styles.title}>
|
|
28
|
+
{result.title}
|
|
29
|
+
</Text>
|
|
30
|
+
<Text variant="tertiary" numberOfLines={previewNumberOfLines}>
|
|
31
|
+
{authorName}: <Snippet segments={snippet} />
|
|
32
|
+
</Text>
|
|
33
|
+
</View>
|
|
34
|
+
<Text variant="footnote">{date}</Text>
|
|
35
|
+
</ResultRow>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
body: {
|
|
41
|
+
flex: 1,
|
|
42
|
+
rowGap: 2,
|
|
43
|
+
},
|
|
44
|
+
title: {
|
|
45
|
+
fontSize: 16,
|
|
46
|
+
fontWeight: platformFontWeightMedium,
|
|
47
|
+
},
|
|
48
|
+
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react'
|
|
2
|
+
import { Pressable, StyleSheet } from 'react-native'
|
|
3
|
+
import { useAtFontScaleBreakpoint, useTheme } from '../../../hooks'
|
|
4
|
+
import { platformPressedOpacityStyle } from '../../../utils'
|
|
5
|
+
|
|
6
|
+
interface ResultRowProps {
|
|
7
|
+
accessibilityLabel: string
|
|
8
|
+
onPress: () => void
|
|
9
|
+
alignItems?: 'flex-start' | 'center'
|
|
10
|
+
children: ReactNode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ResultRow({
|
|
14
|
+
accessibilityLabel,
|
|
15
|
+
onPress,
|
|
16
|
+
alignItems = 'flex-start',
|
|
17
|
+
children,
|
|
18
|
+
}: ResultRowProps) {
|
|
19
|
+
const { colors } = useTheme()
|
|
20
|
+
const atFontScaleBreakpoint = useAtFontScaleBreakpoint()
|
|
21
|
+
const styles = useStyles()
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Pressable
|
|
25
|
+
accessibilityRole="button"
|
|
26
|
+
accessibilityLabel={accessibilityLabel}
|
|
27
|
+
onPress={onPress}
|
|
28
|
+
style={({ pressed }) => [
|
|
29
|
+
styles.row,
|
|
30
|
+
atFontScaleBreakpoint ? styles.stacked : { alignItems },
|
|
31
|
+
pressed && platformPressedOpacityStyle,
|
|
32
|
+
]}
|
|
33
|
+
android_ripple={{ color: colors.androidRippleNeutral, borderless: false, foreground: true }}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</Pressable>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const useStyles = () => {
|
|
41
|
+
const { colors } = useTheme()
|
|
42
|
+
|
|
43
|
+
return StyleSheet.create({
|
|
44
|
+
row: {
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
gap: 8,
|
|
47
|
+
paddingVertical: 12,
|
|
48
|
+
paddingHorizontal: 16,
|
|
49
|
+
borderBottomWidth: 1,
|
|
50
|
+
borderBottomColor: colors.borderColorDefaultDim,
|
|
51
|
+
},
|
|
52
|
+
stacked: {
|
|
53
|
+
flexDirection: 'column',
|
|
54
|
+
alignItems: 'stretch',
|
|
55
|
+
borderBottomColor: colors.borderColorDefaultDark,
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { StyleSheet, View } from 'react-native'
|
|
3
|
+
import { Text } from '../../../components'
|
|
4
|
+
|
|
5
|
+
interface ResultsSectionProps {
|
|
6
|
+
title: string
|
|
7
|
+
footer?: ReactNode
|
|
8
|
+
children: ReactNode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ResultsSection({ title, footer, children }: ResultsSectionProps) {
|
|
12
|
+
return (
|
|
13
|
+
<View>
|
|
14
|
+
<View style={styles.headingRow}>
|
|
15
|
+
<Text accessibilityRole="header" style={styles.heading}>
|
|
16
|
+
{title}
|
|
17
|
+
</Text>
|
|
18
|
+
</View>
|
|
19
|
+
{children}
|
|
20
|
+
{footer}
|
|
21
|
+
</View>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const styles = StyleSheet.create({
|
|
26
|
+
headingRow: {
|
|
27
|
+
paddingHorizontal: 16,
|
|
28
|
+
paddingTop: 16,
|
|
29
|
+
paddingBottom: 8,
|
|
30
|
+
},
|
|
31
|
+
heading: {
|
|
32
|
+
fontWeight: '600',
|
|
33
|
+
},
|
|
34
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import BlankState from '../../../components/primitive/blank_state_primitive'
|
|
3
|
+
|
|
4
|
+
export function SearchPromptBlankState() {
|
|
5
|
+
return (
|
|
6
|
+
<BlankState.Root>
|
|
7
|
+
<BlankState.Imagery name="general.search" />
|
|
8
|
+
<BlankState.Content>
|
|
9
|
+
<BlankState.Heading>Search chat</BlankState.Heading>
|
|
10
|
+
<BlankState.Text>
|
|
11
|
+
Find conversations by title, or search for words from a message.
|
|
12
|
+
</BlankState.Text>
|
|
13
|
+
</BlankState.Content>
|
|
14
|
+
</BlankState.Root>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface NoResultsBlankStateProps {
|
|
19
|
+
term: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function NoResultsBlankState({ term }: NoResultsBlankStateProps) {
|
|
23
|
+
return (
|
|
24
|
+
<BlankState.Root>
|
|
25
|
+
<BlankState.Imagery name="general.search" />
|
|
26
|
+
<BlankState.Content>
|
|
27
|
+
<BlankState.Heading>No results</BlankState.Heading>
|
|
28
|
+
<BlankState.Text>
|
|
29
|
+
Nothing matches “{term}.” Try a conversation title, or a word from a message.
|
|
30
|
+
</BlankState.Text>
|
|
31
|
+
</BlankState.Content>
|
|
32
|
+
</BlankState.Root>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -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,37 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleSheet } from 'react-native'
|
|
3
|
+
import { Text } from '../../../components/display'
|
|
4
|
+
import { useTheme } from '../../../hooks'
|
|
5
|
+
import type { SnippetSegment } from '../../../types/resources/search_result'
|
|
6
|
+
|
|
7
|
+
interface SnippetProps {
|
|
8
|
+
segments: SnippetSegment[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function Snippet({ segments }: SnippetProps) {
|
|
12
|
+
const styles = useStyles()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
{segments.map((segment, index) => (
|
|
17
|
+
<Text key={index} variant="tertiary" style={segment.match && styles.match}>
|
|
18
|
+
{segment.text}
|
|
19
|
+
</Text>
|
|
20
|
+
))}
|
|
21
|
+
</>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function plainSnippetText(segments: SnippetSegment[]) {
|
|
26
|
+
return segments.map(segment => segment.text).join('')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const useStyles = () => {
|
|
30
|
+
const { colors } = useTheme()
|
|
31
|
+
|
|
32
|
+
return StyleSheet.create({
|
|
33
|
+
match: {
|
|
34
|
+
color: colors.interaction,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { SearchPromptBlankState } from './components/search_blank_states'
|
|
14
|
+
import { SearchField } from './components/search_field'
|
|
15
|
+
|
|
16
|
+
export const SearchScreenOptions = ({
|
|
17
|
+
navigation,
|
|
18
|
+
}: NativeStackScreenProps<ParamListBase>): NativeStackNavigationOptions =>
|
|
19
|
+
composeOptions(
|
|
20
|
+
{ title: 'Search', animation: 'fade' },
|
|
21
|
+
withMinimalBack({ onPress: () => navigation.goBack() })
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export function SearchScreen() {
|
|
25
|
+
const [term, setTerm] = useState('')
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<KeyboardView>
|
|
29
|
+
<View style={styles.container} testID="search-screen">
|
|
30
|
+
<SearchField term={term} onChange={setTerm} />
|
|
31
|
+
<SearchPromptBlankState />
|
|
32
|
+
</View>
|
|
33
|
+
</KeyboardView>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
container: {
|
|
39
|
+
flex: 1,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
@@ -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
|
+
>
|
|
@@ -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
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InfiniteData, QueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
2
3
|
import type { ApiCollection, MessageResource } from '../../../types'
|
|
3
4
|
import type { PersonResource } from '../../../types/resources/person'
|
|
4
5
|
import { updateCacheWithMessage } from '../messages_cache'
|
|
@@ -44,7 +45,7 @@ describe('updateCacheWithMessage on message.created', () => {
|
|
|
44
45
|
let queryClient: QueryClient
|
|
45
46
|
|
|
46
47
|
beforeEach(() => {
|
|
47
|
-
queryClient =
|
|
48
|
+
queryClient = buildTestQueryClient()
|
|
48
49
|
seed(
|
|
49
50
|
queryClient,
|
|
50
51
|
message({ id: '01B-temp', idempotentKey: 'key-b', pending: true }),
|