@messenger-box/platform-mobile 0.0.1-alpha.362 → 0.0.1-alpha.365

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 (29) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/index.js +2281 -553
  3. package/lib/index.js.map +1 -1
  4. package/lib/screens/inbox/DialogThreadMessages.d.ts +7 -0
  5. package/lib/screens/inbox/DialogThreads.d.ts +6 -0
  6. package/lib/screens/inbox/components/SupportServiceDialogsListItem.d.ts +21 -0
  7. package/lib/screens/inbox/components/ThreadsViewItem.d.ts +18 -0
  8. package/lib/screens/inbox/config/config.d.ts +2 -0
  9. package/lib/screens/inbox/containers/Dialogs.d.ts +1 -0
  10. package/lib/screens/inbox/containers/SupportServiceDialogs.d.ts +6 -0
  11. package/lib/screens/inbox/containers/ThreadConversationView.d.ts +11 -0
  12. package/lib/screens/inbox/containers/ThreadsView.d.ts +8 -0
  13. package/lib/screens/index.d.ts +2 -0
  14. package/package.json +4 -4
  15. package/src/navigation/InboxNavigation.tsx +63 -0
  16. package/src/screens/inbox/DialogThreadMessages.tsx +90 -0
  17. package/src/screens/inbox/DialogThreads.tsx +107 -0
  18. package/src/screens/inbox/Inbox.tsx +5 -3
  19. package/src/screens/inbox/components/DialogsListItem.tsx +7 -3
  20. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +5 -5
  21. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +295 -0
  22. package/src/screens/inbox/components/ThreadsViewItem.tsx +236 -0
  23. package/src/screens/inbox/config/config.ts +4 -0
  24. package/src/screens/inbox/containers/ConversationView.tsx +440 -156
  25. package/src/screens/inbox/containers/Dialogs.tsx +2 -1
  26. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +119 -0
  27. package/src/screens/inbox/containers/ThreadConversationView.tsx +764 -0
  28. package/src/screens/inbox/containers/ThreadsView.tsx +205 -0
  29. package/src/screens/index.ts +3 -1
