@planningcenter/chat-react-native 4.7.0 → 4.7.1-qa-staging.0
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/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +322 -186
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/display/toast.d.ts +3 -0
- package/build/components/display/toast.d.ts.map +1 -0
- package/build/components/display/toast.js +224 -0
- package/build/components/display/toast.js.map +1 -0
- package/build/components/group_conversation_list.d.ts.map +1 -1
- package/build/components/group_conversation_list.js +1 -0
- package/build/components/group_conversation_list.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +3 -1
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +32 -27
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +1 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_features.d.ts +1 -0
- 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_hide_conversation.d.ts +107 -0
- package/build/hooks/use_hide_conversation.d.ts.map +1 -0
- package/build/hooks/use_hide_conversation.js +238 -0
- package/build/hooks/use_hide_conversation.js.map +1 -0
- package/build/hooks/use_hide_conversations_enabled.d.ts +2 -0
- package/build/hooks/use_hide_conversations_enabled.d.ts.map +1 -0
- package/build/hooks/use_hide_conversations_enabled.js +18 -0
- package/build/hooks/use_hide_conversations_enabled.js.map +1 -0
- 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_actions_screen.d.ts +7 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -0
- package/build/screens/conversation_actions_screen.js +89 -0
- package/build/screens/conversation_actions_screen.js.map +1 -0
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +460 -394
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +18 -10
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/index.d.ts +1 -0
- package/build/screens/index.d.ts.map +1 -1
- package/build/screens/index.js +1 -0
- package/build/screens/index.js.map +1 -1
- package/build/types/resources/conversation_membership.d.ts +1 -0
- package/build/types/resources/conversation_membership.d.ts.map +1 -1
- package/build/types/resources/conversation_membership.js.map +1 -1
- package/build/utils/toast_store.d.ts +21 -0
- package/build/utils/toast_store.d.ts.map +1 -0
- package/build/utils/toast_store.js +27 -0
- package/build/utils/toast_store.js.map +1 -0
- package/package.json +3 -3
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +76 -2
- package/src/components/conversations/conversation_actions.tsx +68 -4
- package/src/components/display/__tests__/toast.test.tsx +55 -0
- package/src/components/display/toast.tsx +115 -0
- package/src/components/group_conversation_list.tsx +4 -1
- package/src/contexts/conversations_context.tsx +6 -1
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +147 -0
- package/src/hooks/use_conversation.ts +1 -0
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_hide_conversation.ts +118 -0
- package/src/hooks/use_hide_conversations_enabled.ts +7 -0
- package/src/navigation/index.tsx +8 -0
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +79 -0
- package/src/screens/__tests__/conversation_details_screen.test.tsx +49 -1
- package/src/screens/conversation_actions_screen.tsx +53 -0
- package/src/screens/conversation_details_screen.tsx +19 -0
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +1 -0
- package/src/screens/conversations/conversations_screen.tsx +2 -0
- package/src/screens/index.ts +1 -0
- package/src/types/resources/conversation_membership.ts +1 -0
- package/src/utils/toast_store.ts +45 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.7.0",
|
|
3
|
+
"version": "4.7.1-qa-staging.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
35
35
|
"@fortawesome/react-native-fontawesome": "^0.3.2",
|
|
36
|
-
"@planningcenter/emoji-keyboard": "4.
|
|
36
|
+
"@planningcenter/emoji-keyboard": "4.7.1-qa-staging.0",
|
|
37
37
|
"lodash-inflection": "^1.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "404c5a0c87f1175f1372a355d8ca3e448ed8d5b5"
|
|
88
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render } from '@testing-library/react-native'
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { Text } from 'react-native'
|
|
4
4
|
import type { ConversationResource } from '../../../types'
|
|
@@ -27,6 +27,28 @@ jest.mock('../../../hooks/use_conversations_actions', () => ({
|
|
|
27
27
|
useConversationsMarkRead: () => ({ read: false, markRead: jest.fn(), isPending: false }),
|
|
28
28
|
}))
|
|
29
29
|
|
|
30
|
+
const mockNavigate = jest.fn()
|
|
31
|
+
jest.mock('@react-navigation/native', () => ({
|
|
32
|
+
...jest.requireActual('@react-navigation/native'),
|
|
33
|
+
useNavigation: () => ({ navigate: mockNavigate }),
|
|
34
|
+
}))
|
|
35
|
+
const mockSetHidden = jest.fn()
|
|
36
|
+
jest.mock('../../../hooks/use_hide_conversation', () => ({
|
|
37
|
+
useHideConversation: () => ({ hidden: false, setHidden: mockSetHidden, isPending: false }),
|
|
38
|
+
}))
|
|
39
|
+
let mockHideEnabled = false
|
|
40
|
+
jest.mock('../../../hooks/use_hide_conversations_enabled', () => ({
|
|
41
|
+
useHideConversationsEnabled: () => mockHideEnabled,
|
|
42
|
+
}))
|
|
43
|
+
let mockHideable = true
|
|
44
|
+
jest.mock('../../../contexts/conversations_context', () => ({
|
|
45
|
+
useConversationsContext: () => ({
|
|
46
|
+
activeConversationId: undefined,
|
|
47
|
+
setActiveConversationId: jest.fn(),
|
|
48
|
+
hideable: mockHideable,
|
|
49
|
+
}),
|
|
50
|
+
}))
|
|
51
|
+
|
|
30
52
|
const createdAt = '2026-10-01T12:00:00Z'
|
|
31
53
|
|
|
32
54
|
const conversation = (overrides: Partial<ConversationResource>): ConversationResource => ({
|
|
@@ -52,11 +74,18 @@ const renderActions = (overrides: Partial<ConversationResource>) =>
|
|
|
52
74
|
)
|
|
53
75
|
|
|
54
76
|
describe('ConversationActions', () => {
|
|
55
|
-
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
mockHideEnabled = false
|
|
79
|
+
jest.clearAllMocks()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('offers mark read but not mute or hide on an archived conversation', () => {
|
|
83
|
+
mockHideEnabled = true
|
|
56
84
|
const view = renderActions({ disabled: true, disabledReason: 'archived' })
|
|
57
85
|
|
|
58
86
|
expect(view.getByText('Mark read')).toBeTruthy()
|
|
59
87
|
expect(view.queryByText('Silence')).toBeNull()
|
|
88
|
+
expect(view.queryByText('Hide')).toBeNull()
|
|
60
89
|
})
|
|
61
90
|
|
|
62
91
|
it('offers mute on a conversation disabled for another reason', () => {
|
|
@@ -65,3 +94,48 @@ describe('ConversationActions', () => {
|
|
|
65
94
|
expect(view.getByText('Silence')).toBeTruthy()
|
|
66
95
|
})
|
|
67
96
|
})
|
|
97
|
+
|
|
98
|
+
describe('ConversationActions hide', () => {
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
mockHideEnabled = true
|
|
101
|
+
mockHideable = true
|
|
102
|
+
jest.clearAllMocks()
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('offers no hide action or long press when the list is not hideable', () => {
|
|
106
|
+
mockHideable = false
|
|
107
|
+
const view = renderActions({})
|
|
108
|
+
|
|
109
|
+
fireEvent(view.getByTestId('conversation-7'), 'longPress')
|
|
110
|
+
|
|
111
|
+
expect(view.queryByText('Hide')).toBeNull()
|
|
112
|
+
expect(view.getByText('Silence')).toBeTruthy()
|
|
113
|
+
expect(mockNavigate).not.toHaveBeenCalled()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('offers no hide action or long press when the flag is off', () => {
|
|
117
|
+
mockHideEnabled = false
|
|
118
|
+
const view = renderActions({})
|
|
119
|
+
|
|
120
|
+
fireEvent(view.getByTestId('conversation-7'), 'longPress')
|
|
121
|
+
|
|
122
|
+
expect(view.queryByText('Hide')).toBeNull()
|
|
123
|
+
expect(mockNavigate).not.toHaveBeenCalled()
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('hides from the swipe action', () => {
|
|
127
|
+
const view = renderActions({})
|
|
128
|
+
|
|
129
|
+
fireEvent.press(view.getByText('Hide'))
|
|
130
|
+
|
|
131
|
+
expect(mockSetHidden).toHaveBeenCalledWith(true)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('opens the conversation actions sheet on long press', () => {
|
|
135
|
+
const view = renderActions({})
|
|
136
|
+
|
|
137
|
+
fireEvent(view.getByTestId('conversation-7'), 'longPress')
|
|
138
|
+
|
|
139
|
+
expect(mockNavigate).toHaveBeenCalledWith('ConversationActions', { conversation_id: 7 })
|
|
140
|
+
})
|
|
141
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useNavigation } from '@react-navigation/native'
|
|
1
2
|
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
|
|
2
3
|
import {
|
|
3
4
|
AccessibilityActionEvent,
|
|
@@ -17,8 +18,11 @@ import {
|
|
|
17
18
|
useConversationsMarkRead,
|
|
18
19
|
useConversationsMute,
|
|
19
20
|
} from '../../hooks/use_conversations_actions'
|
|
21
|
+
import { useHideConversation } from '../../hooks/use_hide_conversation'
|
|
22
|
+
import { useHideConversationsEnabled } from '../../hooks/use_hide_conversations_enabled'
|
|
20
23
|
import { ConversationResource } from '../../types'
|
|
21
24
|
import { isArchivedConversation, platformPressedOpacityStyle } from '../../utils'
|
|
25
|
+
import { Haptic } from '../../utils/native_adapters'
|
|
22
26
|
import { tokens } from '../../vendor/tapestry/tokens'
|
|
23
27
|
import { SwipeableToggleButton } from './swipeable_toggle_button'
|
|
24
28
|
|
|
@@ -36,8 +40,9 @@ export function ConversationActions({
|
|
|
36
40
|
accessibilityLabel?: string
|
|
37
41
|
}) {
|
|
38
42
|
const swipeableRef = useRef<SwipeableMethods>(null)
|
|
43
|
+
const navigation = useNavigation()
|
|
39
44
|
const styles = useStyles()
|
|
40
|
-
const { activeConversationId, setActiveConversationId } = useConversationsContext()
|
|
45
|
+
const { activeConversationId, setActiveConversationId, hideable } = useConversationsContext()
|
|
41
46
|
const [disabled, setDisabled] = useState(false)
|
|
42
47
|
const overshootLeft = Platform.OS === 'ios'
|
|
43
48
|
const androidRippleColor = useCreateAndroidRippleColor({
|
|
@@ -51,9 +56,12 @@ export function ConversationActions({
|
|
|
51
56
|
} = useConversationsMarkRead({
|
|
52
57
|
conversation,
|
|
53
58
|
})
|
|
59
|
+
const { hidden, setHidden, isPending: isHiddenPending } = useHideConversation({ conversation })
|
|
60
|
+
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
54
61
|
|
|
55
62
|
const isConversationEmpty = conversation.lastMessageCreatedAt === null
|
|
56
63
|
const canMute = !isArchivedConversation(conversation)
|
|
64
|
+
const canHide = hideable && hideConversationsEnabled && !isArchivedConversation(conversation)
|
|
57
65
|
|
|
58
66
|
const handleSwipeableClose = useCallback(() => {
|
|
59
67
|
setDisabled(false)
|
|
@@ -75,6 +83,18 @@ export function ConversationActions({
|
|
|
75
83
|
handleSwipeableClose()
|
|
76
84
|
}, [muted, handleSwipeableClose, setMuted])
|
|
77
85
|
|
|
86
|
+
const handleHide = useCallback(() => {
|
|
87
|
+
setHidden(!hidden)
|
|
88
|
+
handleSwipeableClose()
|
|
89
|
+
}, [hidden, handleSwipeableClose, setHidden])
|
|
90
|
+
|
|
91
|
+
const handleLongPress = useCallback(() => {
|
|
92
|
+
if (disabled) return
|
|
93
|
+
|
|
94
|
+
Haptic.impactLight()
|
|
95
|
+
navigation.navigate('ConversationActions', { conversation_id: conversation.id })
|
|
96
|
+
}, [disabled, navigation, conversation.id])
|
|
97
|
+
|
|
78
98
|
const handleLatestMessageUnread = useCallback(() => {
|
|
79
99
|
markRead(!read)
|
|
80
100
|
handleSwipeableClose()
|
|
@@ -98,7 +118,20 @@ export function ConversationActions({
|
|
|
98
118
|
]
|
|
99
119
|
: []
|
|
100
120
|
|
|
101
|
-
const
|
|
121
|
+
const hideAccessibilityAction = canHide
|
|
122
|
+
? [
|
|
123
|
+
{
|
|
124
|
+
name: hidden ? 'unhide' : 'hide',
|
|
125
|
+
label: hidden ? 'Unhide' : 'Hide',
|
|
126
|
+
},
|
|
127
|
+
]
|
|
128
|
+
: []
|
|
129
|
+
|
|
130
|
+
const accessibilityActions = [
|
|
131
|
+
...muteAccessibilityAction,
|
|
132
|
+
...hideAccessibilityAction,
|
|
133
|
+
...readAccessibilityAction,
|
|
134
|
+
]
|
|
102
135
|
|
|
103
136
|
const handleAccessibilityAction = useCallback(
|
|
104
137
|
(event: AccessibilityActionEvent) => {
|
|
@@ -115,9 +148,13 @@ export function ConversationActions({
|
|
|
115
148
|
case 'unmute':
|
|
116
149
|
handleMute()
|
|
117
150
|
break
|
|
151
|
+
case 'hide':
|
|
152
|
+
case 'unhide':
|
|
153
|
+
handleHide()
|
|
154
|
+
break
|
|
118
155
|
}
|
|
119
156
|
},
|
|
120
|
-
[handleLatestMessageUnread, handleMute]
|
|
157
|
+
[handleLatestMessageUnread, handleMute, handleHide]
|
|
121
158
|
)
|
|
122
159
|
|
|
123
160
|
useEffect(() => {
|
|
@@ -141,11 +178,15 @@ export function ConversationActions({
|
|
|
141
178
|
<LeftActions
|
|
142
179
|
isConversationEmpty={isConversationEmpty}
|
|
143
180
|
canMute={canMute}
|
|
181
|
+
canHide={canHide}
|
|
144
182
|
handleMute={handleMute}
|
|
183
|
+
handleHide={handleHide}
|
|
145
184
|
handleLatestMessageUnread={handleLatestMessageUnread}
|
|
146
185
|
muted={muted}
|
|
186
|
+
hidden={hidden}
|
|
147
187
|
read={read}
|
|
148
188
|
isMutedPending={isMutedPending}
|
|
189
|
+
isHiddenPending={isHiddenPending}
|
|
149
190
|
isMarkReadPending={isMarkReadPending}
|
|
150
191
|
/>
|
|
151
192
|
)}
|
|
@@ -153,6 +194,7 @@ export function ConversationActions({
|
|
|
153
194
|
<Pressable
|
|
154
195
|
testID={`conversation-${conversation.id}`}
|
|
155
196
|
onPress={handlePress}
|
|
197
|
+
onLongPress={canHide ? handleLongPress : undefined}
|
|
156
198
|
style={({ pressed }) => [style, pressed && platformPressedOpacityStyle]}
|
|
157
199
|
android_ripple={{ color: androidRippleColor, borderless: false, foreground: true }}
|
|
158
200
|
accessibilityLabel={accessibilityLabel}
|
|
@@ -169,31 +211,44 @@ export function ConversationActions({
|
|
|
169
211
|
interface LeftActionsProps {
|
|
170
212
|
isConversationEmpty: boolean
|
|
171
213
|
canMute: boolean
|
|
214
|
+
canHide: boolean
|
|
172
215
|
handleMute: () => void
|
|
216
|
+
handleHide: () => void
|
|
173
217
|
handleLatestMessageUnread: () => void
|
|
174
218
|
muted: boolean
|
|
219
|
+
hidden: boolean
|
|
175
220
|
read: boolean
|
|
176
221
|
isMutedPending: boolean
|
|
222
|
+
isHiddenPending: boolean
|
|
177
223
|
isMarkReadPending: boolean
|
|
178
224
|
}
|
|
179
225
|
|
|
180
226
|
function LeftActions({
|
|
181
227
|
isConversationEmpty,
|
|
182
228
|
canMute,
|
|
229
|
+
canHide,
|
|
183
230
|
handleMute,
|
|
231
|
+
handleHide,
|
|
184
232
|
handleLatestMessageUnread,
|
|
185
233
|
muted,
|
|
234
|
+
hidden,
|
|
186
235
|
read,
|
|
187
236
|
isMutedPending,
|
|
237
|
+
isHiddenPending,
|
|
188
238
|
isMarkReadPending,
|
|
189
239
|
}: LeftActionsProps) {
|
|
190
|
-
const styles = useStyles({ actionButtonCount:
|
|
240
|
+
const styles = useStyles({ actionButtonCount: 1 + Number(canMute) + Number(canHide) })
|
|
191
241
|
|
|
192
242
|
const muteToggleContent = {
|
|
193
243
|
true: { iconName: 'general.bell', label: 'Enable' },
|
|
194
244
|
false: { iconName: 'general.bellMuted', label: 'Silence' },
|
|
195
245
|
} as const
|
|
196
246
|
|
|
247
|
+
const hideToggleContent = {
|
|
248
|
+
true: { iconName: 'general.showEye', label: 'Unhide' },
|
|
249
|
+
false: { iconName: 'general.hideEye', label: 'Hide' },
|
|
250
|
+
} as const
|
|
251
|
+
|
|
197
252
|
const latestMessageUnreadToggleContent = {
|
|
198
253
|
true: { iconName: 'general.outlinedTextMessage', label: 'Mark read' },
|
|
199
254
|
false: { iconName: 'general.textMessageNotifications', label: 'Mark unread' },
|
|
@@ -218,6 +273,15 @@ function LeftActions({
|
|
|
218
273
|
backgroundColor={tokens.fillColorInteractionSwipeSecondary}
|
|
219
274
|
/>
|
|
220
275
|
)}
|
|
276
|
+
{canHide && (
|
|
277
|
+
<SwipeableToggleButton
|
|
278
|
+
loading={isHiddenPending}
|
|
279
|
+
toggled={hidden}
|
|
280
|
+
onPress={handleHide}
|
|
281
|
+
toggleContent={hideToggleContent}
|
|
282
|
+
backgroundColor={tokens.colorNeutral45}
|
|
283
|
+
/>
|
|
284
|
+
)}
|
|
221
285
|
</View>
|
|
222
286
|
)
|
|
223
287
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { act, fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
4
|
+
import { dismissToast, showToast } from '../../../utils/toast_store'
|
|
5
|
+
import { Toast, TOAST_DURATION_MS } from '../toast'
|
|
6
|
+
|
|
7
|
+
const safeAreaMetrics = {
|
|
8
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
9
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const renderToast = () =>
|
|
13
|
+
render(
|
|
14
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
15
|
+
<Toast />
|
|
16
|
+
</SafeAreaProvider>
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
describe('Toast', () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.useFakeTimers()
|
|
22
|
+
dismissToast()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
jest.useRealTimers()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('runs the action and dismisses when the action is pressed', () => {
|
|
30
|
+
const onUndo = jest.fn()
|
|
31
|
+
const view = renderToast()
|
|
32
|
+
act(() =>
|
|
33
|
+
showToast({
|
|
34
|
+
title: 'Conversation hidden',
|
|
35
|
+
subtitle: 'Subtitle',
|
|
36
|
+
action: { label: 'Undo', onPress: onUndo },
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
expect(view.getByText('Subtitle')).toBeTruthy()
|
|
41
|
+
fireEvent.press(view.getByText('Undo'))
|
|
42
|
+
|
|
43
|
+
expect(onUndo).toHaveBeenCalledTimes(1)
|
|
44
|
+
expect(view.queryByText('Conversation hidden')).toBeNull()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('dismisses itself after a delay', () => {
|
|
48
|
+
const view = renderToast()
|
|
49
|
+
act(() => showToast({ title: 'Conversation hidden' }))
|
|
50
|
+
|
|
51
|
+
act(() => jest.advanceTimersByTime(TOAST_DURATION_MS))
|
|
52
|
+
|
|
53
|
+
expect(view.queryByText('Conversation hidden')).toBeNull()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React, { useEffect, useSyncExternalStore } from 'react'
|
|
2
|
+
import { AccessibilityInfo, StyleSheet, View } from 'react-native'
|
|
3
|
+
import Animated, { FadeInDown, FadeOutDown, ReduceMotion } from 'react-native-reanimated'
|
|
4
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
5
|
+
import { useReduceMotion, useTheme } from '../../hooks'
|
|
6
|
+
import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../utils/styles'
|
|
7
|
+
import { dismissToast, toastStore } from '../../utils/toast_store'
|
|
8
|
+
import { Text } from './text'
|
|
9
|
+
import { TextButton } from './text_button'
|
|
10
|
+
|
|
11
|
+
export const TOAST_DURATION_MS = 5000
|
|
12
|
+
|
|
13
|
+
export function Toast() {
|
|
14
|
+
const toast = useSyncExternalStore(toastStore.subscribe, toastStore.getSnapshot)
|
|
15
|
+
const styles = useStyles()
|
|
16
|
+
const reduceMotion = useReduceMotion() ? ReduceMotion.Always : ReduceMotion.Never
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!toast) return
|
|
20
|
+
|
|
21
|
+
AccessibilityInfo.announceForAccessibility(
|
|
22
|
+
[toast.title, toast.subtitle].filter(Boolean).join('. ')
|
|
23
|
+
)
|
|
24
|
+
const timeout = setTimeout(() => dismissToast(toast.id), TOAST_DURATION_MS)
|
|
25
|
+
return () => clearTimeout(timeout)
|
|
26
|
+
}, [toast])
|
|
27
|
+
|
|
28
|
+
useEffect(() => () => dismissToast(), [])
|
|
29
|
+
|
|
30
|
+
if (!toast) return null
|
|
31
|
+
|
|
32
|
+
const { id, title, subtitle, action } = toast
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View style={styles.container} pointerEvents="box-none">
|
|
36
|
+
<Animated.View
|
|
37
|
+
key={id}
|
|
38
|
+
entering={FadeInDown.duration(200).reduceMotion(reduceMotion)}
|
|
39
|
+
exiting={FadeOutDown.duration(200).reduceMotion(reduceMotion)}
|
|
40
|
+
style={styles.toast}
|
|
41
|
+
accessibilityLiveRegion="polite"
|
|
42
|
+
testID="toast"
|
|
43
|
+
>
|
|
44
|
+
<View style={styles.content}>
|
|
45
|
+
<Text
|
|
46
|
+
style={styles.title}
|
|
47
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
48
|
+
accessibilityRole="alert"
|
|
49
|
+
>
|
|
50
|
+
{title}
|
|
51
|
+
</Text>
|
|
52
|
+
{Boolean(subtitle) && (
|
|
53
|
+
<Text
|
|
54
|
+
variant="footnote"
|
|
55
|
+
style={styles.subtitle}
|
|
56
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
57
|
+
>
|
|
58
|
+
{subtitle}
|
|
59
|
+
</Text>
|
|
60
|
+
)}
|
|
61
|
+
</View>
|
|
62
|
+
{action && (
|
|
63
|
+
<TextButton
|
|
64
|
+
textStyle={styles.actionText}
|
|
65
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
66
|
+
onPress={() => {
|
|
67
|
+
dismissToast(id)
|
|
68
|
+
action.onPress()
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
{action.label}
|
|
72
|
+
</TextButton>
|
|
73
|
+
)}
|
|
74
|
+
</Animated.View>
|
|
75
|
+
</View>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const useStyles = () => {
|
|
80
|
+
const { colors } = useTheme()
|
|
81
|
+
const { bottom } = useSafeAreaInsets()
|
|
82
|
+
|
|
83
|
+
return StyleSheet.create({
|
|
84
|
+
container: {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
left: 0,
|
|
87
|
+
right: 0,
|
|
88
|
+
bottom: bottom + 16,
|
|
89
|
+
paddingHorizontal: 16,
|
|
90
|
+
},
|
|
91
|
+
toast: {
|
|
92
|
+
flexDirection: 'row',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
gap: 16,
|
|
95
|
+
paddingVertical: 12,
|
|
96
|
+
paddingHorizontal: 16,
|
|
97
|
+
borderRadius: 8,
|
|
98
|
+
backgroundColor: colors.fillColorNeutral010,
|
|
99
|
+
},
|
|
100
|
+
content: {
|
|
101
|
+
flex: 1,
|
|
102
|
+
gap: 2,
|
|
103
|
+
},
|
|
104
|
+
title: {
|
|
105
|
+
color: colors.fillColorNeutral100Inverted,
|
|
106
|
+
fontWeight: '600',
|
|
107
|
+
},
|
|
108
|
+
subtitle: {
|
|
109
|
+
color: colors.fillColorNeutral070,
|
|
110
|
+
},
|
|
111
|
+
actionText: {
|
|
112
|
+
color: colors.fillColorNeutral100Inverted,
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
}
|
|
@@ -33,7 +33,10 @@ interface GroupConversationsProps extends Partial<ConversationRequestArgs> {
|
|
|
33
33
|
*/
|
|
34
34
|
export const GroupConversations = ({ chat_group_graph_id, ...rest }: GroupConversationsProps) => {
|
|
35
35
|
return (
|
|
36
|
-
<ConversationsContextProvider
|
|
36
|
+
<ConversationsContextProvider
|
|
37
|
+
args={{ chat_group_graph_id, group_source_app_name: undefined }}
|
|
38
|
+
hideable={false}
|
|
39
|
+
>
|
|
37
40
|
<GroupConversationList {...rest} />
|
|
38
41
|
</ConversationsContextProvider>
|
|
39
42
|
)
|
|
@@ -14,6 +14,7 @@ interface ConversationsContextValue extends UseConversationsValue {
|
|
|
14
14
|
activeConversationId?: number
|
|
15
15
|
setActiveConversationId: (_id: number) => void
|
|
16
16
|
args: ConversationFiltersParams
|
|
17
|
+
hideable: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const defaultQueryValue: UseConversationsValue = {
|
|
@@ -33,6 +34,7 @@ const ConversationsContext = createContext<ConversationsContextValue>({
|
|
|
33
34
|
args: {},
|
|
34
35
|
activeConversationId: undefined,
|
|
35
36
|
setActiveConversationId: () => {},
|
|
37
|
+
hideable: true,
|
|
36
38
|
...defaultQueryValue,
|
|
37
39
|
})
|
|
38
40
|
|
|
@@ -40,9 +42,11 @@ export const ConversationsContextProvider = ({
|
|
|
40
42
|
children,
|
|
41
43
|
args = {},
|
|
42
44
|
opts: paginatorOptions,
|
|
45
|
+
hideable = true,
|
|
43
46
|
}: PropsWithChildren<{
|
|
44
47
|
args: ConversationFiltersParams
|
|
45
48
|
opts?: ApiGetQueryOptions
|
|
49
|
+
hideable?: boolean
|
|
46
50
|
}>) => {
|
|
47
51
|
const [activeConversationId, setActiveConversationId] = useState<number | undefined>()
|
|
48
52
|
const {
|
|
@@ -69,9 +73,10 @@ export const ConversationsContextProvider = ({
|
|
|
69
73
|
args,
|
|
70
74
|
activeConversationId,
|
|
71
75
|
setActiveConversationId,
|
|
76
|
+
hideable,
|
|
72
77
|
...query,
|
|
73
78
|
}),
|
|
74
|
-
[args, activeConversationId, query]
|
|
79
|
+
[args, activeConversationId, hideable, query]
|
|
75
80
|
)
|
|
76
81
|
|
|
77
82
|
return <ConversationsContext.Provider value={value}>{children}</ConversationsContext.Provider>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Alert } from 'react-native'
|
|
5
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
6
|
+
import type { ConversationResource } from '../../types'
|
|
7
|
+
import { getConversationsRequestArgs } from '../../utils/request/conversation'
|
|
8
|
+
import { dismissToast, toastStore } from '../../utils/toast_store'
|
|
9
|
+
import { getConversationRequestArgs } from '../use_conversation'
|
|
10
|
+
import {
|
|
11
|
+
HIDDEN_AND_SILENCED_TOAST_SUBTITLE,
|
|
12
|
+
HIDDEN_TOAST_SUBTITLE,
|
|
13
|
+
useHideConversation,
|
|
14
|
+
} from '../use_hide_conversation'
|
|
15
|
+
import { getRequestQueryKey } from '../use_suspense_api'
|
|
16
|
+
|
|
17
|
+
const mockPatch = jest.fn()
|
|
18
|
+
jest.mock('../use_api_client', () => ({
|
|
19
|
+
useApiClient: () => ({ chat: { patch: mockPatch } }),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
const conversation = { id: 7, muted: false } as ConversationResource
|
|
23
|
+
const otherConversation = { id: 8, muted: false } as ConversationResource
|
|
24
|
+
const conversationKey = getRequestQueryKey(getConversationRequestArgs({ conversation_id: 7 }))
|
|
25
|
+
const allKey = getRequestQueryKey(getConversationsRequestArgs({ gids: 'all' }))
|
|
26
|
+
const unreadKey = getRequestQueryKey(
|
|
27
|
+
getConversationsRequestArgs({ gids: 'all', show_unread: true })
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const listData = (conversations: ConversationResource[]) => ({
|
|
31
|
+
pages: [{ data: conversations, links: {}, meta: { count: conversations.length } }],
|
|
32
|
+
pageParams: [{}],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const listIds = (queryKey: unknown[]) =>
|
|
36
|
+
(
|
|
37
|
+
queryClient.getQueryData(queryKey) as ReturnType<typeof listData> | undefined
|
|
38
|
+
)?.pages[0].data.map(({ id }) => id)
|
|
39
|
+
|
|
40
|
+
const buildQueryClient = () =>
|
|
41
|
+
buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
42
|
+
|
|
43
|
+
let queryClient = buildQueryClient()
|
|
44
|
+
|
|
45
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
46
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const renderHide = (target: ConversationResource = conversation) =>
|
|
50
|
+
renderHook(() => useHideConversation({ conversation: target }), { wrapper })
|
|
51
|
+
|
|
52
|
+
describe('useHideConversation', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
queryClient = buildQueryClient()
|
|
55
|
+
queryClient.setQueryData(allKey, listData([conversation, otherConversation]))
|
|
56
|
+
queryClient.setQueryData(unreadKey, listData([conversation]))
|
|
57
|
+
queryClient.setQueryData(conversationKey, {
|
|
58
|
+
data: { id: 7, conversationMembership: { muted: false } },
|
|
59
|
+
})
|
|
60
|
+
mockPatch.mockReset()
|
|
61
|
+
dismissToast()
|
|
62
|
+
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
jest.restoreAllMocks()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('removes the conversation from every list before the request resolves', async () => {
|
|
70
|
+
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
71
|
+
const { result } = renderHide()
|
|
72
|
+
|
|
73
|
+
await act(async () => result.current.setHidden(true))
|
|
74
|
+
|
|
75
|
+
expect(listIds(allKey)).toEqual([8])
|
|
76
|
+
expect(listIds(unreadKey)).toEqual([])
|
|
77
|
+
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
78
|
+
data: { id: 7, conversationMembership: { muted: false, hidden: true } },
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('patches hidden on the membership', async () => {
|
|
83
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
84
|
+
const { result } = renderHide()
|
|
85
|
+
|
|
86
|
+
await act(() => result.current.mutateAsync(true))
|
|
87
|
+
|
|
88
|
+
expect(mockPatch).toHaveBeenCalledWith({
|
|
89
|
+
url: '/me/conversations/7/conversation_membership',
|
|
90
|
+
data: {
|
|
91
|
+
data: { type: 'ConversationMembership', attributes: { hidden: true } },
|
|
92
|
+
fields: { ConversationMembership: 'hidden' },
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it.each([
|
|
98
|
+
[false, HIDDEN_TOAST_SUBTITLE],
|
|
99
|
+
[true, HIDDEN_AND_SILENCED_TOAST_SUBTITLE],
|
|
100
|
+
])('shows an undo toast for muted=%s', async (muted, subtitle) => {
|
|
101
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
102
|
+
const { result } = renderHide({ ...conversation, muted })
|
|
103
|
+
|
|
104
|
+
await act(() => result.current.mutateAsync(true))
|
|
105
|
+
|
|
106
|
+
expect(toastStore.getSnapshot()).toMatchObject({
|
|
107
|
+
title: 'Conversation hidden',
|
|
108
|
+
subtitle,
|
|
109
|
+
action: { label: 'Undo' },
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('restores the lists and unhides on undo', async () => {
|
|
114
|
+
mockPatch.mockResolvedValue({ data: {} })
|
|
115
|
+
const { result } = renderHide()
|
|
116
|
+
await act(() => result.current.mutateAsync(true))
|
|
117
|
+
|
|
118
|
+
await act(async () => toastStore.getSnapshot()?.action?.onPress())
|
|
119
|
+
|
|
120
|
+
expect(listIds(allKey)).toEqual([7, 8])
|
|
121
|
+
expect(listIds(unreadKey)).toEqual([7])
|
|
122
|
+
expect(mockPatch).toHaveBeenLastCalledWith(
|
|
123
|
+
expect.objectContaining({
|
|
124
|
+
data: expect.objectContaining({
|
|
125
|
+
data: { type: 'ConversationMembership', attributes: { hidden: false } },
|
|
126
|
+
}),
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('puts the conversation back and alerts when hiding fails', async () => {
|
|
132
|
+
mockPatch.mockRejectedValue(new Error('nope'))
|
|
133
|
+
const { result } = renderHide()
|
|
134
|
+
|
|
135
|
+
await act(() => result.current.mutateAsync(true).catch(() => {}))
|
|
136
|
+
|
|
137
|
+
expect(listIds(allKey)).toEqual([7, 8])
|
|
138
|
+
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
139
|
+
data: { id: 7, conversationMembership: { muted: false, hidden: false } },
|
|
140
|
+
})
|
|
141
|
+
expect(toastStore.getSnapshot()).toBeNull()
|
|
142
|
+
expect(Alert.alert).toHaveBeenCalledWith(
|
|
143
|
+
'Oops',
|
|
144
|
+
"Couldn't hide this conversation. Please try again."
|
|
145
|
+
)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
@@ -61,6 +61,7 @@ export const availableFeatures = {
|
|
|
61
61
|
filter_dropdown_rollout: 'ROLLOUT_MOBILE_filter_dropdown',
|
|
62
62
|
manual_archiving: 'QA_MOBILE_manual_archiving',
|
|
63
63
|
manual_archiving_rollout: 'ROLLOUT_MOBILE_manual_archiving',
|
|
64
|
+
hide_conversations: 'ROLLOUT_hide_conversations',
|
|
64
65
|
} as const satisfies Record<string, `${'QA' | 'ROLLOUT'}_${string}`>
|
|
65
66
|
|
|
66
67
|
const featureNames = Object.values(availableFeatures)
|