@planningcenter/chat-react-native 4.8.0-qa-staging.4 → 4.8.0-qa-staging.6
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/conversations/bulk_conversation_actions_bar.d.ts.map +1 -1
- package/build/components/conversations/bulk_conversation_actions_bar.js +137 -45
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +120 -113
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/conversations/conversation_preview.d.ts.map +1 -1
- package/build/components/conversations/conversation_preview.js +129 -115
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/display/button.js +0 -1
- package/build/components/display/button.js.map +1 -1
- package/build/screens/conversation_actions_screen.d.ts +2 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -1
- package/build/screens/conversation_actions_screen.js +380 -46
- package/build/screens/conversation_actions_screen.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +1 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +94 -48
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/package.json +3 -3
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +13 -6
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +62 -33
- package/src/components/conversations/conversation_actions.tsx +7 -5
- package/src/components/conversations/conversation_preview.tsx +8 -1
- package/src/components/display/button.tsx +0 -1
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
- package/src/screens/conversation_actions_screen.tsx +145 -12
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +29 -5
- package/src/screens/conversations/conversations_screen.tsx +17 -1
|
@@ -1,39 +1,150 @@
|
|
|
1
|
-
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
1
|
+
import { StackActions, StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { StyleSheet } from 'react-native'
|
|
3
|
+
import { StyleSheet, View } from 'react-native'
|
|
4
|
+
import { ConversationAvatar, Heading, Text } from '../components/display'
|
|
4
5
|
import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
|
|
5
|
-
import {
|
|
6
|
+
import { useTheme } from '../hooks'
|
|
7
|
+
import { useConversation, useConversationMute } from '../hooks/use_conversation'
|
|
8
|
+
import { useConversationsMarkRead } from '../hooks/use_conversations_actions'
|
|
6
9
|
import { useHideConversation } from '../hooks/use_hide_conversation'
|
|
7
10
|
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
11
|
+
import { isArchivedConversation, MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../utils'
|
|
8
12
|
|
|
9
13
|
export const ConversationActionsScreenOptions = getFormSheetScreenOptions({
|
|
10
14
|
headerTitle: 'Conversation actions',
|
|
15
|
+
sheetAllowedDetents: 'fitToContents',
|
|
11
16
|
})
|
|
12
17
|
|
|
13
18
|
export type ConversationActionsScreenProps = StaticScreenProps<{
|
|
14
19
|
conversation_id: number
|
|
20
|
+
read?: boolean
|
|
21
|
+
muted?: boolean
|
|
15
22
|
}>
|
|
16
23
|
|
|
17
24
|
export function ConversationActionsScreen({ route }: ConversationActionsScreenProps) {
|
|
18
25
|
const navigation = useNavigation()
|
|
19
26
|
const styles = useStyles()
|
|
20
|
-
const {
|
|
21
|
-
const {
|
|
27
|
+
const { conversation_id } = route.params
|
|
28
|
+
const { data: conversation } = useConversation({ conversation_id })
|
|
29
|
+
const { hidden, setHidden, isPending: isHiddenPending } = useHideConversation({ conversation })
|
|
30
|
+
const markReadState = useConversationsMarkRead({ conversation })
|
|
31
|
+
const muteState = useConversationMute({ conversation_id })
|
|
22
32
|
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
23
33
|
|
|
34
|
+
const read = route.params.read ?? markReadState.read
|
|
35
|
+
const muted = route.params.muted ?? muteState.muted
|
|
36
|
+
const archived = isArchivedConversation(conversation)
|
|
37
|
+
const emptyConversation = conversation.lastMessageCreatedAt === null
|
|
38
|
+
const subtitle = conversation.badges?.[0]?.text
|
|
39
|
+
|
|
40
|
+
const navigateAfterDismiss = (navigate: () => void) => {
|
|
41
|
+
navigation.goBack()
|
|
42
|
+
requestAnimationFrame(navigate)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const handleOpenPress = () =>
|
|
46
|
+
navigateAfterDismiss(() =>
|
|
47
|
+
navigation.navigate('Conversation', {
|
|
48
|
+
conversation_id,
|
|
49
|
+
title: conversation.title ?? undefined,
|
|
50
|
+
badge: conversation.badges?.[0],
|
|
51
|
+
deleted: conversation.deleted,
|
|
52
|
+
muted,
|
|
53
|
+
})
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const handleDetailsPress = () =>
|
|
57
|
+
navigateAfterDismiss(() => navigation.navigate('ConversationDetails', { conversation_id }))
|
|
58
|
+
|
|
59
|
+
const handleMarkReadPress = () => {
|
|
60
|
+
markReadState.markRead(!read)
|
|
61
|
+
navigation.goBack()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const handleMutePress = () => {
|
|
65
|
+
muteState.setMuted(!muted)
|
|
66
|
+
navigation.goBack()
|
|
67
|
+
}
|
|
68
|
+
|
|
24
69
|
const handleHidePress = () => {
|
|
25
70
|
setHidden(!hidden)
|
|
26
71
|
navigation.goBack()
|
|
27
72
|
}
|
|
28
73
|
|
|
74
|
+
const handleSelectPress = () => {
|
|
75
|
+
navigation.dispatch(
|
|
76
|
+
StackActions.popTo(
|
|
77
|
+
'Conversations',
|
|
78
|
+
{ select_conversation_id: conversation_id },
|
|
79
|
+
{ merge: true }
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!hideConversationsEnabled) return <FormSheet.Root fitToContents>{null}</FormSheet.Root>
|
|
85
|
+
|
|
29
86
|
return (
|
|
30
|
-
<FormSheet.Root
|
|
31
|
-
|
|
87
|
+
<FormSheet.Root fitToContents>
|
|
88
|
+
<FormSheet.Header>
|
|
89
|
+
<View style={styles.header}>
|
|
90
|
+
<ConversationAvatar conversation={conversation} size="md" showFallback />
|
|
91
|
+
<View style={styles.headerText}>
|
|
92
|
+
<Heading
|
|
93
|
+
variant="h3"
|
|
94
|
+
numberOfLines={1}
|
|
95
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
96
|
+
>
|
|
97
|
+
{conversation.title}
|
|
98
|
+
</Heading>
|
|
99
|
+
{!!subtitle && (
|
|
100
|
+
<Text
|
|
101
|
+
variant="tertiary"
|
|
102
|
+
numberOfLines={1}
|
|
103
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
104
|
+
>
|
|
105
|
+
{subtitle}
|
|
106
|
+
</Text>
|
|
107
|
+
)}
|
|
108
|
+
</View>
|
|
109
|
+
</View>
|
|
110
|
+
</FormSheet.Header>
|
|
111
|
+
<FormSheet.Action
|
|
112
|
+
onPress={handleOpenPress}
|
|
113
|
+
title="Open conversation"
|
|
114
|
+
iconName="general.textMessage"
|
|
115
|
+
/>
|
|
116
|
+
<FormSheet.Action
|
|
117
|
+
onPress={handleDetailsPress}
|
|
118
|
+
title="Conversation details"
|
|
119
|
+
iconName="general.cog"
|
|
120
|
+
/>
|
|
121
|
+
{!emptyConversation && (
|
|
122
|
+
<FormSheet.Action
|
|
123
|
+
onPress={handleMarkReadPress}
|
|
124
|
+
title={read ? 'Mark as unread' : 'Mark as read'}
|
|
125
|
+
iconName={read ? 'general.message' : 'general.outlinedMessage'}
|
|
126
|
+
disabled={markReadState.isPending}
|
|
127
|
+
/>
|
|
128
|
+
)}
|
|
129
|
+
{!archived && (
|
|
130
|
+
<FormSheet.Action
|
|
131
|
+
onPress={handleMutePress}
|
|
132
|
+
title={muted ? 'Enable' : 'Silence'}
|
|
133
|
+
iconName={muted ? 'general.bell' : 'general.bellMuted'}
|
|
134
|
+
disabled={muteState.isPending}
|
|
135
|
+
accessibilityHint={
|
|
136
|
+
muted
|
|
137
|
+
? 'Turns notifications for this conversation back on.'
|
|
138
|
+
: 'Turns off notifications for this conversation.'
|
|
139
|
+
}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
{!archived && (
|
|
32
143
|
<FormSheet.Action
|
|
33
144
|
onPress={handleHidePress}
|
|
34
145
|
title={hidden ? 'Unhide conversation' : 'Hide conversation'}
|
|
35
146
|
iconName={hidden ? 'general.showEye' : 'general.hideEye'}
|
|
36
|
-
disabled={
|
|
147
|
+
disabled={isHiddenPending}
|
|
37
148
|
accessibilityHint={
|
|
38
149
|
hidden
|
|
39
150
|
? 'Shows this conversation in your conversation list again.'
|
|
@@ -41,13 +152,35 @@ export function ConversationActionsScreen({ route }: ConversationActionsScreenPr
|
|
|
41
152
|
}
|
|
42
153
|
/>
|
|
43
154
|
)}
|
|
155
|
+
<View style={styles.divider} />
|
|
156
|
+
<FormSheet.Action
|
|
157
|
+
onPress={handleSelectPress}
|
|
158
|
+
title="Select conversations"
|
|
159
|
+
iconName="general.check"
|
|
160
|
+
accessibilityHint="Selects this conversation and lets you choose more to hide, silence, or mark read."
|
|
161
|
+
/>
|
|
44
162
|
</FormSheet.Root>
|
|
45
163
|
)
|
|
46
164
|
}
|
|
47
165
|
|
|
48
|
-
const useStyles = () =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
166
|
+
const useStyles = () => {
|
|
167
|
+
const { colors } = useTheme()
|
|
168
|
+
|
|
169
|
+
return StyleSheet.create({
|
|
170
|
+
header: {
|
|
171
|
+
flex: 1,
|
|
172
|
+
flexDirection: 'row',
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
gap: 12,
|
|
175
|
+
},
|
|
176
|
+
headerText: {
|
|
177
|
+
flex: 1,
|
|
178
|
+
},
|
|
179
|
+
divider: {
|
|
180
|
+
height: 1,
|
|
181
|
+
marginHorizontal: 16,
|
|
182
|
+
marginVertical: 4,
|
|
183
|
+
backgroundColor: colors.borderColorDefaultBase,
|
|
52
184
|
},
|
|
53
185
|
})
|
|
186
|
+
}
|
|
@@ -9,12 +9,14 @@ import {
|
|
|
9
9
|
ImagePickerAdapter,
|
|
10
10
|
VideoAdapter,
|
|
11
11
|
} from '../../../utils/native_adapters'
|
|
12
|
-
import { ConversationsScreen } from '../conversations_screen'
|
|
12
|
+
import { ConversationsScreen, ConversationsScreenProps } from '../conversations_screen'
|
|
13
13
|
|
|
14
14
|
const mockGet = jest.fn()
|
|
15
|
+
const mockSetParams = jest.fn()
|
|
16
|
+
const mockEnterSelectMode = jest.fn()
|
|
15
17
|
jest.mock('@react-navigation/native', () => ({
|
|
16
18
|
...jest.requireActual('@react-navigation/native'),
|
|
17
|
-
useNavigation: () => ({ setOptions: jest.fn(), goBack: jest.fn() }),
|
|
19
|
+
useNavigation: () => ({ setOptions: jest.fn(), goBack: jest.fn(), setParams: mockSetParams }),
|
|
18
20
|
}))
|
|
19
21
|
jest.mock('../../../hooks/use_api_client', () => ({
|
|
20
22
|
useApiClient: () => ({ chat: { get: mockGet } }),
|
|
@@ -25,7 +27,11 @@ jest.mock('../../../hooks/use_product_analytics', () => ({
|
|
|
25
27
|
}))
|
|
26
28
|
jest.mock('../../../contexts/conversations_context', () => ({
|
|
27
29
|
ConversationsContextProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
28
|
-
useConversationsContext: () => ({
|
|
30
|
+
useConversationsContext: () => ({
|
|
31
|
+
selectMode: false,
|
|
32
|
+
selectedIds: [],
|
|
33
|
+
enterSelectMode: mockEnterSelectMode,
|
|
34
|
+
}),
|
|
29
35
|
}))
|
|
30
36
|
jest.mock('../../../components', () => ({
|
|
31
37
|
Conversations: ({ ListHeaderComponent }: { ListHeaderComponent: React.ReactElement }) =>
|
|
@@ -63,7 +69,10 @@ const configureAdapters = () => {
|
|
|
63
69
|
})
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
const renderWithFeatures = (
|
|
72
|
+
const renderWithFeatures = (
|
|
73
|
+
enabledFeatures: string[],
|
|
74
|
+
params: ConversationsScreenProps['route']['params'] = {}
|
|
75
|
+
) => {
|
|
67
76
|
mockGet.mockResolvedValue({
|
|
68
77
|
data: enabledFeatures.map((name, index) => ({
|
|
69
78
|
type: 'Feature',
|
|
@@ -78,7 +87,7 @@ const renderWithFeatures = (enabledFeatures: string[]) => {
|
|
|
78
87
|
return render(
|
|
79
88
|
<QueryClientProvider client={buildTestQueryClient()}>
|
|
80
89
|
<Suspense fallback={null}>
|
|
81
|
-
<ConversationsScreen route={{ params
|
|
90
|
+
<ConversationsScreen route={{ params }} />
|
|
82
91
|
</Suspense>
|
|
83
92
|
</QueryClientProvider>
|
|
84
93
|
)
|
|
@@ -119,3 +128,18 @@ describe('ConversationsScreen header gating', () => {
|
|
|
119
128
|
expect(await view.findByText('Default header')).toBeTruthy()
|
|
120
129
|
})
|
|
121
130
|
})
|
|
131
|
+
|
|
132
|
+
describe('ConversationsScreen select mode request', () => {
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
configureAdapters()
|
|
135
|
+
jest.clearAllMocks()
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('enters select mode for the requested conversation and consumes the request', async () => {
|
|
139
|
+
const view = renderWithFeatures([], { select_conversation_id: 7 })
|
|
140
|
+
await view.findByText('Default header')
|
|
141
|
+
|
|
142
|
+
expect(mockEnterSelectMode).toHaveBeenCalledWith(7)
|
|
143
|
+
expect(mockSetParams).toHaveBeenCalledWith({ select_conversation_id: undefined })
|
|
144
|
+
})
|
|
145
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
|
-
import React, { useLayoutEffect, useRef } from 'react'
|
|
2
|
+
import React, { useEffect, useLayoutEffect, useRef } from 'react'
|
|
3
3
|
import { StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Conversations } from '../../components'
|
|
5
5
|
import { AppUpdateBanner } from '../../components/conversations/app_update_banner'
|
|
@@ -31,6 +31,7 @@ export type ConversationsScreenProps = StaticScreenProps<{
|
|
|
31
31
|
show_archived?: boolean
|
|
32
32
|
show_hidden?: boolean
|
|
33
33
|
show_unread?: boolean
|
|
34
|
+
select_conversation_id?: number
|
|
34
35
|
}>
|
|
35
36
|
|
|
36
37
|
export const conversationsScreenOptions = ({
|
|
@@ -55,6 +56,7 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
55
56
|
<View style={styles.container}>
|
|
56
57
|
<ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
|
|
57
58
|
<SelectModeHeader title={route.params?.title} />
|
|
59
|
+
<SelectModeRequest conversationId={route.params?.select_conversation_id} />
|
|
58
60
|
<Conversations
|
|
59
61
|
ListHeaderComponent={
|
|
60
62
|
<>
|
|
@@ -95,6 +97,20 @@ function SelectModeHeader({ title }: { title?: string }) {
|
|
|
95
97
|
return null
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
function SelectModeRequest({ conversationId }: { conversationId?: number }) {
|
|
101
|
+
const navigation = useNavigation()
|
|
102
|
+
const { enterSelectMode } = useConversationsContext()
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (conversationId === undefined) return
|
|
106
|
+
|
|
107
|
+
enterSelectMode(conversationId)
|
|
108
|
+
navigation.setParams({ select_conversation_id: undefined })
|
|
109
|
+
}, [conversationId, enterSelectMode, navigation])
|
|
110
|
+
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
|
|
98
114
|
const useListHeaderComponent = () => {
|
|
99
115
|
const filterDropdownEnabled = useFilterDropdownEnabled()
|
|
100
116
|
const searchEnabled = useSearchEnabled()
|