@@ -0,0 +1,205 @@
1
+ import React, { useCallback, useMemo, useEffect, useState } from 'react';
2
+ import { FlatList, Box, Heading, Input, Text, Icon, Center, Spinner, Button } from 'native-base';
3
+ import { Ionicons } from '@expo/vector-icons';
4
+ import { useSelector, useDispatch } from 'react-redux';
5
+ import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-navigation/native';
6
+ import { orderBy, uniqBy, startCase } from 'lodash';
7
+ import { ThreadViewItem } from '../components/ThreadsViewItem';
8
+ import { useThreadMessagesQuery,useOnThreadCreatedUpdatedSubscription } from '@messenger-box/platform-client';
9
+ import { userSelector } from '@adminide-stack/user-auth0-client';
10
+ import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
11
+ import { config } from '../config';
12
+ const { MESSAGES_PER_PAGE } = config;
13
+
14
+ export interface ThreadsViewProps {
15
+ channelId?: string;
16
+ role?: string;
17
+ channelsDetail?: any;
18
+ refetchChannelDetail: (id: any) => Promise<any>;
19
+ }
20
+
21
+ const ThreadsViewComponent = ({ channelId,role, channelsDetail, refetchChannelDetail }: ThreadsViewProps) => {
22
+ const { params } = useRoute<any>();
23
+ const auth = useSelector(userSelector);
24
+ const dispatch = useDispatch();
25
+ const navigation = useNavigation<any>();
26
+ const isFocused = useIsFocused();
27
+ const [refreshing, setRefresh] = useState<boolean>(false);
28
+ const [threadData, setThreadsData] = useState<any>([]);
29
+
30
+ const {
31
+ data,
32
+ loading: threadLoading,
33
+ error,
34
+ refetch,
35
+ } = useThreadMessagesQuery({
36
+ variables: {
37
+ channelId: channelId?.toString(),
38
+ role:role?.toString(),
39
+ limit: MESSAGES_PER_PAGE,
40
+ },
41
+ fetchPolicy: 'cache-and-network',
42
+ });
43
+
44
+
45
+ const { data:threadCreatedUpdated} = useOnThreadCreatedUpdatedSubscription();
46
+
47
+ useFocusEffect(
48
+ React.useCallback(() => {
49
+ // Do something when the screen is focused
50
+ navigation?.setOptions({ title: params?.title ?? 'Thread' });
51
+ refetch({
52
+ channelId: channelId?.toString(),
53
+ role:role?.toString(),
54
+ limit: MESSAGES_PER_PAGE,
55
+ }).then(({ data }) => {
56
+ if (!data?.threadMessages?.data) {
57
+ return;
58
+ }
59
+
60
+ if(data?.threadMessages?.data?.length){
61
+ const { data:newThreads} = data?.threadMessages
62
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
63
+ }
64
+ });
65
+
66
+ return () => {
67
+ // Do something when the screen is unfocused
68
+ // Useful for cleanup functions
69
+ };
70
+ }, []),
71
+ );
72
+
73
+ React.useEffect(()=>{
74
+ if(data?.threadMessages?.data?.length){
75
+ const { data:newThreads} = data?.threadMessages
76
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
77
+ }
78
+
79
+ },[data])
80
+
81
+
82
+ React.useEffect(()=>{
83
+ if(threadCreatedUpdated?.threadCreatedUpdated?.data){
84
+ const { data:newThreads} = threadCreatedUpdated?.threadCreatedUpdated;
85
+
86
+ setThreadsData((oldThreads: any) => {
87
+ const i = oldThreads.findIndex((el:any) => el.id === newThreads?.id);
88
+ if (i > -1) oldThreads[i] = newThreads; // (2)
89
+ else oldThreads.push(newThreads);
90
+ return oldThreads;
91
+ });
92
+ // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
93
+ }
94
+
95
+ },[threadCreatedUpdated])
96
+
97
+ const threads = React.useMemo(() => {
98
+ if (!threadData?.length) return null;
99
+ return threadData || [];
100
+ }, [threadData]);
101
+
102
+ // const threads = React.useMemo(() => {
103
+ // if (!data?.threadMessages?.data?.length) return null;
104
+ // return data?.threadMessages?.data || [];
105
+ // }, [data]);
106
+
107
+ const handleSelectThread = useCallback((id: any, title: any, postParentId: any) => {
108
+ navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
109
+ channelId: id,
110
+ role:role?.toString(),
111
+ title: title,
112
+ postParentId: postParentId,
113
+ hideTabBar: true,
114
+ });
115
+ // if (params?.channelId) {
116
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
117
+ // channelId: params?.channelId,
118
+ // title: params?.title ?? null,
119
+ // postParentId: postParentId,
120
+ // hideTabBar: true,
121
+ // });
122
+ // } else {
123
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
124
+ // channelId: id,
125
+ // title: title,
126
+ // postParentId: postParentId,
127
+ // hideTabBar: true,
128
+ // });
129
+ // }
130
+ }, []);
131
+
132
+ const handleRefresh = useCallback(() => {
133
+ refetch({
134
+ channelId: channelId?.toString(),
135
+ role:role?.toString(),
136
+ limit: MESSAGES_PER_PAGE,
137
+ }).then(({ data }) => {
138
+ if (!data?.threadMessages?.data) {
139
+ return;
140
+ }
141
+
142
+ if(data?.threadMessages?.data?.length){
143
+ const { data:newThreads} = data?.threadMessages
144
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
145
+ }
146
+ });
147
+ }, []);
148
+
149
+ const fetchMoreThreads = useCallback(() => {
150
+ refetch({
151
+ channelId: channelId?.toString(),
152
+ role:role?.toString(),
153
+ skip: threads?.length,
154
+ });
155
+ }, []);
156
+
157
+
158
+
159
+ return (
160
+ <Box
161
+ flex={1}
162
+ p={2}
163
+ pb={0}
164
+ _dark={{
165
+ borderColor: 'coolGray.600',
166
+ backgroundColor: 'gray.700',
167
+ }}
168
+ _web={{
169
+ shadow: 2,
170
+ borderWidth: 0,
171
+ }}
172
+ _light={{
173
+ backgroundColor: 'gray.50',
174
+ }}
175
+ >
176
+ <FlatList
177
+ style={{flex:1}}
178
+ data={threads && threads?.length > 0 ? threads : []}
179
+ onRefresh={handleRefresh}
180
+ refreshing={threadLoading}
181
+ contentContainerStyle={{ paddingBottom:60 }}
182
+ ItemSeparatorComponent={() => <Box height="0.5" backgroundColor="gray.200" />}
183
+ renderItem={({ item: thread }) => (
184
+ <ThreadViewItem onOpen={handleSelectThread} currentUser={auth} thread={thread} />
185
+ )}
186
+ ListEmptyComponent={() => (
187
+ <>
188
+ {!threadLoading || threads?.length == 0}
189
+ <Box p={5}>
190
+ <Center mt={6}>
191
+ <Icon as={Ionicons} name="chatbubbles" size={'xl'} />
192
+ <Text>You don't have any message yet!</Text>
193
+ </Center>
194
+ </Box>
195
+ </>
196
+ )}
197
+ keyExtractor={(item, index) => 'threads-view-key' + index}
198
+ onEndReached={fetchMoreThreads}
199
+ onEndReachedThreshold={0.1}
200
+ />
201
+ </Box>
202
+ );
203
+ };
204
+
205
+ export const ThreadsView = React.memo(ThreadsViewComponent);
@@ -1,2 +1,4 @@
1
1
  export * from './inbox/Inbox';
2
- export * from './inbox/DialogMessages';
2
+ export * from './inbox/DialogMessages';
3
+ export * from './inbox/DialogThreads';
4
+ export * from './inbox/DialogThreadMessages'