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

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 (28) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/index.js +2085 -527
  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 +28 -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/SupportServiceDialogsListItem.tsx +295 -0
  21. package/src/screens/inbox/components/ThreadsViewItem.tsx +229 -0
  22. package/src/screens/inbox/config/config.ts +4 -0
  23. package/src/screens/inbox/containers/ConversationView.tsx +288 -95
  24. package/src/screens/inbox/containers/Dialogs.tsx +2 -1
  25. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +119 -0
  26. package/src/screens/inbox/containers/ThreadConversationView.tsx +700 -0
  27. package/src/screens/inbox/containers/ThreadsView.tsx +186 -0
  28. package/src/screens/index.ts +3 -1
@@ -0,0 +1,186 @@
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 } 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
+ useFocusEffect(
45
+ React.useCallback(() => {
46
+ // Do something when the screen is focused
47
+ navigation?.setOptions({ title: params?.title ?? 'Thread' });
48
+ refetch({
49
+ channelId: channelId?.toString(),
50
+ role:role?.toString(),
51
+ limit: MESSAGES_PER_PAGE,
52
+ }).then(({ data }) => {
53
+ if (!data?.threadMessages?.data) {
54
+ return;
55
+ }
56
+
57
+ if(data?.threadMessages?.data?.length){
58
+ const { data:newThreads} = data?.threadMessages
59
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
60
+ }
61
+ });
62
+
63
+ return () => {
64
+ // Do something when the screen is unfocused
65
+ // Useful for cleanup functions
66
+ };
67
+ }, []),
68
+ );
69
+
70
+ React.useEffect(()=>{
71
+ if(data?.threadMessages?.data?.length){
72
+ const { data:newThreads} = data?.threadMessages
73
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
74
+ }
75
+
76
+ },[data])
77
+
78
+ const threads = React.useMemo(() => {
79
+ if (!threadData?.length) return null;
80
+ return threadData || [];
81
+ }, [threadData]);
82
+
83
+ // const threads = React.useMemo(() => {
84
+ // if (!data?.threadMessages?.data?.length) return null;
85
+ // return data?.threadMessages?.data || [];
86
+ // }, [data]);
87
+
88
+ const handleSelectThread = useCallback((id: any, title: any, postParentId: any) => {
89
+ navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
90
+ channelId: id,
91
+ role:role?.toString(),
92
+ title: title,
93
+ postParentId: postParentId,
94
+ hideTabBar: true,
95
+ });
96
+ // if (params?.channelId) {
97
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
98
+ // channelId: params?.channelId,
99
+ // title: params?.title ?? null,
100
+ // postParentId: postParentId,
101
+ // hideTabBar: true,
102
+ // });
103
+ // } else {
104
+ // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
105
+ // channelId: id,
106
+ // title: title,
107
+ // postParentId: postParentId,
108
+ // hideTabBar: true,
109
+ // });
110
+ // }
111
+ }, []);
112
+
113
+ const handleRefresh = useCallback(() => {
114
+ refetch({
115
+ channelId: channelId?.toString(),
116
+ role:role?.toString(),
117
+ limit: MESSAGES_PER_PAGE,
118
+ }).then(({ data }) => {
119
+ if (!data?.threadMessages?.data) {
120
+ return;
121
+ }
122
+
123
+ if(data?.threadMessages?.data?.length){
124
+ const { data:newThreads} = data?.threadMessages
125
+ setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
126
+ }
127
+ });
128
+ }, []);
129
+
130
+ const fetchMoreThreads = useCallback(() => {
131
+ refetch({
132
+ channelId: channelId?.toString(),
133
+ role:role?.toString(),
134
+ skip: threads?.length,
135
+ });
136
+ }, []);
137
+
138
+
139
+
140
+ return (
141
+ <Box
142
+ flex={1}
143
+ p={2}
144
+ pb={0}
145
+ _dark={{
146
+ borderColor: 'coolGray.600',
147
+ backgroundColor: 'gray.700',
148
+ }}
149
+ _web={{
150
+ shadow: 2,
151
+ borderWidth: 0,
152
+ }}
153
+ _light={{
154
+ backgroundColor: 'gray.50',
155
+ }}
156
+ >
157
+ <FlatList
158
+ style={{flex:1}}
159
+ data={threads && threads?.length > 0 ? threads : []}
160
+ onRefresh={handleRefresh}
161
+ refreshing={threadLoading}
162
+ contentContainerStyle={{ paddingBottom:60 }}
163
+ ItemSeparatorComponent={() => <Box height="0.5" backgroundColor="gray.200" />}
164
+ renderItem={({ item: thread }) => (
165
+ <ThreadViewItem onOpen={handleSelectThread} currentUser={auth} thread={thread} />
166
+ )}
167
+ ListEmptyComponent={() => (
168
+ <>
169
+ {!threadLoading || threads?.length == 0}
170
+ <Box p={5}>
171
+ <Center mt={6}>
172
+ <Icon as={Ionicons} name="chatbubbles" size={'xl'} />
173
+ <Text>You don't have any message yet!</Text>
174
+ </Center>
175
+ </Box>
176
+ </>
177
+ )}
178
+ keyExtractor={(item, index) => 'threads-view-key' + index}
179
+ onEndReached={fetchMoreThreads}
180
+ onEndReachedThreshold={0.1}
181
+ />
182
+ </Box>
183
+ );
184
+ };
185
+
186
+ 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'