@planningcenter/chat-react-native 4.2.0-rc.1 → 4.2.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/build/components/display/index.d.ts +1 -0
  2. package/build/components/display/index.d.ts.map +1 -1
  3. package/build/components/display/index.js +1 -0
  4. package/build/components/display/index.js.map +1 -1
  5. package/build/components/display/version_footer.d.ts +2 -0
  6. package/build/components/display/version_footer.d.ts.map +1 -0
  7. package/build/components/display/version_footer.js +36 -0
  8. package/build/components/display/version_footer.js.map +1 -0
  9. package/build/contexts/api_provider.d.ts.map +1 -1
  10. package/build/contexts/api_provider.js +12 -1
  11. package/build/contexts/api_provider.js.map +1 -1
  12. package/build/hooks/use_features.d.ts +16 -0
  13. package/build/hooks/use_features.d.ts.map +1 -1
  14. package/build/hooks/use_features.js +43 -47
  15. package/build/hooks/use_features.js.map +1 -1
  16. package/build/screens/conversations/components/search_list_header_component.d.ts +2 -0
  17. package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -0
  18. package/build/screens/conversations/components/search_list_header_component.js +496 -0
  19. package/build/screens/conversations/components/search_list_header_component.js.map +1 -0
  20. package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
  21. package/build/screens/conversations/conversations_screen.js +28 -16
  22. package/build/screens/conversations/conversations_screen.js.map +1 -1
  23. package/build/screens/settings_screen.d.ts.map +1 -1
  24. package/build/screens/settings_screen.js +41 -14
  25. package/build/screens/settings_screen.js.map +1 -1
  26. package/build/utils/package_version.d.ts +2 -0
  27. package/build/utils/package_version.d.ts.map +1 -0
  28. package/build/utils/package_version.js +5 -0
  29. package/build/utils/package_version.js.map +1 -0
  30. package/build/utils/time.d.ts +1 -0
  31. package/build/utils/time.d.ts.map +1 -1
  32. package/build/utils/time.js +1 -0
  33. package/build/utils/time.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/__tests__/hooks/use_features.test.ts +61 -0
  36. package/src/components/display/__tests__/version_footer.test.tsx +48 -0
  37. package/src/components/display/index.ts +1 -0
  38. package/src/components/display/version_footer.tsx +26 -0
  39. package/src/contexts/api_provider.tsx +4 -0
  40. package/src/hooks/use_features.ts +26 -14
  41. package/src/screens/conversations/components/search_list_header_component.tsx +291 -0
  42. package/src/screens/conversations/conversations_screen.tsx +6 -1
  43. package/src/screens/settings_screen.tsx +11 -1
  44. package/src/utils/package_version.ts +3 -0
  45. package/src/utils/time.ts +1 -0
