@planningcenter/chat-react-native 4.8.0-rc.8 → 4.8.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/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +31 -25
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversations/app_update_banner.d.ts +2 -0
- package/build/components/conversations/app_update_banner.d.ts.map +1 -0
- package/build/components/conversations/app_update_banner.js +52 -0
- package/build/components/conversations/app_update_banner.js.map +1 -0
- 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 +215 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +202 -161
- 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/conversations/swipeable_toggle_button.d.ts +5 -1
- package/build/components/conversations/swipeable_toggle_button.d.ts.map +1 -1
- package/build/components/conversations/swipeable_toggle_button.js +96 -67
- package/build/components/conversations/swipeable_toggle_button.js.map +1 -1
- package/build/components/display/icon.d.ts +3 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +2 -0
- package/build/components/display/icon.js.map +1 -1
- package/build/components/primitive/banner_primitive.js +7 -3
- package/build/components/primitive/banner_primitive.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 +105 -33
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/utils/native_adapters/configuration.d.ts +3 -0
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +3 -0
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/updates.d.ts +11 -0
- package/build/utils/native_adapters/updates.d.ts.map +1 -0
- package/build/utils/native_adapters/updates.js +8 -0
- package/build/utils/native_adapters/updates.js.map +1 -0
- package/build/utils/theme.js +20 -21
- package/build/utils/theme.js.map +1 -1
- package/package.json +2 -2
- package/src/components/conversation/__tests__/message_form.test.tsx +19 -2
- package/src/components/conversation/message_form.tsx +15 -2
- package/src/components/conversations/__tests__/app_update_banner.test.tsx +27 -0
- package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +10 -3
- package/src/components/conversations/app_update_banner.tsx +36 -0
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +140 -0
- package/src/components/conversations/conversation_actions.tsx +51 -34
- package/src/components/conversations/conversation_preview.tsx +8 -1
- package/src/components/conversations/swipeable_toggle_button.tsx +45 -16
- package/src/components/display/icon.tsx +3 -0
- package/src/components/primitive/banner_primitive.tsx +5 -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 +34 -8
- package/src/screens/conversations/conversations_screen.tsx +28 -2
- package/src/utils/native_adapters/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/updates.ts +16 -0
- package/src/utils/theme.ts +20 -21
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import ReanimatedSwipeable, {
|
|
13
13
|
SwipeableMethods,
|
|
14
14
|
} from 'react-native-gesture-handler/ReanimatedSwipeable'
|
|
15
|
+
import Animated, { SharedValue, useAnimatedStyle } from 'react-native-reanimated'
|
|
15
16
|
import { useConversationsContext } from '../../contexts/conversations_context'
|
|
16
17
|
import { useTheme, useCreateAndroidRippleColor } from '../../hooks'
|
|
17
18
|
import {
|
|
@@ -24,7 +25,7 @@ import { ConversationResource } from '../../types'
|
|
|
24
25
|
import { isArchivedConversation, platformPressedOpacityStyle } from '../../utils'
|
|
25
26
|
import { Haptic } from '../../utils/native_adapters'
|
|
26
27
|
import { tokens } from '../../vendor/tapestry/tokens'
|
|
27
|
-
import { SwipeableToggleButton } from './swipeable_toggle_button'
|
|
28
|
+
import { SWIPEABLE_TOGGLE_BUTTON_WIDTH, SwipeableToggleButton } from './swipeable_toggle_button'
|
|
28
29
|
|
|
29
30
|
export function ConversationActions({
|
|
30
31
|
children,
|
|
@@ -70,6 +71,7 @@ export function ConversationActions({
|
|
|
70
71
|
const canMute = !isArchivedConversation(conversation)
|
|
71
72
|
const canHide = hideable && hideConversationsEnabled && !isArchivedConversation(conversation)
|
|
72
73
|
const selectMode = selected !== undefined
|
|
74
|
+
const canOpenActions = hideable && hideConversationsEnabled && !selectMode
|
|
73
75
|
|
|
74
76
|
const handleSwipeableClose = useCallback(() => {
|
|
75
77
|
setDisabled(false)
|
|
@@ -100,8 +102,8 @@ export function ConversationActions({
|
|
|
100
102
|
if (disabled) return
|
|
101
103
|
|
|
102
104
|
Haptic.impactLight()
|
|
103
|
-
navigation.navigate('ConversationActions', { conversation_id: conversation.id })
|
|
104
|
-
}, [disabled, navigation, conversation.id])
|
|
105
|
+
navigation.navigate('ConversationActions', { conversation_id: conversation.id, read, muted })
|
|
106
|
+
}, [disabled, navigation, conversation.id, read, muted])
|
|
105
107
|
|
|
106
108
|
const handleLatestMessageUnread = useCallback(() => {
|
|
107
109
|
markRead(!read)
|
|
@@ -185,8 +187,10 @@ export function ConversationActions({
|
|
|
185
187
|
onSwipeableOpenStartDrag={handleSwipeableOpen}
|
|
186
188
|
onSwipeableClose={() => setDisabled(false)}
|
|
187
189
|
renderRightActions={() => <></>}
|
|
188
|
-
renderLeftActions={() => (
|
|
190
|
+
renderLeftActions={(progress, translation) => (
|
|
189
191
|
<LeftActions
|
|
192
|
+
progress={progress}
|
|
193
|
+
translation={translation}
|
|
190
194
|
isConversationEmpty={isConversationEmpty}
|
|
191
195
|
canMute={canMute}
|
|
192
196
|
canHide={canHide}
|
|
@@ -205,7 +209,7 @@ export function ConversationActions({
|
|
|
205
209
|
<Pressable
|
|
206
210
|
testID={`conversation-${conversation.id}`}
|
|
207
211
|
onPress={handlePress}
|
|
208
|
-
onLongPress={
|
|
212
|
+
onLongPress={canOpenActions ? handleLongPress : undefined}
|
|
209
213
|
style={({ pressed }) => [style, pressed && platformPressedOpacityStyle]}
|
|
210
214
|
android_ripple={{ color: androidRippleColor, borderless: false, foreground: true }}
|
|
211
215
|
accessibilityLabel={accessibilityLabel}
|
|
@@ -221,6 +225,8 @@ export function ConversationActions({
|
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
interface LeftActionsProps {
|
|
228
|
+
progress: SharedValue<number>
|
|
229
|
+
translation: SharedValue<number>
|
|
224
230
|
isConversationEmpty: boolean
|
|
225
231
|
canMute: boolean
|
|
226
232
|
canHide: boolean
|
|
@@ -236,6 +242,8 @@ interface LeftActionsProps {
|
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
function LeftActions({
|
|
245
|
+
progress,
|
|
246
|
+
translation,
|
|
239
247
|
isConversationEmpty,
|
|
240
248
|
canMute,
|
|
241
249
|
canHide,
|
|
@@ -250,6 +258,9 @@ function LeftActions({
|
|
|
250
258
|
isMarkReadPending,
|
|
251
259
|
}: LeftActionsProps) {
|
|
252
260
|
const styles = useStyles({ actionButtonCount: 1 + Number(canMute) + Number(canHide) })
|
|
261
|
+
// The buttons split whatever the drag has uncovered, so every action is on screen from the
|
|
262
|
+
// first few points and grows with the drag, instead of the last one waiting for a full open.
|
|
263
|
+
const revealStyle = useAnimatedStyle(() => ({ width: Math.max(translation.value, 0) }))
|
|
253
264
|
|
|
254
265
|
const muteToggleContent = {
|
|
255
266
|
true: { iconName: 'general.bell', label: 'Enable' },
|
|
@@ -268,38 +279,41 @@ function LeftActions({
|
|
|
268
279
|
|
|
269
280
|
return (
|
|
270
281
|
<View style={styles.actionButtonContainer}>
|
|
271
|
-
<
|
|
272
|
-
loading={isMarkReadPending}
|
|
273
|
-
disabled={isConversationEmpty}
|
|
274
|
-
toggled={!read}
|
|
275
|
-
onPress={handleLatestMessageUnread}
|
|
276
|
-
toggleContent={latestMessageUnreadToggleContent}
|
|
277
|
-
backgroundColor={tokens.fillColorInteractionSwipeDefault}
|
|
278
|
-
/>
|
|
279
|
-
{canMute && (
|
|
282
|
+
<Animated.View style={[styles.actionButtonReveal, revealStyle]}>
|
|
280
283
|
<SwipeableToggleButton
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
progress={progress}
|
|
285
|
+
loading={isMarkReadPending}
|
|
286
|
+
disabled={isConversationEmpty}
|
|
287
|
+
toggled={!read}
|
|
288
|
+
onPress={handleLatestMessageUnread}
|
|
289
|
+
toggleContent={latestMessageUnreadToggleContent}
|
|
290
|
+
backgroundColor={tokens.fillColorInteractionSwipeDefault}
|
|
286
291
|
/>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
292
|
+
{canMute && (
|
|
293
|
+
<SwipeableToggleButton
|
|
294
|
+
progress={progress}
|
|
295
|
+
loading={isMutedPending}
|
|
296
|
+
toggled={muted}
|
|
297
|
+
onPress={handleMute}
|
|
298
|
+
toggleContent={muteToggleContent}
|
|
299
|
+
backgroundColor={tokens.fillColorInteractionSwipeSecondary}
|
|
300
|
+
/>
|
|
301
|
+
)}
|
|
302
|
+
{canHide && (
|
|
303
|
+
<SwipeableToggleButton
|
|
304
|
+
progress={progress}
|
|
305
|
+
loading={isHiddenPending}
|
|
306
|
+
toggled={hidden}
|
|
307
|
+
onPress={handleHide}
|
|
308
|
+
toggleContent={hideToggleContent}
|
|
309
|
+
backgroundColor={tokens.colorNeutral45}
|
|
310
|
+
/>
|
|
311
|
+
)}
|
|
312
|
+
</Animated.View>
|
|
297
313
|
</View>
|
|
298
314
|
)
|
|
299
315
|
}
|
|
300
316
|
|
|
301
|
-
const ACTION_BUTTON_WIDTH = 120
|
|
302
|
-
|
|
303
317
|
const useStyles = ({ actionButtonCount = 2 }: { actionButtonCount?: number } = {}) => {
|
|
304
318
|
const { colors } = useTheme()
|
|
305
319
|
return StyleSheet.create({
|
|
@@ -307,10 +321,13 @@ const useStyles = ({ actionButtonCount = 2 }: { actionButtonCount?: number } = {
|
|
|
307
321
|
backgroundColor: colors.conversationActionsBackground,
|
|
308
322
|
},
|
|
309
323
|
actionButtonContainer: {
|
|
324
|
+
// Fixed at the fully open width: the swipeable measures this to find its snap point.
|
|
325
|
+
width: SWIPEABLE_TOGGLE_BUTTON_WIDTH * actionButtonCount,
|
|
326
|
+
height: '100%',
|
|
327
|
+
},
|
|
328
|
+
actionButtonReveal: {
|
|
310
329
|
flexDirection: 'row',
|
|
311
|
-
|
|
312
|
-
width: ACTION_BUTTON_WIDTH * actionButtonCount,
|
|
313
|
-
alignContent: 'stretch',
|
|
330
|
+
height: '100%',
|
|
314
331
|
},
|
|
315
332
|
swipeableContainer: {
|
|
316
333
|
backgroundColor: colors.surfaceColor090,
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useFontScale,
|
|
8
8
|
useScalableNumberOfLines,
|
|
9
9
|
} from '../../hooks'
|
|
10
|
+
import { useSelectedChipBackgroundColor } from '../../hooks/use_selected_chip_background_color'
|
|
10
11
|
import { ConversationPreviewData, ConversationResource } from '../../types'
|
|
11
12
|
import { REACTION_EMOJIS, isArchivedConversation, platformFontWeightBold } from '../../utils'
|
|
12
13
|
import { formatDatePreview } from '../../utils/date'
|
|
@@ -67,6 +68,7 @@ export const ConversationPreview = ({
|
|
|
67
68
|
const hasMetaContent = lastMessageCreatedAt || unreadCount > 0 || muted || hidden
|
|
68
69
|
const isUnread = unreadCount > 0 || unreadReaction
|
|
69
70
|
const selected = selectMode ? selectedIds.includes(id) : undefined
|
|
71
|
+
const selectedBackgroundColor = useSelectedChipBackgroundColor()
|
|
70
72
|
|
|
71
73
|
const numberOfLinesScaledTitle = useScalableNumberOfLines(1)
|
|
72
74
|
const numberOfLinesScaledPreviewText = useScalableNumberOfLines(2)
|
|
@@ -85,7 +87,12 @@ export const ConversationPreview = ({
|
|
|
85
87
|
return (
|
|
86
88
|
<ConversationActions
|
|
87
89
|
conversation={conversation}
|
|
88
|
-
style={[
|
|
90
|
+
style={[
|
|
91
|
+
styles.previewRow,
|
|
92
|
+
disabled && !archived && styles.disabled,
|
|
93
|
+
selected && { backgroundColor: selectedBackgroundColor },
|
|
94
|
+
style,
|
|
95
|
+
]}
|
|
89
96
|
onPress={selectMode ? () => toggleSelected(id) : onPress}
|
|
90
97
|
accessibilityLabel={conversationAccessibilityLabel}
|
|
91
98
|
selected={selected}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { StyleSheet } from 'react-native'
|
|
2
|
+
import { StyleSheet, View } from 'react-native'
|
|
3
3
|
import { Pressable, type PressableProps } from 'react-native-gesture-handler'
|
|
4
|
+
import Animated, {
|
|
5
|
+
Extrapolation,
|
|
6
|
+
SharedValue,
|
|
7
|
+
interpolate,
|
|
8
|
+
useAnimatedStyle,
|
|
9
|
+
} from 'react-native-reanimated'
|
|
4
10
|
import { useCreateAndroidRippleColor, useTheme } from '../../hooks'
|
|
5
11
|
import { Haptic } from '../../utils/native_adapters/configuration'
|
|
6
12
|
import {
|
|
@@ -11,8 +17,12 @@ import {
|
|
|
11
17
|
import { tokens } from '../../vendor/tapestry/tokens'
|
|
12
18
|
import { Icon, IconString, Spinner, Text } from '../display'
|
|
13
19
|
|
|
20
|
+
export const SWIPEABLE_TOGGLE_BUTTON_WIDTH = 120
|
|
21
|
+
|
|
14
22
|
interface SwipeableToggleButtonProps extends PressableProps {
|
|
15
23
|
backgroundColor: string
|
|
24
|
+
/** How far the swipe is open, 0 (closed) to 1 (fully open). */
|
|
25
|
+
progress: SharedValue<number>
|
|
16
26
|
toggled: boolean
|
|
17
27
|
toggleContent: {
|
|
18
28
|
true: { iconName: IconString; label: string }
|
|
@@ -24,6 +34,7 @@ interface SwipeableToggleButtonProps extends PressableProps {
|
|
|
24
34
|
export function SwipeableToggleButton({
|
|
25
35
|
backgroundColor,
|
|
26
36
|
onPress,
|
|
37
|
+
progress,
|
|
27
38
|
toggleContent,
|
|
28
39
|
disabled = false,
|
|
29
40
|
toggled,
|
|
@@ -37,6 +48,13 @@ export function SwipeableToggleButton({
|
|
|
37
48
|
|
|
38
49
|
const { iconName, label } = toggleContent[toggled ? 'true' : 'false']
|
|
39
50
|
|
|
51
|
+
const iconStyle = useAnimatedStyle(() => ({
|
|
52
|
+
transform: [{ scale: interpolate(progress.value, [0, 1], [0.7, 1], Extrapolation.CLAMP) }],
|
|
53
|
+
}))
|
|
54
|
+
const labelStyle = useAnimatedStyle(() => ({
|
|
55
|
+
opacity: interpolate(progress.value, [0.5, 1], [0, 1], Extrapolation.CLAMP),
|
|
56
|
+
}))
|
|
57
|
+
|
|
40
58
|
return (
|
|
41
59
|
<Pressable
|
|
42
60
|
onPress={event => {
|
|
@@ -53,20 +71,24 @@ export function SwipeableToggleButton({
|
|
|
53
71
|
{loading ? (
|
|
54
72
|
<Spinner size={20} />
|
|
55
73
|
) : (
|
|
56
|
-
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
<View style={styles.content}>
|
|
75
|
+
<Animated.View style={iconStyle}>
|
|
76
|
+
<Icon
|
|
77
|
+
name={iconName}
|
|
78
|
+
style={styles.icon}
|
|
79
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
|
|
80
|
+
/>
|
|
81
|
+
</Animated.View>
|
|
82
|
+
<Animated.View style={labelStyle}>
|
|
83
|
+
<Text
|
|
84
|
+
variant="footnote"
|
|
85
|
+
style={styles.text}
|
|
86
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
|
|
87
|
+
>
|
|
88
|
+
{label}
|
|
89
|
+
</Text>
|
|
90
|
+
</Animated.View>
|
|
91
|
+
</View>
|
|
70
92
|
)}
|
|
71
93
|
</Pressable>
|
|
72
94
|
)
|
|
@@ -85,10 +107,17 @@ const useStyles = ({ backgroundColor, disabled }: Partial<SwipeableToggleButtonP
|
|
|
85
107
|
flexDirection: 'column',
|
|
86
108
|
alignItems: 'center',
|
|
87
109
|
justifyContent: 'center',
|
|
88
|
-
gap: 4,
|
|
89
110
|
height: '100%',
|
|
111
|
+
overflow: 'hidden',
|
|
90
112
|
backgroundColor: buttonBackgroundColor,
|
|
91
113
|
},
|
|
114
|
+
// Laid out at the fully open width and clipped by the button, so the icon and label stay
|
|
115
|
+
// centered and never reflow while the button is narrower than that.
|
|
116
|
+
content: {
|
|
117
|
+
width: SWIPEABLE_TOGGLE_BUTTON_WIDTH,
|
|
118
|
+
alignItems: 'center',
|
|
119
|
+
gap: 4,
|
|
120
|
+
},
|
|
92
121
|
icon: {
|
|
93
122
|
fontSize: 20,
|
|
94
123
|
color: fillColor,
|
|
@@ -3,6 +3,7 @@ import * as api from '@planningcenter/icons/paths/api'
|
|
|
3
3
|
import * as brand from '@planningcenter/icons/paths/brand'
|
|
4
4
|
import * as calendar from '@planningcenter/icons/paths/calendar'
|
|
5
5
|
import * as chat from '@planningcenter/icons/paths/chat'
|
|
6
|
+
import * as checkIns from '@planningcenter/icons/paths/check-ins'
|
|
6
7
|
import * as churchCenter from '@planningcenter/icons/paths/church-center'
|
|
7
8
|
import * as general from '@planningcenter/icons/paths/general'
|
|
8
9
|
import * as groups from '@planningcenter/icons/paths/groups'
|
|
@@ -30,6 +31,7 @@ const ICONS = {
|
|
|
30
31
|
brand,
|
|
31
32
|
calendar,
|
|
32
33
|
chat,
|
|
34
|
+
checkIns,
|
|
33
35
|
churchCenter,
|
|
34
36
|
general,
|
|
35
37
|
groups,
|
|
@@ -55,6 +57,7 @@ export type IconString =
|
|
|
55
57
|
| `brand.${IconName<'brand'>}`
|
|
56
58
|
| `calendar.${IconName<'calendar'>}`
|
|
57
59
|
| `chat.${IconName<'chat'>}`
|
|
60
|
+
| `checkIns.${IconName<'checkIns'>}`
|
|
58
61
|
| `churchCenter.${IconName<'churchCenter'>}`
|
|
59
62
|
| `general.${IconName<'general'>}`
|
|
60
63
|
| `groups.${IconName<'groups'>}`
|
|
@@ -249,7 +249,7 @@ function BannerLink({ children, onPress }: BannerLinkProps) {
|
|
|
249
249
|
const styles = useStyles({ appearance })
|
|
250
250
|
|
|
251
251
|
return (
|
|
252
|
-
<TextInlineButton variant="tertiary" style={styles.
|
|
252
|
+
<TextInlineButton variant="tertiary" style={styles.link} onPress={onPress}>
|
|
253
253
|
{children}
|
|
254
254
|
</TextInlineButton>
|
|
255
255
|
)
|
|
@@ -295,5 +295,9 @@ const useStyles = ({ appearance = 'neutral' }: Styles = {}) => {
|
|
|
295
295
|
text: {
|
|
296
296
|
color: statusColorMap[appearance].text,
|
|
297
297
|
},
|
|
298
|
+
link: {
|
|
299
|
+
color: statusColorMap[appearance].text,
|
|
300
|
+
textDecorationColor: statusColorMap[appearance].text,
|
|
301
|
+
},
|
|
298
302
|
})
|
|
299
303
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
1
|
+
import { DefaultTheme, StackActions, ThemeProvider } from '@react-navigation/native'
|
|
2
2
|
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
5
5
|
import type { ConversationResource } from '../../types'
|
|
6
6
|
import { ConversationActionsScreen } from '../conversation_actions_screen'
|
|
7
7
|
|
|
8
|
-
const mockNavigation = { goBack: jest.fn() }
|
|
8
|
+
const mockNavigation = { goBack: jest.fn(), dispatch: jest.fn(), navigate: jest.fn() }
|
|
9
9
|
jest.mock('@react-navigation/native', () => ({
|
|
10
10
|
...jest.requireActual('@react-navigation/native'),
|
|
11
11
|
useNavigation: () => mockNavigation,
|
|
@@ -15,9 +15,20 @@ jest.mock('@react-navigation/elements', () => ({
|
|
|
15
15
|
useHeaderHeight: () => 0,
|
|
16
16
|
}))
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
let mockConversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
|
|
19
|
+
const mockSetMuted = jest.fn()
|
|
19
20
|
jest.mock('../../hooks/use_conversation', () => ({
|
|
20
|
-
useConversation: () => ({ data:
|
|
21
|
+
useConversation: () => ({ data: mockConversation }),
|
|
22
|
+
useConversationMute: () => ({ muted: false, setMuted: mockSetMuted, isPending: false }),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const mockMarkRead = jest.fn()
|
|
26
|
+
jest.mock('../../hooks/use_conversations_actions', () => ({
|
|
27
|
+
useConversationsMarkRead: () => ({ read: true, markRead: mockMarkRead, isPending: false }),
|
|
28
|
+
}))
|
|
29
|
+
jest.mock('../../components/display', () => ({
|
|
30
|
+
...jest.requireActual('../../components/display'),
|
|
31
|
+
ConversationAvatar: () => null,
|
|
21
32
|
}))
|
|
22
33
|
|
|
23
34
|
let mockHidden = false
|
|
@@ -36,11 +47,11 @@ const safeAreaMetrics = {
|
|
|
36
47
|
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
const renderScreen = () =>
|
|
50
|
+
const renderScreen = (params: { read?: boolean; muted?: boolean } = {}) =>
|
|
40
51
|
render(
|
|
41
52
|
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
42
53
|
<ThemeProvider value={DefaultTheme}>
|
|
43
|
-
<ConversationActionsScreen route={{ params: { conversation_id: 7 } }} />
|
|
54
|
+
<ConversationActionsScreen route={{ params: { conversation_id: 7, ...params } }} />
|
|
44
55
|
</ThemeProvider>
|
|
45
56
|
</SafeAreaProvider>
|
|
46
57
|
)
|
|
@@ -49,6 +60,7 @@ describe('ConversationActionsScreen', () => {
|
|
|
49
60
|
beforeEach(() => {
|
|
50
61
|
mockHidden = false
|
|
51
62
|
mockHideEnabled = true
|
|
63
|
+
mockConversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
|
|
52
64
|
jest.clearAllMocks()
|
|
53
65
|
})
|
|
54
66
|
|
|
@@ -57,6 +69,17 @@ describe('ConversationActionsScreen', () => {
|
|
|
57
69
|
const { queryByText } = renderScreen()
|
|
58
70
|
|
|
59
71
|
expect(queryByText('Hide conversation')).toBeNull()
|
|
72
|
+
expect(queryByText('Select conversations')).toBeNull()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('asks the conversation list to enter select mode with this conversation', () => {
|
|
76
|
+
const { getByText } = renderScreen()
|
|
77
|
+
|
|
78
|
+
fireEvent.press(getByText('Select conversations'))
|
|
79
|
+
|
|
80
|
+
expect(mockNavigation.dispatch).toHaveBeenCalledWith(
|
|
81
|
+
StackActions.popTo('Conversations', { select_conversation_id: 7 }, { merge: true })
|
|
82
|
+
)
|
|
60
83
|
})
|
|
61
84
|
|
|
62
85
|
it('hides the conversation and closes the sheet', () => {
|
|
@@ -76,4 +99,23 @@ describe('ConversationActionsScreen', () => {
|
|
|
76
99
|
|
|
77
100
|
expect(mockSetHidden).toHaveBeenCalledWith(false)
|
|
78
101
|
})
|
|
102
|
+
|
|
103
|
+
it('toggles read and silenced from the state the list row passed in', () => {
|
|
104
|
+
const { getByText } = renderScreen({ read: false, muted: true })
|
|
105
|
+
|
|
106
|
+
fireEvent.press(getByText('Mark as read'))
|
|
107
|
+
fireEvent.press(getByText('Enable'))
|
|
108
|
+
|
|
109
|
+
expect(mockMarkRead).toHaveBeenCalledWith(true)
|
|
110
|
+
expect(mockSetMuted).toHaveBeenCalledWith(false)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('offers neither silence nor hide on an archived conversation', () => {
|
|
114
|
+
mockConversation = { ...mockConversation, disabled: true, disabledReason: 'archived' }
|
|
115
|
+
const { queryByText, getByText } = renderScreen()
|
|
116
|
+
|
|
117
|
+
expect(queryByText('Silence')).toBeNull()
|
|
118
|
+
expect(queryByText('Hide conversation')).toBeNull()
|
|
119
|
+
expect(getByText('Select conversations')).toBeTruthy()
|
|
120
|
+
})
|
|
79
121
|
})
|
|
@@ -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 ? 'checkIns.checkPending' : 'checkIns.check'}
|
|
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
|
+
}
|