@planningcenter/chat-react-native 4.8.0-qa-staging.1 → 4.8.0-qa-staging.3
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 +2 -0
- package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js +120 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts +2 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +143 -107
- 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 +154 -110
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +50 -48
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/checkbox.d.ts +8 -0
- package/build/components/display/checkbox.d.ts.map +1 -0
- package/build/components/display/checkbox.js +87 -0
- package/build/components/display/checkbox.js.map +1 -0
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +5 -0
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +121 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/use_bulk_conversation_actions.d.ts +8 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.js +309 -0
- package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
- package/build/hooks/use_conversations_cache.d.ts +14 -2
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +149 -56
- package/build/hooks/use_conversations_cache.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -7
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +4 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +122 -43
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/package.json +3 -3
- package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +36 -11
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +108 -0
- package/src/components/conversations/conversation_actions.tsx +18 -12
- package/src/components/conversations/conversation_preview.tsx +12 -1
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/index.ts +1 -0
- package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -0
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +15 -3
- package/src/hooks/use_bulk_conversation_actions.ts +173 -0
- package/src/hooks/use_conversations_cache.ts +32 -3
- package/src/navigation/index.tsx +8 -8
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +8 -0
- package/src/screens/conversations/conversations_screen.tsx +51 -3
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert } from 'react-native'
|
|
3
|
+
import { useConversationsContext } from '../contexts/conversations_context'
|
|
4
|
+
import { ApiResource, ConversationResource } from '../types'
|
|
5
|
+
import { pluralize } from '../utils/pluralize'
|
|
6
|
+
import { HIDDEN_CONVERSATIONS_FILTER } from '../utils/request/conversation'
|
|
7
|
+
import { showToast } from '../utils/toast_store'
|
|
8
|
+
import { useApiClient } from './use_api_client'
|
|
9
|
+
import { getConversationRequestArgs } from './use_conversation'
|
|
10
|
+
import { useConversationsCache } from './use_conversations_cache'
|
|
11
|
+
import { useCurrentPersonCache } from './use_current_person'
|
|
12
|
+
import { getRequestQueryKey } from './use_suspense_api'
|
|
13
|
+
|
|
14
|
+
const settle = async (
|
|
15
|
+
conversations: ConversationResource[],
|
|
16
|
+
request: (conversation: ConversationResource) => Promise<unknown>
|
|
17
|
+
) => {
|
|
18
|
+
const results = await Promise.allSettled(conversations.map(request))
|
|
19
|
+
const succeeded = conversations.filter((_, i) => results[i].status === 'fulfilled')
|
|
20
|
+
const failed = conversations.filter((_, i) => results[i].status === 'rejected')
|
|
21
|
+
|
|
22
|
+
return { succeeded, failed }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const alertFailures = (verb: string, failed: ConversationResource[]) => {
|
|
26
|
+
if (failed.length === 0) return
|
|
27
|
+
|
|
28
|
+
Alert.alert(
|
|
29
|
+
'Oops',
|
|
30
|
+
`Couldn't ${verb} ${pluralize(failed.length, 'conversation')}. Please try again.`
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const sumUnread = (conversations: ConversationResource[]) =>
|
|
35
|
+
conversations.reduce((sum, { unreadCount }) => sum + (unreadCount || 0), 0)
|
|
36
|
+
|
|
37
|
+
export const useBulkConversationActions = () => {
|
|
38
|
+
const apiClient = useApiClient()
|
|
39
|
+
const queryClient = useQueryClient()
|
|
40
|
+
const { args } = useConversationsContext()
|
|
41
|
+
const currentPersonCache = useCurrentPersonCache()
|
|
42
|
+
const {
|
|
43
|
+
cancelAllLists,
|
|
44
|
+
invalidateAllLists,
|
|
45
|
+
removeFromAllLists,
|
|
46
|
+
restoreLists,
|
|
47
|
+
snapshotAllLists,
|
|
48
|
+
updateInAllLists,
|
|
49
|
+
} = useConversationsCache(args)
|
|
50
|
+
|
|
51
|
+
const setMembershipHidden = (conversations: ConversationResource[], hidden: boolean) =>
|
|
52
|
+
conversations.forEach(({ id }) =>
|
|
53
|
+
queryClient.setQueryData<ApiResource<ConversationResource>>(
|
|
54
|
+
getRequestQueryKey(getConversationRequestArgs({ conversation_id: id })),
|
|
55
|
+
prev => {
|
|
56
|
+
if (!prev?.data) return prev
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...prev,
|
|
60
|
+
data: {
|
|
61
|
+
...prev.data,
|
|
62
|
+
conversationMembership: { ...prev.data.conversationMembership, hidden },
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const patchMembership =
|
|
70
|
+
(attributes: { hidden?: boolean; muted?: boolean }) =>
|
|
71
|
+
({ id }: ConversationResource) =>
|
|
72
|
+
apiClient.chat.patch({
|
|
73
|
+
url: `/me/conversations/${id}/conversation_membership`,
|
|
74
|
+
data: {
|
|
75
|
+
data: { type: 'ConversationMembership', attributes },
|
|
76
|
+
fields: { ConversationMembership: Object.keys(attributes).join(',') },
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const applyHidden = async (conversations: ConversationResource[], hidden: boolean) => {
|
|
81
|
+
const filter = hidden ? undefined : HIDDEN_CONVERSATIONS_FILTER
|
|
82
|
+
await cancelAllLists()
|
|
83
|
+
const previousLists = snapshotAllLists()
|
|
84
|
+
|
|
85
|
+
removeFromAllLists(
|
|
86
|
+
conversations.map(({ id }) => id),
|
|
87
|
+
{ filter }
|
|
88
|
+
)
|
|
89
|
+
setMembershipHidden(conversations, hidden)
|
|
90
|
+
|
|
91
|
+
const result = await settle(conversations, patchMembership({ hidden }))
|
|
92
|
+
|
|
93
|
+
if (result.failed.length > 0) {
|
|
94
|
+
restoreLists(previousLists)
|
|
95
|
+
removeFromAllLists(
|
|
96
|
+
result.succeeded.map(({ id }) => id),
|
|
97
|
+
{ filter }
|
|
98
|
+
)
|
|
99
|
+
setMembershipHidden(result.failed, !hidden)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { ...result, previousLists }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const unhide = async (conversations: ConversationResource[]) => {
|
|
106
|
+
const { failed } = await applyHidden(conversations, false)
|
|
107
|
+
|
|
108
|
+
invalidateAllLists()
|
|
109
|
+
alertFailures('unhide', failed)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const hide = async (conversations: ConversationResource[]) => {
|
|
113
|
+
const { succeeded, failed, previousLists } = await applyHidden(conversations, true)
|
|
114
|
+
|
|
115
|
+
alertFailures('hide', failed)
|
|
116
|
+
if (succeeded.length === 0) return
|
|
117
|
+
|
|
118
|
+
invalidateAllLists({ filter: HIDDEN_CONVERSATIONS_FILTER })
|
|
119
|
+
showToast({
|
|
120
|
+
title: `${pluralize(succeeded.length, 'conversation')} hidden`,
|
|
121
|
+
action: {
|
|
122
|
+
label: 'Undo',
|
|
123
|
+
onPress: () => {
|
|
124
|
+
restoreLists(previousLists)
|
|
125
|
+
unhide(succeeded)
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const silence = async (conversations: ConversationResource[]) => {
|
|
132
|
+
const setMuted = (conversation: ConversationResource, muted: boolean) =>
|
|
133
|
+
updateInAllLists(conversation.id, {
|
|
134
|
+
muted,
|
|
135
|
+
conversationMembership: { ...conversation.conversationMembership, muted },
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
conversations.forEach(conversation => setMuted(conversation, true))
|
|
139
|
+
|
|
140
|
+
const { failed } = await settle(conversations, patchMembership({ muted: true }))
|
|
141
|
+
|
|
142
|
+
failed.forEach(conversation => setMuted(conversation, conversation.muted))
|
|
143
|
+
alertFailures('silence', failed)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const adjustPersonUnread = (delta: number) =>
|
|
147
|
+
currentPersonCache.update({}, person => ({
|
|
148
|
+
...person,
|
|
149
|
+
unreadCount: Math.max(person.unreadCount + delta, 0),
|
|
150
|
+
}))
|
|
151
|
+
|
|
152
|
+
const markRead = async (conversations: ConversationResource[]) => {
|
|
153
|
+
conversations.forEach(({ id }) =>
|
|
154
|
+
updateInAllLists(id, { unreadCount: 0, unreadReaction: false })
|
|
155
|
+
)
|
|
156
|
+
adjustPersonUnread(-sumUnread(conversations))
|
|
157
|
+
|
|
158
|
+
const { failed } = await settle(conversations, ({ id }) =>
|
|
159
|
+
apiClient.chat.post({
|
|
160
|
+
url: `/me/conversations/${id}/mark_read`,
|
|
161
|
+
data: { data: { type: '', attributes: {} }, fields: { Conversation: 'unread_count,id' } },
|
|
162
|
+
})
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
failed.forEach(({ id, unreadCount, unreadReaction }) =>
|
|
166
|
+
updateInAllLists(id, { unreadCount, unreadReaction })
|
|
167
|
+
)
|
|
168
|
+
adjustPersonUnread(sumUnread(failed))
|
|
169
|
+
alertFailures('mark read', failed)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { hide, unhide, silence, markRead }
|
|
173
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InfiniteData, useQueryClient } from '@tanstack/react-query'
|
|
1
|
+
import { InfiniteData, QueryKey, useQueryClient } from '@tanstack/react-query'
|
|
2
2
|
import { ApiCollection, ConversationResource } from '../types'
|
|
3
3
|
import {
|
|
4
4
|
deleteRecordInPagesData,
|
|
@@ -10,6 +10,7 @@ import { useApiClient } from './use_api_client'
|
|
|
10
10
|
import { getRequestQueryKey } from './use_suspense_api'
|
|
11
11
|
|
|
12
12
|
type QueryData = InfiniteData<ApiCollection<ConversationResource>>
|
|
13
|
+
export type ConversationListsSnapshot = Array<[QueryKey, QueryData | undefined]>
|
|
13
14
|
|
|
14
15
|
export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
15
16
|
const apiClient = useApiClient()
|
|
@@ -63,8 +64,32 @@ export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
|
63
64
|
})
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
const
|
|
67
|
-
|
|
67
|
+
const listsQueryKey = (filter?: string) =>
|
|
68
|
+
filter ? [conversationsRequestArgs.url, { filter }] : [conversationsRequestArgs.url]
|
|
69
|
+
|
|
70
|
+
const invalidateAllLists = ({ filter }: { filter?: string } = {}) =>
|
|
71
|
+
queryClient.invalidateQueries({ queryKey: listsQueryKey(filter) })
|
|
72
|
+
|
|
73
|
+
const cancelAllLists = () => queryClient.cancelQueries({ queryKey: listsQueryKey() })
|
|
74
|
+
|
|
75
|
+
const snapshotAllLists = (): ConversationListsSnapshot =>
|
|
76
|
+
queryClient.getQueriesData<QueryData>({ queryKey: listsQueryKey() })
|
|
77
|
+
|
|
78
|
+
const restoreLists = (lists: ConversationListsSnapshot) =>
|
|
79
|
+
lists.forEach(([queryKey, data]) => queryClient.setQueryData<QueryData>(queryKey, data))
|
|
80
|
+
|
|
81
|
+
const removeFromAllLists = (ids: number[], { filter }: { filter?: string } = {}) =>
|
|
82
|
+
queryClient.setQueriesData<QueryData>({ queryKey: listsQueryKey(filter) }, prev => {
|
|
83
|
+
if (!prev?.pages) return prev
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...prev,
|
|
87
|
+
pages: prev.pages.map(page => ({
|
|
88
|
+
...page,
|
|
89
|
+
data: page.data.filter(({ id }) => !ids.includes(id)),
|
|
90
|
+
})),
|
|
91
|
+
}
|
|
92
|
+
})
|
|
68
93
|
|
|
69
94
|
const handleConversationDestroy = ({ id }: { id: number }) => {
|
|
70
95
|
if (!id) return
|
|
@@ -93,12 +118,16 @@ export function useConversationsCache(args?: Partial<ConversationRequestArgs>) {
|
|
|
93
118
|
}
|
|
94
119
|
|
|
95
120
|
return {
|
|
121
|
+
cancelAllLists,
|
|
96
122
|
queryKey: conversationQueryKey,
|
|
97
123
|
create: updateOrCreate,
|
|
98
124
|
destroy: handleConversationDestroy,
|
|
99
125
|
fetchSync: fetchAndSync,
|
|
100
126
|
invalidate: () => queryClient.invalidateQueries({ queryKey: conversationQueryKey }),
|
|
101
127
|
invalidateAllLists,
|
|
128
|
+
removeFromAllLists,
|
|
129
|
+
restoreLists,
|
|
130
|
+
snapshotAllLists,
|
|
102
131
|
update: updateOrCreate,
|
|
103
132
|
updateAll,
|
|
104
133
|
updateInAllLists,
|
package/src/navigation/index.tsx
CHANGED
|
@@ -60,7 +60,10 @@ import {
|
|
|
60
60
|
ConversationSelectTypeScreen,
|
|
61
61
|
ConversationSelectTypeScreenOptions,
|
|
62
62
|
} from '../screens/conversation_select_type_screen'
|
|
63
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
ConversationsScreen,
|
|
65
|
+
conversationsScreenOptions,
|
|
66
|
+
} from '../screens/conversations/conversations_screen'
|
|
64
67
|
import { GetHelpScreen } from '../screens/get_help_screen'
|
|
65
68
|
import {
|
|
66
69
|
GroupNotificationLevelSelectScreen,
|
|
@@ -181,13 +184,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
181
184
|
Conversations: {
|
|
182
185
|
screen: ConversationsScreen,
|
|
183
186
|
options: ({ route, navigation }) =>
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
},
|
|
189
|
-
withRightClose({ onPress: navigation.goBack })
|
|
190
|
-
),
|
|
187
|
+
conversationsScreenOptions({
|
|
188
|
+
title: (route.params as { title?: string })?.title,
|
|
189
|
+
onClose: navigation.goBack,
|
|
190
|
+
}),
|
|
191
191
|
},
|
|
192
192
|
ConversationFilters: {
|
|
193
193
|
screen: ConversationFiltersScreen,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type RouteProp, useRoute } from '@react-navigation/native'
|
|
2
|
-
import { Pressable,
|
|
3
|
-
import {
|
|
2
|
+
import { Pressable, StyleSheet, type ViewStyle } from 'react-native'
|
|
3
|
+
import { Checkbox, Text } from '../../../components'
|
|
4
4
|
import { useTheme } from '../../../hooks'
|
|
5
|
-
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
6
5
|
import { ConversationFilterRecipientsScreenProps, SetTeamFilters, TeamProps } from '../types'
|
|
7
6
|
|
|
8
7
|
interface TeamRowProps {
|
|
@@ -43,7 +42,7 @@ export const CheckboxRow = ({
|
|
|
43
42
|
accessibilityLabelledBy={accessibilityLabelledBy}
|
|
44
43
|
accessibilityLabel={`${teamName} team`}
|
|
45
44
|
>
|
|
46
|
-
<
|
|
45
|
+
<Checkbox checked={checked} />
|
|
47
46
|
<Text style={styles.label} numberOfLines={2}>
|
|
48
47
|
{teamName}
|
|
49
48
|
</Text>
|
|
@@ -51,28 +50,9 @@ export const CheckboxRow = ({
|
|
|
51
50
|
)
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
function CheckboxIcon({ checked }: { checked: boolean }) {
|
|
55
|
-
const styles = useStyles()
|
|
56
|
-
const checkedStyle = checked ? styles.checkedContainer : styles.uncheckedContainer
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<View style={checkedStyle}>
|
|
60
|
-
{checked && <Icon name="general.thickCheckmark" style={styles.checkedIcon} />}
|
|
61
|
-
</View>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
53
|
const useStyles = () => {
|
|
66
54
|
const { colors } = useTheme()
|
|
67
55
|
|
|
68
|
-
const baseCheckboxStyles: ViewStyle = {
|
|
69
|
-
width: 20,
|
|
70
|
-
height: 20,
|
|
71
|
-
borderRadius: 40,
|
|
72
|
-
alignItems: 'center',
|
|
73
|
-
justifyContent: 'center',
|
|
74
|
-
}
|
|
75
|
-
|
|
76
56
|
return StyleSheet.create({
|
|
77
57
|
checkboxRow: {
|
|
78
58
|
flexDirection: 'row',
|
|
@@ -89,17 +69,5 @@ const useStyles = () => {
|
|
|
89
69
|
label: {
|
|
90
70
|
flex: 1,
|
|
91
71
|
},
|
|
92
|
-
checkedContainer: {
|
|
93
|
-
...baseCheckboxStyles,
|
|
94
|
-
backgroundColor: colors.statusSuccessIcon,
|
|
95
|
-
},
|
|
96
|
-
uncheckedContainer: {
|
|
97
|
-
...baseCheckboxStyles,
|
|
98
|
-
borderWidth: 2,
|
|
99
|
-
borderColor: colors.borderColorDefaultDarker,
|
|
100
|
-
},
|
|
101
|
-
checkedIcon: {
|
|
102
|
-
color: tokens.colorNeutral100White,
|
|
103
|
-
},
|
|
104
72
|
})
|
|
105
73
|
}
|
|
@@ -12,6 +12,10 @@ import {
|
|
|
12
12
|
import { ConversationsScreen } from '../conversations_screen'
|
|
13
13
|
|
|
14
14
|
const mockGet = jest.fn()
|
|
15
|
+
jest.mock('@react-navigation/native', () => ({
|
|
16
|
+
...jest.requireActual('@react-navigation/native'),
|
|
17
|
+
useNavigation: () => ({ setOptions: jest.fn(), goBack: jest.fn() }),
|
|
18
|
+
}))
|
|
15
19
|
jest.mock('../../../hooks/use_api_client', () => ({
|
|
16
20
|
useApiClient: () => ({ chat: { get: mockGet } }),
|
|
17
21
|
}))
|
|
@@ -21,12 +25,16 @@ jest.mock('../../../hooks/use_product_analytics', () => ({
|
|
|
21
25
|
}))
|
|
22
26
|
jest.mock('../../../contexts/conversations_context', () => ({
|
|
23
27
|
ConversationsContextProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
28
|
+
useConversationsContext: () => ({ selectMode: false, selectedIds: [] }),
|
|
24
29
|
}))
|
|
25
30
|
jest.mock('../../../components', () => ({
|
|
26
31
|
Conversations: ({ ListHeaderComponent }: { ListHeaderComponent: React.ReactElement }) =>
|
|
27
32
|
ListHeaderComponent,
|
|
28
33
|
}))
|
|
29
34
|
jest.mock('../../../components/display/toast', () => ({ Toast: () => null }))
|
|
35
|
+
jest.mock('../../../components/conversations/bulk_conversation_actions_bar', () => ({
|
|
36
|
+
BulkConversationActionsBar: () => null,
|
|
37
|
+
}))
|
|
30
38
|
jest.mock('../components/list_header_component', () => {
|
|
31
39
|
const { Text } = require('react-native')
|
|
32
40
|
return { ListHeaderComponent: () => <Text>Default header</Text> }
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { StaticScreenProps } from '@react-navigation/native'
|
|
2
|
-
import React from 'react'
|
|
1
|
+
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
|
+
import React, { 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'
|
|
6
|
+
import { BulkConversationActionsBar } from '../../components/conversations/bulk_conversation_actions_bar'
|
|
7
|
+
import {
|
|
8
|
+
composeOptions,
|
|
9
|
+
withRightClose,
|
|
10
|
+
withRightText,
|
|
11
|
+
} from '../../components/display/platform_modal_header_buttons'
|
|
6
12
|
import { Toast } from '../../components/display/toast'
|
|
7
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ConversationsContextProvider,
|
|
15
|
+
useConversationsContext,
|
|
16
|
+
} from '../../contexts/conversations_context'
|
|
8
17
|
import { useFilterDropdownEnabled } from '../../hooks/use_filter_dropdown_enabled'
|
|
9
18
|
import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
|
|
10
19
|
import { useSearchEnabled } from '../../hooks/use_search_enabled'
|
|
@@ -24,6 +33,18 @@ export type ConversationsScreenProps = StaticScreenProps<{
|
|
|
24
33
|
show_unread?: boolean
|
|
25
34
|
}>
|
|
26
35
|
|
|
36
|
+
export const conversationsScreenOptions = ({
|
|
37
|
+
title,
|
|
38
|
+
onClose,
|
|
39
|
+
}: {
|
|
40
|
+
title?: string
|
|
41
|
+
onClose: () => void
|
|
42
|
+
}) =>
|
|
43
|
+
composeOptions(
|
|
44
|
+
{ headerTitle: title ?? 'Chat', headerBackVisible: false },
|
|
45
|
+
withRightClose({ onPress: onClose })
|
|
46
|
+
)
|
|
47
|
+
|
|
27
48
|
export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
28
49
|
const styles = useStyles()
|
|
29
50
|
const Header = useListHeaderComponent()
|
|
@@ -33,6 +54,7 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
33
54
|
return (
|
|
34
55
|
<View style={styles.container}>
|
|
35
56
|
<ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
|
|
57
|
+
<SelectModeHeader title={route.params?.title} />
|
|
36
58
|
<Conversations
|
|
37
59
|
ListHeaderComponent={
|
|
38
60
|
<>
|
|
@@ -41,12 +63,38 @@ export function ConversationsScreen({ route }: ConversationsScreenProps) {
|
|
|
41
63
|
</>
|
|
42
64
|
}
|
|
43
65
|
/>
|
|
66
|
+
<BulkConversationActionsBar />
|
|
44
67
|
</ConversationsContextProvider>
|
|
45
68
|
<Toast />
|
|
46
69
|
</View>
|
|
47
70
|
)
|
|
48
71
|
}
|
|
49
72
|
|
|
73
|
+
function SelectModeHeader({ title }: { title?: string }) {
|
|
74
|
+
const navigation = useNavigation()
|
|
75
|
+
const { selectMode, selectedIds, clearSelection } = useConversationsContext()
|
|
76
|
+
const hasEnteredSelectMode = useRef(false)
|
|
77
|
+
const selectedCount = selectedIds.length
|
|
78
|
+
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
if (selectMode) hasEnteredSelectMode.current = true
|
|
81
|
+
if (!hasEnteredSelectMode.current) return
|
|
82
|
+
|
|
83
|
+
navigation.setOptions(
|
|
84
|
+
selectMode
|
|
85
|
+
? composeOptions(
|
|
86
|
+
{
|
|
87
|
+
headerTitle: selectedCount > 0 ? `${selectedCount} selected` : 'Select conversations',
|
|
88
|
+
},
|
|
89
|
+
withRightText({ text: 'Cancel', onPress: clearSelection })
|
|
90
|
+
)
|
|
91
|
+
: conversationsScreenOptions({ title, onClose: navigation.goBack })
|
|
92
|
+
)
|
|
93
|
+
}, [navigation, selectMode, selectedCount, clearSelection, title])
|
|
94
|
+
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
50
98
|
const useListHeaderComponent = () => {
|
|
51
99
|
const filterDropdownEnabled = useFilterDropdownEnabled()
|
|
52
100
|
const searchEnabled = useSearchEnabled()
|