@planningcenter/chat-react-native 4.7.1-qa-staging.1 → 4.7.1-qa-1092.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 +193 -333
- 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 +91 -106
- 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 +56 -63
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/conversations/conversations_blank_state.d.ts +1 -2
- package/build/components/conversations/conversations_blank_state.d.ts.map +1 -1
- package/build/components/conversations/conversations_blank_state.js +39 -71
- package/build/components/conversations/conversations_blank_state.js.map +1 -1
- package/build/components/group_conversation_list.d.ts.map +1 -1
- package/build/components/group_conversation_list.js +0 -1
- package/build/components/group_conversation_list.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +1 -3
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +31 -39
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +0 -6
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/use_api.d.ts +0 -6
- package/build/hooks/use_api.d.ts.map +1 -1
- package/build/hooks/use_api.js +5 -8
- package/build/hooks/use_api.js.map +1 -1
- package/build/hooks/use_clear_conversation_filters.d.ts.map +1 -1
- package/build/hooks/use_clear_conversation_filters.js +0 -1
- package/build/hooks/use_clear_conversation_filters.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 +0 -1
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -2
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_groups.d.ts +0 -6
- package/build/hooks/use_groups.d.ts.map +1 -1
- package/build/hooks/use_groups_groups.d.ts +0 -6
- package/build/hooks/use_groups_groups.d.ts.map +1 -1
- package/build/hooks/use_teams.d.ts +0 -6
- package/build/hooks/use_teams.d.ts.map +1 -1
- package/build/navigation/index.d.ts +0 -5
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +0 -5
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +394 -460
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_filters/components/conversation_filters.d.ts.map +1 -1
- package/build/screens/conversation_filters/components/conversation_filters.js +12 -53
- package/build/screens/conversation_filters/components/conversation_filters.js.map +1 -1
- package/build/screens/conversation_filters/components/rows.d.ts +3 -6
- package/build/screens/conversation_filters/components/rows.d.ts.map +1 -1
- package/build/screens/conversation_filters/components/rows.js +62 -99
- package/build/screens/conversation_filters/components/rows.js.map +1 -1
- package/build/screens/conversation_filters/context/conversation_filter_context.d.ts.map +1 -1
- package/build/screens/conversation_filters/context/conversation_filter_context.js +0 -4
- package/build/screens/conversation_filters/context/conversation_filter_context.js.map +1 -1
- package/build/screens/conversation_filters/filter_types.d.ts +0 -1
- package/build/screens/conversation_filters/filter_types.d.ts.map +1 -1
- package/build/screens/conversation_filters/filter_types.js +0 -1
- package/build/screens/conversation_filters/filter_types.js.map +1 -1
- package/build/screens/conversation_filters/hooks/filters.d.ts +0 -12
- package/build/screens/conversation_filters/hooks/filters.d.ts.map +1 -1
- package/build/screens/conversation_filters/screen_props.d.ts +0 -1
- package/build/screens/conversation_filters/screen_props.d.ts.map +1 -1
- package/build/screens/conversation_filters/screen_props.js.map +1 -1
- package/build/screens/conversations/components/filter_dropdown_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/filter_dropdown_list_header_component.js +126 -138
- package/build/screens/conversations/components/filter_dropdown_list_header_component.js.map +1 -1
- package/build/screens/conversations/components/list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/list_header_component.js +90 -95
- package/build/screens/conversations/components/list_header_component.js.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.js +95 -100
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +0 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +10 -18
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/index.d.ts +0 -1
- package/build/screens/index.d.ts.map +1 -1
- package/build/screens/index.js +0 -1
- package/build/screens/index.js.map +1 -1
- package/build/types/resources/conversation_membership.d.ts +0 -1
- package/build/types/resources/conversation_membership.d.ts.map +1 -1
- package/build/types/resources/conversation_membership.js.map +1 -1
- package/build/utils/request/conversation.d.ts +1 -3
- package/build/utils/request/conversation.d.ts.map +1 -1
- package/build/utils/request/conversation.js +0 -4
- package/build/utils/request/conversation.js.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.d.ts +0 -1
- package/build/vendor/font_awesome_pro_solid_icons.d.ts.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.js +0 -5
- package/build/vendor/font_awesome_pro_solid_icons.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/screens/conversation_filters/components/conversation_filters.test.tsx +0 -6
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +2 -77
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +0 -29
- package/src/components/conversations/__tests__/conversations.test.tsx +0 -26
- package/src/components/conversations/__tests__/conversations_blank_state.test.tsx +0 -17
- package/src/components/conversations/conversation_actions.tsx +4 -73
- package/src/components/conversations/conversation_preview.tsx +1 -12
- package/src/components/conversations/conversations.tsx +0 -9
- package/src/components/conversations/conversations_blank_state.tsx +0 -18
- package/src/components/group_conversation_list.tsx +1 -4
- package/src/contexts/conversations_context.tsx +1 -8
- package/src/hooks/use_api.ts +1 -2
- package/src/hooks/use_clear_conversation_filters.ts +0 -1
- package/src/hooks/use_conversation.ts +0 -1
- package/src/hooks/use_features.ts +0 -1
- package/src/navigation/index.tsx +0 -8
- package/src/screens/__tests__/conversation_details_screen.test.tsx +1 -49
- package/src/screens/conversation_details_screen.tsx +0 -19
- package/src/screens/conversation_filters/__tests__/conversation_filters.test.tsx +0 -42
- package/src/screens/conversation_filters/components/conversation_filters.tsx +3 -22
- package/src/screens/conversation_filters/components/rows.tsx +10 -44
- package/src/screens/conversation_filters/context/conversation_filter_context.tsx +0 -4
- package/src/screens/conversation_filters/filter_types.ts +0 -1
- package/src/screens/conversation_filters/screen_props.ts +0 -1
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +0 -1
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -42
- package/src/screens/conversations/components/__tests__/list_header_component.test.tsx +0 -1
- package/src/screens/conversations/components/filter_dropdown_list_header_component.tsx +5 -21
- package/src/screens/conversations/components/list_header_component.tsx +4 -14
- package/src/screens/conversations/components/search_list_header_component.tsx +4 -14
- package/src/screens/conversations/conversations_screen.tsx +0 -3
- package/src/screens/index.ts +0 -1
- package/src/types/resources/conversation_membership.ts +0 -1
- package/src/utils/request/conversation.ts +0 -6
- package/src/vendor/font_awesome_pro_solid_icons.ts +0 -12
- package/build/components/conversations/hidden_indicator.d.ts +0 -4
- package/build/components/conversations/hidden_indicator.d.ts.map +0 -1
- package/build/components/conversations/hidden_indicator.js +0 -52
- package/build/components/conversations/hidden_indicator.js.map +0 -1
- package/build/components/conversations/hidden_results_footer.d.ts +0 -2
- package/build/components/conversations/hidden_results_footer.d.ts.map +0 -1
- package/build/components/conversations/hidden_results_footer.js +0 -34
- package/build/components/conversations/hidden_results_footer.js.map +0 -1
- package/build/components/display/toast.d.ts +0 -3
- package/build/components/display/toast.d.ts.map +0 -1
- package/build/components/display/toast.js +0 -224
- package/build/components/display/toast.js.map +0 -1
- package/build/hooks/use_hidden_conversations_count.d.ts +0 -2
- package/build/hooks/use_hidden_conversations_count.d.ts.map +0 -1
- package/build/hooks/use_hidden_conversations_count.js +0 -32
- package/build/hooks/use_hidden_conversations_count.js.map +0 -1
- package/build/hooks/use_hide_conversation.d.ts +0 -108
- package/build/hooks/use_hide_conversation.d.ts.map +0 -1
- package/build/hooks/use_hide_conversation.js +0 -243
- package/build/hooks/use_hide_conversation.js.map +0 -1
- package/build/hooks/use_hide_conversations_enabled.d.ts +0 -2
- package/build/hooks/use_hide_conversations_enabled.d.ts.map +0 -1
- package/build/hooks/use_hide_conversations_enabled.js +0 -18
- package/build/hooks/use_hide_conversations_enabled.js.map +0 -1
- package/build/screens/conversation_actions_screen.d.ts +0 -7
- package/build/screens/conversation_actions_screen.d.ts.map +0 -1
- package/build/screens/conversation_actions_screen.js +0 -89
- package/build/screens/conversation_actions_screen.js.map +0 -1
- package/build/utils/toast_store.d.ts +0 -21
- package/build/utils/toast_store.d.ts.map +0 -1
- package/build/utils/toast_store.js +0 -27
- package/build/utils/toast_store.js.map +0 -1
- package/src/components/conversations/hidden_indicator.tsx +0 -30
- package/src/components/conversations/hidden_results_footer.tsx +0 -25
- package/src/components/display/__tests__/toast.test.tsx +0 -55
- package/src/components/display/toast.tsx +0 -115
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +0 -189
- package/src/hooks/use_hidden_conversations_count.ts +0 -14
- package/src/hooks/use_hide_conversation.ts +0 -128
- package/src/hooks/use_hide_conversations_enabled.ts +0 -7
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +0 -79
- package/src/screens/conversation_actions_screen.tsx +0 -53
- package/src/utils/toast_store.ts +0 -45
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
const hiddenKey = getRequestQueryKey(getConversationsRequestArgs({ show_hidden: true }))
|
|
30
|
-
|
|
31
|
-
const listData = (conversations: ConversationResource[]) => ({
|
|
32
|
-
pages: [{ data: conversations, links: {}, meta: { count: conversations.length } }],
|
|
33
|
-
pageParams: [{}],
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const listIds = (queryKey: unknown[]) =>
|
|
37
|
-
(
|
|
38
|
-
queryClient.getQueryData(queryKey) as ReturnType<typeof listData> | undefined
|
|
39
|
-
)?.pages[0].data.map(({ id }) => id)
|
|
40
|
-
|
|
41
|
-
const buildQueryClient = () =>
|
|
42
|
-
buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
43
|
-
|
|
44
|
-
let queryClient = buildQueryClient()
|
|
45
|
-
|
|
46
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
47
|
-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const renderHide = (target: ConversationResource = conversation, hidden?: boolean) =>
|
|
51
|
-
renderHook(() => useHideConversation({ conversation: target, hidden }), { wrapper })
|
|
52
|
-
|
|
53
|
-
describe('useHideConversation', () => {
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
queryClient = buildQueryClient()
|
|
56
|
-
queryClient.setQueryData(allKey, listData([conversation, otherConversation]))
|
|
57
|
-
queryClient.setQueryData(unreadKey, listData([conversation]))
|
|
58
|
-
queryClient.setQueryData(conversationKey, {
|
|
59
|
-
data: { id: 7, conversationMembership: { muted: false } },
|
|
60
|
-
})
|
|
61
|
-
mockPatch.mockReset()
|
|
62
|
-
dismissToast()
|
|
63
|
-
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
jest.restoreAllMocks()
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('removes the conversation from every list before the request resolves', async () => {
|
|
71
|
-
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
72
|
-
const { result } = renderHide()
|
|
73
|
-
|
|
74
|
-
await act(async () => result.current.setHidden(true))
|
|
75
|
-
|
|
76
|
-
expect(listIds(allKey)).toEqual([8])
|
|
77
|
-
expect(listIds(unreadKey)).toEqual([])
|
|
78
|
-
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
79
|
-
data: { id: 7, conversationMembership: { muted: false, hidden: true } },
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('patches hidden on the membership', async () => {
|
|
84
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
85
|
-
const { result } = renderHide()
|
|
86
|
-
|
|
87
|
-
await act(() => result.current.mutateAsync(true))
|
|
88
|
-
|
|
89
|
-
expect(mockPatch).toHaveBeenCalledWith({
|
|
90
|
-
url: '/me/conversations/7/conversation_membership',
|
|
91
|
-
data: {
|
|
92
|
-
data: { type: 'ConversationMembership', attributes: { hidden: true } },
|
|
93
|
-
fields: { ConversationMembership: 'hidden' },
|
|
94
|
-
},
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it.each([
|
|
99
|
-
[false, HIDDEN_TOAST_SUBTITLE],
|
|
100
|
-
[true, HIDDEN_AND_SILENCED_TOAST_SUBTITLE],
|
|
101
|
-
])('shows an undo toast for muted=%s', async (muted, subtitle) => {
|
|
102
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
103
|
-
const { result } = renderHide({ ...conversation, muted })
|
|
104
|
-
|
|
105
|
-
await act(() => result.current.mutateAsync(true))
|
|
106
|
-
|
|
107
|
-
expect(toastStore.getSnapshot()).toMatchObject({
|
|
108
|
-
title: 'Conversation hidden',
|
|
109
|
-
subtitle,
|
|
110
|
-
action: { label: 'Undo' },
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('restores the lists and unhides on undo', async () => {
|
|
115
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
116
|
-
const { result } = renderHide()
|
|
117
|
-
await act(() => result.current.mutateAsync(true))
|
|
118
|
-
|
|
119
|
-
await act(async () => toastStore.getSnapshot()?.action?.onPress())
|
|
120
|
-
|
|
121
|
-
expect(listIds(allKey)).toEqual([7, 8])
|
|
122
|
-
expect(listIds(unreadKey)).toEqual([7])
|
|
123
|
-
expect(mockPatch).toHaveBeenLastCalledWith(
|
|
124
|
-
expect.objectContaining({
|
|
125
|
-
data: expect.objectContaining({
|
|
126
|
-
data: { type: 'ConversationMembership', attributes: { hidden: false } },
|
|
127
|
-
}),
|
|
128
|
-
})
|
|
129
|
-
)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('puts the conversation back and alerts when hiding fails', async () => {
|
|
133
|
-
mockPatch.mockRejectedValue(new Error('nope'))
|
|
134
|
-
const { result } = renderHide()
|
|
135
|
-
|
|
136
|
-
await act(() => result.current.mutateAsync(true).catch(() => {}))
|
|
137
|
-
|
|
138
|
-
expect(listIds(allKey)).toEqual([7, 8])
|
|
139
|
-
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
140
|
-
data: { id: 7, conversationMembership: { muted: false, hidden: false } },
|
|
141
|
-
})
|
|
142
|
-
expect(toastStore.getSnapshot()).toBeNull()
|
|
143
|
-
expect(Alert.alert).toHaveBeenCalledWith(
|
|
144
|
-
'Oops',
|
|
145
|
-
"Couldn't hide this conversation. Please try again."
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
describe('from the hidden list', () => {
|
|
150
|
-
beforeEach(() => {
|
|
151
|
-
queryClient.setQueryData(hiddenKey, listData([conversation, otherConversation]))
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('removes the conversation from the hidden list before the request resolves', async () => {
|
|
155
|
-
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
156
|
-
const { result } = renderHide(conversation, true)
|
|
157
|
-
|
|
158
|
-
expect(result.current.hidden).toBe(true)
|
|
159
|
-
|
|
160
|
-
await act(async () => result.current.setHidden(false))
|
|
161
|
-
|
|
162
|
-
expect(listIds(hiddenKey)).toEqual([8])
|
|
163
|
-
expect(listIds(allKey)).toEqual([7, 8])
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
it('puts the conversation back in the hidden list when unhiding fails', async () => {
|
|
167
|
-
mockPatch.mockRejectedValue(new Error('nope'))
|
|
168
|
-
const { result } = renderHide(conversation, true)
|
|
169
|
-
|
|
170
|
-
await act(() => result.current.mutateAsync(false).catch(() => {}))
|
|
171
|
-
|
|
172
|
-
expect(listIds(hiddenKey)).toEqual([7, 8])
|
|
173
|
-
expect(Alert.alert).toHaveBeenCalledWith(
|
|
174
|
-
'Oops',
|
|
175
|
-
"Couldn't unhide this conversation. Please try again."
|
|
176
|
-
)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('refreshes the hidden list after hiding elsewhere', async () => {
|
|
180
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
181
|
-
const { result } = renderHide(otherConversation)
|
|
182
|
-
|
|
183
|
-
await act(() => result.current.mutateAsync(true))
|
|
184
|
-
|
|
185
|
-
expect(queryClient.getQueryState(hiddenKey)?.isInvalidated).toBe(true)
|
|
186
|
-
expect(queryClient.getQueryState(unreadKey)?.isInvalidated).toBe(false)
|
|
187
|
-
})
|
|
188
|
-
})
|
|
189
|
-
})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ConversationResource } from '../types'
|
|
2
|
-
import { getConversationsRequestArgs } from '../utils/request/conversation'
|
|
3
|
-
import { useApiPaginator } from './use_api'
|
|
4
|
-
import { useHideConversationsEnabled } from './use_hide_conversations_enabled'
|
|
5
|
-
|
|
6
|
-
export function useHiddenConversationsCount() {
|
|
7
|
-
const enabled = useHideConversationsEnabled()
|
|
8
|
-
const { totalCount } = useApiPaginator<ConversationResource>(
|
|
9
|
-
getConversationsRequestArgs({ show_hidden: true }),
|
|
10
|
-
{ enabled }
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
return enabled ? totalCount : 0
|
|
14
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { InfiniteData, QueryKey, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { Alert } from 'react-native'
|
|
3
|
-
import {
|
|
4
|
-
ApiCollection,
|
|
5
|
-
ApiResource,
|
|
6
|
-
ConversationMembershipResource,
|
|
7
|
-
ConversationResource,
|
|
8
|
-
} from '../types'
|
|
9
|
-
import { deleteRecordInPagesData } from '../utils/cache/page_mutations'
|
|
10
|
-
import { Haptic } from '../utils/native_adapters'
|
|
11
|
-
import {
|
|
12
|
-
getConversationsRequestArgs,
|
|
13
|
-
HIDDEN_CONVERSATIONS_FILTER,
|
|
14
|
-
} from '../utils/request/conversation'
|
|
15
|
-
import { showToast } from '../utils/toast_store'
|
|
16
|
-
import { useApiClient } from './use_api_client'
|
|
17
|
-
import { getConversationRequestArgs } from './use_conversation'
|
|
18
|
-
import { getRequestQueryKey } from './use_suspense_api'
|
|
19
|
-
|
|
20
|
-
type ConversationsData = InfiniteData<ApiCollection<ConversationResource>>
|
|
21
|
-
type ListsSnapshot = Array<[QueryKey, ConversationsData | undefined]>
|
|
22
|
-
|
|
23
|
-
export const HIDDEN_TOAST_TITLE = 'Conversation hidden'
|
|
24
|
-
export const HIDDEN_TOAST_SUBTITLE = "It'll come back if someone sends a new message."
|
|
25
|
-
export const HIDDEN_AND_SILENCED_TOAST_SUBTITLE =
|
|
26
|
-
"It's silenced too, so it stays hidden until you unhide it."
|
|
27
|
-
|
|
28
|
-
export const useHideConversation = ({
|
|
29
|
-
conversation,
|
|
30
|
-
hidden: knownHidden,
|
|
31
|
-
}: {
|
|
32
|
-
conversation: ConversationResource
|
|
33
|
-
hidden?: boolean
|
|
34
|
-
}) => {
|
|
35
|
-
const apiClient = useApiClient()
|
|
36
|
-
const queryClient = useQueryClient()
|
|
37
|
-
const listsQueryKey = [getConversationsRequestArgs().url]
|
|
38
|
-
const hiddenListsQueryKey = [...listsQueryKey, { filter: HIDDEN_CONVERSATIONS_FILTER }]
|
|
39
|
-
const conversationQueryKey = getRequestQueryKey(
|
|
40
|
-
getConversationRequestArgs({ conversation_id: conversation.id })
|
|
41
|
-
)
|
|
42
|
-
const hidden = knownHidden ?? !!conversation.conversationMembership?.hidden
|
|
43
|
-
|
|
44
|
-
const setMembershipHidden = (value: boolean) =>
|
|
45
|
-
queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, prev => {
|
|
46
|
-
if (!prev?.data) return prev
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
...prev,
|
|
50
|
-
data: {
|
|
51
|
-
...prev.data,
|
|
52
|
-
conversationMembership: { ...prev.data.conversationMembership, hidden: value },
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const removeFromLists = (queryKey: QueryKey) =>
|
|
58
|
-
queryClient.setQueriesData<ConversationsData>({ queryKey }, prev => {
|
|
59
|
-
if (!prev?.pages) return prev
|
|
60
|
-
|
|
61
|
-
return deleteRecordInPagesData({ data: prev, record: { id: conversation.id } })
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const restoreLists = (lists: ListsSnapshot) => {
|
|
65
|
-
lists.forEach(([queryKey, data]) => {
|
|
66
|
-
queryClient.setQueryData<ConversationsData>(queryKey, data)
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const { mutate: setHidden, ...mutation } = useMutation({
|
|
71
|
-
mutationKey: ['hideConversation', conversation.id],
|
|
72
|
-
scope: { id: `hideConversation-${conversation.id}` },
|
|
73
|
-
onMutate: async (value: boolean) => {
|
|
74
|
-
await queryClient.cancelQueries({ queryKey: listsQueryKey })
|
|
75
|
-
const previousLists = queryClient.getQueriesData<ConversationsData>({
|
|
76
|
-
queryKey: listsQueryKey,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
removeFromLists(value ? listsQueryKey : hiddenListsQueryKey)
|
|
80
|
-
setMembershipHidden(value)
|
|
81
|
-
|
|
82
|
-
return { previousLists }
|
|
83
|
-
},
|
|
84
|
-
mutationFn: (value: boolean) =>
|
|
85
|
-
apiClient.chat.patch<ApiResource<ConversationMembershipResource>>({
|
|
86
|
-
url: `/me/conversations/${conversation.id}/conversation_membership`,
|
|
87
|
-
data: {
|
|
88
|
-
data: { type: 'ConversationMembership', attributes: { hidden: value } },
|
|
89
|
-
fields: { ConversationMembership: 'hidden' },
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
onSuccess: (_response, value, { previousLists }) => {
|
|
93
|
-
Haptic.notificationSuccess()
|
|
94
|
-
|
|
95
|
-
if (!value) {
|
|
96
|
-
queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
queryClient.invalidateQueries({ queryKey: hiddenListsQueryKey })
|
|
101
|
-
showToast({
|
|
102
|
-
title: HIDDEN_TOAST_TITLE,
|
|
103
|
-
subtitle: conversation.muted ? HIDDEN_AND_SILENCED_TOAST_SUBTITLE : HIDDEN_TOAST_SUBTITLE,
|
|
104
|
-
action: {
|
|
105
|
-
label: 'Undo',
|
|
106
|
-
onPress: () => {
|
|
107
|
-
restoreLists(previousLists)
|
|
108
|
-
setHidden(false)
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
},
|
|
113
|
-
onError: (_error, value, context) => {
|
|
114
|
-
if (context) restoreLists(context.previousLists)
|
|
115
|
-
setMembershipHidden(!value)
|
|
116
|
-
Alert.alert(
|
|
117
|
-
'Oops',
|
|
118
|
-
`Couldn't ${value ? 'hide' : 'unhide'} this conversation. Please try again.`
|
|
119
|
-
)
|
|
120
|
-
},
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
hidden,
|
|
125
|
-
setHidden,
|
|
126
|
-
...mutation,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
5
|
-
import type { ConversationResource } from '../../types'
|
|
6
|
-
import { ConversationActionsScreen } from '../conversation_actions_screen'
|
|
7
|
-
|
|
8
|
-
const mockNavigation = { goBack: jest.fn() }
|
|
9
|
-
jest.mock('@react-navigation/native', () => ({
|
|
10
|
-
...jest.requireActual('@react-navigation/native'),
|
|
11
|
-
useNavigation: () => mockNavigation,
|
|
12
|
-
}))
|
|
13
|
-
jest.mock('@react-navigation/elements', () => ({
|
|
14
|
-
...jest.requireActual('@react-navigation/elements'),
|
|
15
|
-
useHeaderHeight: () => 0,
|
|
16
|
-
}))
|
|
17
|
-
|
|
18
|
-
const conversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
|
|
19
|
-
jest.mock('../../hooks/use_conversation', () => ({
|
|
20
|
-
useConversation: () => ({ data: conversation }),
|
|
21
|
-
}))
|
|
22
|
-
|
|
23
|
-
let mockHidden = false
|
|
24
|
-
const mockSetHidden = jest.fn()
|
|
25
|
-
jest.mock('../../hooks/use_hide_conversation', () => ({
|
|
26
|
-
useHideConversation: () => ({ hidden: mockHidden, setHidden: mockSetHidden, isPending: false }),
|
|
27
|
-
}))
|
|
28
|
-
|
|
29
|
-
let mockHideEnabled = true
|
|
30
|
-
jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
|
|
31
|
-
useHideConversationsEnabled: () => mockHideEnabled,
|
|
32
|
-
}))
|
|
33
|
-
|
|
34
|
-
const safeAreaMetrics = {
|
|
35
|
-
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
36
|
-
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const renderScreen = () =>
|
|
40
|
-
render(
|
|
41
|
-
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
42
|
-
<ThemeProvider value={DefaultTheme}>
|
|
43
|
-
<ConversationActionsScreen route={{ params: { conversation_id: 7 } }} />
|
|
44
|
-
</ThemeProvider>
|
|
45
|
-
</SafeAreaProvider>
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
describe('ConversationActionsScreen', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
mockHidden = false
|
|
51
|
-
mockHideEnabled = true
|
|
52
|
-
jest.clearAllMocks()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('offers nothing when the flag is off', () => {
|
|
56
|
-
mockHideEnabled = false
|
|
57
|
-
const { queryByText } = renderScreen()
|
|
58
|
-
|
|
59
|
-
expect(queryByText('Hide conversation')).toBeNull()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('hides the conversation and closes the sheet', () => {
|
|
63
|
-
const { getByText } = renderScreen()
|
|
64
|
-
|
|
65
|
-
fireEvent.press(getByText('Hide conversation'))
|
|
66
|
-
|
|
67
|
-
expect(mockSetHidden).toHaveBeenCalledWith(true)
|
|
68
|
-
expect(mockNavigation.goBack).toHaveBeenCalledTimes(1)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('unhides a hidden conversation', () => {
|
|
72
|
-
mockHidden = true
|
|
73
|
-
const { getByText } = renderScreen()
|
|
74
|
-
|
|
75
|
-
fireEvent.press(getByText('Unhide conversation'))
|
|
76
|
-
|
|
77
|
-
expect(mockSetHidden).toHaveBeenCalledWith(false)
|
|
78
|
-
})
|
|
79
|
-
})
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { StyleSheet } from 'react-native'
|
|
4
|
-
import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
|
|
5
|
-
import { useConversation } from '../hooks/use_conversation'
|
|
6
|
-
import { useHideConversation } from '../hooks/use_hide_conversation'
|
|
7
|
-
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
8
|
-
|
|
9
|
-
export const ConversationActionsScreenOptions = getFormSheetScreenOptions({
|
|
10
|
-
headerTitle: 'Conversation actions',
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export type ConversationActionsScreenProps = StaticScreenProps<{
|
|
14
|
-
conversation_id: number
|
|
15
|
-
}>
|
|
16
|
-
|
|
17
|
-
export function ConversationActionsScreen({ route }: ConversationActionsScreenProps) {
|
|
18
|
-
const navigation = useNavigation()
|
|
19
|
-
const styles = useStyles()
|
|
20
|
-
const { data: conversation } = useConversation(route.params)
|
|
21
|
-
const { hidden, setHidden, isPending } = useHideConversation({ conversation })
|
|
22
|
-
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
23
|
-
|
|
24
|
-
const handleHidePress = () => {
|
|
25
|
-
setHidden(!hidden)
|
|
26
|
-
navigation.goBack()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<FormSheet.Root style={styles.formSheetContent}>
|
|
31
|
-
{hideConversationsEnabled && (
|
|
32
|
-
<FormSheet.Action
|
|
33
|
-
onPress={handleHidePress}
|
|
34
|
-
title={hidden ? 'Unhide conversation' : 'Hide conversation'}
|
|
35
|
-
iconName={hidden ? 'general.showEye' : 'general.hideEye'}
|
|
36
|
-
disabled={isPending}
|
|
37
|
-
accessibilityHint={
|
|
38
|
-
hidden
|
|
39
|
-
? 'Shows this conversation in your conversation list again.'
|
|
40
|
-
: 'Hides this conversation from your conversation list.'
|
|
41
|
-
}
|
|
42
|
-
/>
|
|
43
|
-
)}
|
|
44
|
-
</FormSheet.Root>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const useStyles = () =>
|
|
49
|
-
StyleSheet.create({
|
|
50
|
-
formSheetContent: {
|
|
51
|
-
paddingTop: 16,
|
|
52
|
-
},
|
|
53
|
-
})
|
package/src/utils/toast_store.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export interface ToastAction {
|
|
2
|
-
label: string
|
|
3
|
-
onPress: () => void
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface ToastOptions {
|
|
7
|
-
title: string
|
|
8
|
-
subtitle?: string
|
|
9
|
-
action?: ToastAction
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ToastState extends ToastOptions {
|
|
13
|
-
id: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Listener = () => void
|
|
17
|
-
|
|
18
|
-
let currentToast: ToastState | null = null
|
|
19
|
-
let nextId = 1
|
|
20
|
-
const listeners = new Set<Listener>()
|
|
21
|
-
|
|
22
|
-
const emit = () => listeners.forEach(listener => listener())
|
|
23
|
-
|
|
24
|
-
export const toastStore = {
|
|
25
|
-
getSnapshot: () => currentToast,
|
|
26
|
-
subscribe: (listener: Listener) => {
|
|
27
|
-
listeners.add(listener)
|
|
28
|
-
return () => {
|
|
29
|
-
listeners.delete(listener)
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function showToast(options: ToastOptions) {
|
|
35
|
-
currentToast = { ...options, id: nextId++ }
|
|
36
|
-
emit()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function dismissToast(id?: number) {
|
|
40
|
-
if (!currentToast) return
|
|
41
|
-
if (id !== undefined && currentToast.id !== id) return
|
|
42
|
-
|
|
43
|
-
currentToast = null
|
|
44
|
-
emit()
|
|
45
|
-
}
|