@planningcenter/chat-react-native 3.1.0-rc.0 → 3.1.0-rc.2
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.js +2 -2
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_reaction.d.ts +1 -1
- package/build/components/conversation/message_reaction.d.ts.map +1 -1
- package/build/components/conversation/message_reaction.js +4 -0
- package/build/components/conversation/message_reaction.js.map +1 -1
- package/build/components/display/badge.js +3 -0
- package/build/components/display/badge.js.map +1 -1
- package/build/components/display/index.d.ts +5 -4
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +5 -4
- package/build/components/display/index.js.map +1 -1
- package/build/components/display/person.d.ts +10 -0
- package/build/components/display/person.d.ts.map +1 -0
- package/build/components/display/person.js +67 -0
- package/build/components/display/person.js.map +1 -0
- package/build/hooks/use_conversation_jolt_events.js +2 -2
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +2 -2
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts +1 -2
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +63 -9
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/screens/conversation_details_screen.js +2 -16
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/design_system_screen.d.ts.map +1 -1
- package/build/screens/design_system_screen.js +29 -2
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/utils/cache/page_mutations.d.ts +21 -2
- package/build/utils/cache/page_mutations.d.ts.map +1 -1
- package/build/utils/cache/page_mutations.js +19 -2
- package/build/utils/cache/page_mutations.js.map +1 -1
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.d.ts +12 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.d.ts.map +1 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.js +20 -0
- package/build/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/utils/cache/page_mutations.ts +85 -3
- package/src/components/conversation/message_form.tsx +2 -2
- package/src/components/conversation/message_reaction.tsx +3 -0
- package/src/components/display/badge.tsx +3 -0
- package/src/components/display/index.ts +5 -4
- package/src/components/display/person.tsx +90 -0
- package/src/hooks/use_conversation_jolt_events.ts +2 -2
- package/src/hooks/use_conversation_messages.ts +5 -2
- package/src/hooks/use_conversation_messages_jolt_events.ts +75 -11
- package/src/screens/conversation_details_screen.tsx +3 -30
- package/src/screens/design_system_screen.tsx +37 -1
- package/src/utils/cache/page_mutations.ts +31 -3
- package/src/utils/jolt/transform_reaction_event_data_to_reaction_count_resource.ts +36 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
Icon,
|
|
14
14
|
IconButton,
|
|
15
15
|
Image,
|
|
16
|
+
Person,
|
|
16
17
|
Spinner,
|
|
17
18
|
Switch,
|
|
18
19
|
Text,
|
|
@@ -50,6 +51,24 @@ const URL = {
|
|
|
50
51
|
],
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const personAdult = {
|
|
55
|
+
id: '1',
|
|
56
|
+
type: 'Member' as const,
|
|
57
|
+
name: 'John Doe',
|
|
58
|
+
avatar: URL.avatar,
|
|
59
|
+
badges: [{ title: 'Conversation owner' }, { title: 'Leader' }],
|
|
60
|
+
child: false,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const personChild = {
|
|
64
|
+
id: '2',
|
|
65
|
+
type: 'Member' as const,
|
|
66
|
+
name: 'Kid McChild',
|
|
67
|
+
avatar: URL.two_avatars[1],
|
|
68
|
+
badges: [],
|
|
69
|
+
child: true,
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
const buttonPress = () => Alert.alert('Button clicked')
|
|
54
73
|
|
|
55
74
|
// =================================
|
|
@@ -69,7 +88,8 @@ export function DesignSystemScreen() {
|
|
|
69
88
|
<PressablesSection />
|
|
70
89
|
<ImageIconsSection />
|
|
71
90
|
<FormControlsSection />
|
|
72
|
-
<StatusComponentsSection
|
|
91
|
+
<StatusComponentsSection />
|
|
92
|
+
<MiscComponentsSection isLast />
|
|
73
93
|
</ScrollView>
|
|
74
94
|
)
|
|
75
95
|
}
|
|
@@ -852,6 +872,22 @@ function StatusComponentsSection({ isLast }: SectionProps) {
|
|
|
852
872
|
)
|
|
853
873
|
}
|
|
854
874
|
|
|
875
|
+
function MiscComponentsSection({ isLast }: SectionProps) {
|
|
876
|
+
return (
|
|
877
|
+
<CollapsableSection title="Misc components" isLast={isLast}>
|
|
878
|
+
<Group
|
|
879
|
+
title="Person"
|
|
880
|
+
description="Takes a person object (`MemberResource` type) and displays an avatar, name, and badges. If person is a child we show a special badge and faded styles. Implomentation is based on a similar Chat Web component."
|
|
881
|
+
>
|
|
882
|
+
<Column>
|
|
883
|
+
<Person person={personAdult} />
|
|
884
|
+
<Person person={personChild} />
|
|
885
|
+
</Column>
|
|
886
|
+
</Group>
|
|
887
|
+
</CollapsableSection>
|
|
888
|
+
)
|
|
889
|
+
}
|
|
890
|
+
|
|
855
891
|
// =================================
|
|
856
892
|
// ====== Docs UI ==================
|
|
857
893
|
// =================================
|
|
@@ -8,12 +8,41 @@ import { ApiCollection, ResourceObject } from '../../types'
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* updateRecordInPagesData
|
|
11
|
-
*
|
|
11
|
+
* Updates record if found in the cache, otherwise noops.
|
|
12
12
|
*/
|
|
13
13
|
export function updateRecordInPagesData<T extends ResourceObject>({
|
|
14
14
|
data,
|
|
15
15
|
record,
|
|
16
16
|
processRecord = r => r,
|
|
17
|
+
}: {
|
|
18
|
+
data?: { pages: ApiCollection<T>[]; pageParams: any }
|
|
19
|
+
record: T
|
|
20
|
+
processRecord?: (_next: T, _prev: T) => T
|
|
21
|
+
}) {
|
|
22
|
+
if (!data) return data
|
|
23
|
+
|
|
24
|
+
const newPages = data.pages.map(page => {
|
|
25
|
+
const newData = page.data.map(message => {
|
|
26
|
+
if (message.id === record.id) {
|
|
27
|
+
return processRecord(record, message)
|
|
28
|
+
}
|
|
29
|
+
return message
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return { ...page, data: newData }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return { ...data, pages: newPages }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* updateOrCreateRecordInPagesData
|
|
40
|
+
* Updates record if found in the cache, otherwise inserts.
|
|
41
|
+
*/
|
|
42
|
+
export function updateOrCreateRecordInPagesData<T extends ResourceObject>({
|
|
43
|
+
data,
|
|
44
|
+
record,
|
|
45
|
+
processRecord = r => r,
|
|
17
46
|
}: {
|
|
18
47
|
data?: { pages: ApiCollection<T>[]; pageParams: any }
|
|
19
48
|
record: T
|
|
@@ -35,7 +64,6 @@ export function updateRecordInPagesData<T extends ResourceObject>({
|
|
|
35
64
|
})
|
|
36
65
|
|
|
37
66
|
if (!foundRecord) {
|
|
38
|
-
// Can be used to add as well but it's not at all efficient. It's better to use addRecordInPagesData.
|
|
39
67
|
// This is a fallback for when the record is not found in the cache.
|
|
40
68
|
const firstPage = { ...newPages[0] }
|
|
41
69
|
firstPage.data = [processRecord(record), ...firstPage.data]
|
|
@@ -52,7 +80,7 @@ export function addRecordInPagesData<T extends ResourceObject>({
|
|
|
52
80
|
}: {
|
|
53
81
|
data?: { pages: ApiCollection<T>[]; pageParams: any }
|
|
54
82
|
record: T
|
|
55
|
-
processRecord?: (_next: T
|
|
83
|
+
processRecord?: (_next: T) => T
|
|
56
84
|
}) {
|
|
57
85
|
if (!data) return data
|
|
58
86
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { JoltReactionEvent } from '../../types/jolt_events'
|
|
2
|
+
import { ReactionCreatedEvent } from '../../types/jolt_events/reaction_events'
|
|
3
|
+
import { ReactionCountResource } from '../../types/resources/reaction'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
data: ReactionCreatedEvent['data']['data']
|
|
7
|
+
oldData?: ReactionCountResource
|
|
8
|
+
event: JoltReactionEvent['event']
|
|
9
|
+
currentPersonId: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function transformReactionEventDataToReactionCountResource({
|
|
13
|
+
data,
|
|
14
|
+
oldData,
|
|
15
|
+
event,
|
|
16
|
+
currentPersonId,
|
|
17
|
+
}: Props): ReactionCountResource {
|
|
18
|
+
let authorIds = new Set(oldData?.authorIds || [])
|
|
19
|
+
if (event === 'reaction.created') {
|
|
20
|
+
authorIds.add(data.author_id.toString())
|
|
21
|
+
} else if (event === 'reaction.destroyed') {
|
|
22
|
+
authorIds.delete(data.author_id.toString())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const mine = authorIds.has(currentPersonId.toString())
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
type: 'ReactionCount',
|
|
29
|
+
id: `${data.message_sort_key}/${data.value}`,
|
|
30
|
+
value: data.value,
|
|
31
|
+
count: data.count,
|
|
32
|
+
mine: mine ? 1 : 0,
|
|
33
|
+
messageId: data.message_sort_key,
|
|
34
|
+
authorIds: Array.from(authorIds),
|
|
35
|
+
}
|
|
36
|
+
}
|