@@ -0,0 +1,291 @@
1
+ import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'
2
+ import React, { useCallback, useMemo } from 'react'
3
+ import { Alert, ScrollView, StyleSheet, View } from 'react-native'
4
+ import { Heading, TextButton, ToggleButton } from '../../../components'
5
+ import {
6
+ useAtFontScaleBreakpoint,
7
+ useCanCreateConversations,
8
+ useCurrentPersonCache,
9
+ useDirectMessagesEligible,
10
+ useHasDirectMessages,
11
+ useNewConversationEntry,
12
+ useTheme,
13
+ } from '../../../hooks'
14
+ import { useMarkAllRead } from '../../../hooks/use_conversations_actions'
15
+ import { useCanDisplayGroups } from '../../../hooks/use_groups'
16
+ import { useNewConversationFromFilter } from '../../../hooks/use_new_conversation_from_filter'
17
+ import { GraphId } from '../../../types/resources/group_resource'
18
+ import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../../utils'
19
+ import { Haptic } from '../../../utils/native_adapters'
20
+ import { ConversationFiltersParams } from '../../conversation_filters/screen_props'
21
+ import { ConversationsScreenProps } from '../conversations_screen'
22
+ import { ChatGroupBadge } from './chat_group_badge'
23
+ import { ListHeaderActionButton } from './list_header_action_button'
24
+
25
+ const ROW_PADDING_HORIZONTAL = 16
26
+
27
+ enum FilterTypes {
28
+ All = 'All',
29
+ Groups = 'Groups',
30
+ Teams = 'Teams',
31
+ DMs = 'DMs',
32
+ More = 'More',
33
+ }
34
+
35
+ export const SearchListHeaderComponent = () => {
36
+ const navigation = useNavigation()
37
+ const canFilterByTeams = useCanDisplayGroups({ source_app_name: 'Services', source_type: 'Team' })
38
+ const canFilterByGroups = useCanDisplayGroups({ source_app_name: 'Groups', source_type: 'Group' })
39
+ const directMessagesEligible = useDirectMessagesEligible()
40
+ const hasDirectMessages = useHasDirectMessages()
41
+ const canFilterByDMs = directMessagesEligible && hasDirectMessages
42
+ const route = useRoute<RouteProp<ConversationsScreenProps['route']>>()
43
+ const {
44
+ chat_group_graph_id,
45
+ group_source_app_name = '',
46
+ show_direct_messages,
47
+ } = route.params || {}
48
+ const currentPersonCache = useCurrentPersonCache()
49
+ const { markAllRead, isPending } = useMarkAllRead()
50
+ const canCreateConversations = useCanCreateConversations()
51
+ const entryMode = useNewConversationEntry()
52
+ const newConversationFromFilter = useNewConversationFromFilter(
53
+ chat_group_graph_id as GraphId | undefined
54
+ )
55
+
56
+ const active: FilterTypes = useMemo(() => {
57
+ if (chat_group_graph_id) {
58
+ return FilterTypes.More
59
+ } else if (/groups/i.test(group_source_app_name)) {
60
+ return FilterTypes.Groups
61
+ } else if (/services/i.test(group_source_app_name)) {
62
+ return FilterTypes.Teams
63
+ } else if (show_direct_messages) {
64
+ return FilterTypes.DMs
65
+ }
66
+
67
+ return FilterTypes.All
68
+ }, [chat_group_graph_id, group_source_app_name, show_direct_messages])
69
+
70
+ const handleNewConversationNavigation = useCallback(() => {
71
+ if (newConversationFromFilter || entryMode === 'select_type') {
72
+ return navigation.navigate('ConversationSelectType', {
73
+ ...route.params,
74
+ newConversationFromFilter,
75
+ })
76
+ }
77
+
78
+ if (entryMode === 'groups') {
79
+ return navigation.navigate('New', {
80
+ screen: 'ConversationSelectGroupRecipients',
81
+ params: { ...route.params },
82
+ })
83
+ }
84
+
85
+ if (entryMode === 'teams') {
86
+ return navigation.navigate('New', {
87
+ screen: 'ConversationSelectTeamsILeadRecipients',
88
+ params: { ...route.params },
89
+ })
90
+ }
91
+
92
+ if (entryMode === 'direct_message') {
93
+ return navigation.navigate('New', {
94
+ screen: 'ConversationSelectDirectMessageRecipients',
95
+ params: { ...route.params },
96
+ })
97
+ }
98
+ }, [navigation, route.params, entryMode, newConversationFromFilter])
99
+
100
+ const handleSetFilter = useCallback(
101
+ (params: ConversationFiltersParams) => {
102
+ navigation.setParams({
103
+ title: undefined,
104
+ chat_group_graph_id: undefined,
105
+ group_source_app_name: undefined,
106
+ show_direct_messages: undefined,
107
+ ...params,
108
+ })
109
+ },
110
+ [navigation]
111
+ )
112
+
113
+ const handleChatSettings = useCallback(() => {
114
+ navigation.navigate('ChatSettings', {})
115
+ }, [navigation])
116
+
117
+ const handleOpenConversationFilters = useCallback(() => {
118
+ navigation.navigate('ConversationFilters', {
119
+ chat_group_graph_id,
120
+ group_source_app_name,
121
+ show_direct_messages,
122
+ })
123
+ }, [navigation, chat_group_graph_id, group_source_app_name, show_direct_messages])
124
+
125
+ const handleMarkAllRead = useCallback(() => {
126
+ currentPersonCache.update({ unreadCount: 0 })
127
+ Haptic.notificationSuccess()
128
+ markAllRead()
129
+ }, [currentPersonCache, markAllRead])
130
+
131
+ const alertMarkAllRead = useCallback(() => {
132
+ if (active === FilterTypes.All) return handleMarkAllRead()
133
+
134
+ Alert.alert('Mark all read', 'This includes conversations not shown by the current filter.', [
135
+ { text: 'Cancel' },
136
+ { text: 'OK', onPress: () => handleMarkAllRead() },
137
+ ])
138
+ }, [active, handleMarkAllRead])
139
+
140
+ const hasSomeSourceFilterCapability = canFilterByTeams || canFilterByGroups
141
+ const hasMultiSourceFilterCapabilities = canFilterByTeams && canFilterByGroups
142
+ const showFilterRow = hasMultiSourceFilterCapabilities || canFilterByDMs
143
+ const shouldShowHeaderFiltersButton = hasSomeSourceFilterCapability && !showFilterRow
144
+ const moreFiltersButtonA11yLabel = shouldShowHeaderFiltersButton
145
+ ? 'View filters'
146
+ : 'View more filters'
147
+
148
+ const moreFiltersButtonProps = {
149
+ onPress: handleOpenConversationFilters,
150
+ active: active === FilterTypes.More,
151
+ iconNameRight: 'general.threeReducingHorizontalBars' as const,
152
+ accessibilityLabel: moreFiltersButtonA11yLabel,
153
+ }
154
+
155
+ const styles = useStyles({ shouldShowHeaderFiltersButton })
156
+
157
+ return (
158
+ <View style={styles.listHeader}>
159
+ <View style={styles.headingRow}>
160
+ <View style={styles.titleContainer}>
161
+ <Heading numberOfLines={1} variant="h2">
162
+ Conversations
163
+ </Heading>
164
+ <TextButton
165
+ onPress={alertMarkAllRead}
166
+ disabled={isPending}
167
+ maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
168
+ accessibilityShowsLargeContentViewer
169
+ accessibilityLargeContentTitle="Mark all read"
170
+ >
171
+ Mark all read
172
+ </TextButton>
173
+ </View>
174
+ <View style={styles.actionsContainer}>
175
+ <ListHeaderActionButton
176
+ name="general.cog"
177
+ onPress={handleChatSettings}
178
+ accessibilityLabel="Chat settings"
179
+ testID="conversations-chat-settings-button"
180
+ maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
181
+ />
182
+ {canCreateConversations && (
183
+ <ListHeaderActionButton
184
+ name="churchCenter.signups"
185
+ onPress={handleNewConversationNavigation}
186
+ accessibilityLabel="New conversation"
187
+ testID="conversations-new-conversation-button"
188
+ maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
189
+ />
190
+ )}
191
+ {shouldShowHeaderFiltersButton && <ToggleButton {...moreFiltersButtonProps} />}
192
+ </View>
193
+ </View>
194
+ {showFilterRow && (
195
+ <ScrollView
196
+ horizontal
197
+ showsHorizontalScrollIndicator={false}
198
+ contentContainerStyle={styles.filterRow}
199
+ accessibilityRole="toolbar"
200
+ >
201
+ <ToggleButton
202
+ title={FilterTypes.All}
203
+ active={active === FilterTypes.All}
204
+ onPress={() => handleSetFilter({})}
205
+ accessibilityLabel="Show all conversations"
206
+ style={styles.filterButton}
207
+ />
208
+ {canFilterByGroups && (
209
+ <ToggleButton
210
+ title={FilterTypes.Groups}
211
+ active={active === FilterTypes.Groups}
212
+ onPress={() => handleSetFilter({ group_source_app_name: 'Groups' })}
213
+ accessibilityLabel="Filter to group conversations"
214
+ style={styles.filterButton}
215
+ />
216
+ )}
217
+ {canFilterByTeams && (
218
+ <ToggleButton
219
+ title={FilterTypes.Teams}
220
+ active={active === FilterTypes.Teams}
221
+ onPress={() => handleSetFilter({ group_source_app_name: 'Services' })}
222
+ accessibilityLabel="Filter to team conversations"
223
+ style={styles.filterButton}
224
+ />
225
+ )}
226
+ {canFilterByDMs && (
227
+ <ToggleButton
228
+ title={FilterTypes.DMs}
229
+ active={active === FilterTypes.DMs}
230
+ onPress={() => handleSetFilter({ show_direct_messages: true })}
231
+ accessibilityLabel="Filter to direct message conversations"
232
+ style={styles.filterButton}
233
+ />
234
+ )}
235
+ <ToggleButton {...moreFiltersButtonProps} />
236
+ </ScrollView>
237
+ )}
238
+ <ChatGroupBadge rowPaddingHorizontal={ROW_PADDING_HORIZONTAL} />
239
+ </View>
240
+ )
241
+ }
242
+
243
+ const useStyles = ({
244
+ shouldShowHeaderFiltersButton,
245
+ }: {
246
+ shouldShowHeaderFiltersButton: boolean
247
+ }) => {
248
+ const theme = useTheme()
249
+ const atFontScaleBreakpoint = useAtFontScaleBreakpoint(
250
+ shouldShowHeaderFiltersButton ? 1.2 : undefined
251
+ )
252
+
253
+ return StyleSheet.create({
254
+ listHeader: {
255
+ borderBottomWidth: 1,
256
+ borderBottomColor: theme.colors.statusErrorBorder,
257
+ paddingBottom: 16,
258
+ gap: 16,
259
+ },
260
+ headingRow: {
261
+ gap: 12,
262
+ flexDirection: atFontScaleBreakpoint ? 'column' : 'row',
263
+ alignItems: atFontScaleBreakpoint ? 'flex-start' : 'center',
264
+ justifyContent: 'space-between',
265
+ paddingBottom: atFontScaleBreakpoint ? 4 : 0,
266
+ paddingHorizontal: ROW_PADDING_HORIZONTAL,
267
+ },
268
+ titleContainer: {
269
+ gap: 8,
270
+ },
271
+ actionsContainer: {
272
+ flexDirection: 'row',
273
+ gap: 8,
274
+ alignItems: 'center',
275
+ },
276
+ markAllReadRow: {
277
+ paddingBottom: 4,
278
+ },
279
+ filterRow: {
280
+ flexDirection: 'row',
281
+ justifyContent: 'flex-start',
282
+ gap: 8,
283
+ paddingHorizontal: ROW_PADDING_HORIZONTAL,
284
+ flexGrow: 1,
285
+ },
286
+ filterButton: {
287
+ flex: 1,
288
+ minWidth: 65,
289
+ },
290
+ })
291
+ }
@@ -3,10 +3,12 @@ import React from 'react'
3
3
  import { StyleSheet, View } from 'react-native'
4
4
  import { Conversations } from '../../components'
5
5
  import { ConversationsContextProvider } from '../../contexts/conversations_context'
6
+ import { availableFeatures, useFeatures } from '../../hooks/use_features'
6
7
  import { analyticsEvents, usePublishProductAnalyticsEvent } from '../../hooks/use_product_analytics'
7
8
  import { AppName } from '../../types/resources/app_name'
8
9
  import { GraphId } from '../../types/resources/group_resource'
9
10
  import { ListHeaderComponent } from './components/list_header_component'
11
+ import { SearchListHeaderComponent } from './components/search_list_header_component'
10
12
 
11
13
  export type ConversationsScreenProps = StaticScreenProps<{
12
14
  title?: string
@@ -17,13 +19,16 @@ export type ConversationsScreenProps = StaticScreenProps<{
17
19
 
18
20
  export function ConversationsScreen({ route }: ConversationsScreenProps) {
19
21
  const styles = useStyles()
22
+ const { featureEnabled } = useFeatures()
23
+ const searchEnabled = featureEnabled(availableFeatures.search)
24
+ const Header = searchEnabled ? SearchListHeaderComponent : ListHeaderComponent
20
25
 
21
26
  usePublishProductAnalyticsEvent(analyticsEvents.conversation_index_opened)
22
27
 
23
28
  return (
24
29
  <View style={styles.container}>
25
30
  <ConversationsContextProvider args={route.params} opts={{ throwOnError: true }}>
26
- <Conversations ListHeaderComponent={ListHeaderComponent} />
31
+ <Conversations ListHeaderComponent={Header} />
27
32
  </ConversationsContextProvider>
28
33
  </View>
29
34
  )
@@ -2,7 +2,8 @@ import { PlatformPressable } from '@react-navigation/elements'
2
2
  import { StaticScreenProps, useNavigation } from '@react-navigation/native'
3
3
  import React, { useCallback } from 'react'
4
4
  import { Platform, StyleSheet, View } from 'react-native'
5
- import { Heading, Icon, Text } from '../components'
5
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
6
+ import { Heading, Icon, Text, VersionFooter } from '../components'
6
7
  import { Switch } from '../components/display/switch'
7
8
  import { useDirectMessagesEligible, useTheme } from '../hooks'
8
9
  import { useAppName } from '../hooks/use_app_name'
@@ -50,6 +51,9 @@ export function SettingsScreen({}: SettingsScreenProps) {
50
51
  <NavRow label="Notification settings" onPress={handleNotificationSettings} />
51
52
  {appName !== 'services' && <NavRow label="Get help" onPress={handleGetHelp} />}
52
53
  </View>
54
+ <View style={styles.footer}>
55
+ <VersionFooter />
56
+ </View>
53
57
  </View>
54
58
  )
55
59
  }
@@ -80,10 +84,16 @@ function NavRow({ label, onPress }: NavRowProps) {
80
84
 
81
85
  const useStyles = () => {
82
86
  const { colors } = useTheme()
87
+ const insets = useSafeAreaInsets()
83
88
  return StyleSheet.create({
84
89
  container: {
85
90
  flex: 1,
86
91
  },
92
+ footer: {
93
+ flex: 1,
94
+ justifyContent: 'flex-end',
95
+ paddingBottom: Math.max(insets.bottom, 8),
96
+ },
87
97
  sectionOuter: {
88
98
  paddingLeft: 16,
89
99
  },
@@ -0,0 +1,3 @@
1
+ const { version } = require('../../package.json') as { version: string }
2
+
3
+ export const chatReactNativeVersion = version
package/src/utils/time.ts CHANGED
@@ -12,6 +12,7 @@ export function toMs(value: number, unit: TimeUnit): number {
12
12
  }
13
13
 
14
14
  export const FIVE_SECONDS = toMs(5, 'seconds')
15
+ export const ONE_MINUTE = toMs(1, 'minutes')
15
16
  export const FIVE_MINUTES = toMs(5, 'minutes')
16
17
  export const THIRTY_MINUTES = toMs(30, 'minutes')
17
18
  export const ONE_HOUR = toMs(1, 'hours')