@messenger-box/platform-mobile 10.0.3-alpha.7 → 10.0.3-alpha.72
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/CHANGELOG.md +116 -0
- package/lib/compute.js +2 -3
- package/lib/compute.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/queries/inboxQueries.js +65 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogMessages.js +1 -1
- package/lib/screens/inbox/DialogMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreadMessages.js +4 -8
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +57 -12
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/Inbox.js +1 -1
- package/lib/screens/inbox/Inbox.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/consts.js +1 -1
- package/lib/screens/inbox/components/CachedImage/consts.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/index.js +168 -46
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogItem.js +169 -0
- package/lib/screens/inbox/components/DialogItem.js.map +1 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +147 -31
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js +6 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/components/ThreadsViewItem.js +66 -55
- package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
- package/lib/screens/inbox/config/config.js +2 -2
- package/lib/screens/inbox/config/config.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +1111 -434
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +193 -80
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +725 -216
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +83 -50
- package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
- package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
- package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
- package/package.json +4 -4
- package/src/compute.ts +5 -6
- package/src/index.ts +2 -0
- package/src/navigation/InboxNavigation.tsx +3 -3
- package/src/queries/inboxQueries.ts +299 -0
- package/src/queries/index.d.ts +2 -0
- package/src/queries/index.ts +1 -0
- package/src/screens/inbox/DialogMessages.tsx +1 -1
- package/src/screens/inbox/DialogThreadMessages.tsx +7 -14
- package/src/screens/inbox/DialogThreads.tsx +55 -61
- package/src/screens/inbox/Inbox.tsx +1 -1
- package/src/screens/inbox/components/Actionsheet.tsx +30 -0
- package/src/screens/inbox/components/CachedImage/consts.ts +4 -3
- package/src/screens/inbox/components/CachedImage/index.tsx +232 -61
- package/src/screens/inbox/components/DialogItem.tsx +306 -0
- package/src/screens/inbox/components/DialogsHeader.tsx +6 -13
- package/src/screens/inbox/components/DialogsListItem.tsx +262 -198
- package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
- package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
- package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +337 -194
- package/src/screens/inbox/components/SlackInput.tsx +23 -0
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +233 -23
- package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +1 -1
- package/src/screens/inbox/components/SmartLoader.tsx +61 -0
- package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +53 -55
- package/src/screens/inbox/components/ThreadsViewItem.tsx +178 -285
- package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
- package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
- package/src/screens/inbox/config/config.ts +2 -2
- package/src/screens/inbox/containers/ConversationView.tsx +1843 -702
- package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
- package/src/screens/inbox/containers/Dialogs.tsx +402 -204
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +4 -4
- package/src/screens/inbox/containers/ThreadConversationView.tsx +1350 -319
- package/src/screens/inbox/containers/ThreadsView.tsx +105 -193
- package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +20 -0
- package/src/screens/inbox/containers/workflow/conversation-xstate.ts +313 -0
- package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +196 -0
- package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +401 -0
- package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
- package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
- package/src/screens/inbox/index.ts +37 -0
- package/src/screens/inbox/machines/threadsMachine.ts +147 -0
- package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
- package/tsconfig.json +11 -54
- package/lib/screens/inbox/components/DialogsListItem.js +0 -171
- package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -171
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
|
@@ -6,13 +6,14 @@ import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-na
|
|
|
6
6
|
import { orderBy, uniqBy, startCase } from 'lodash-es';
|
|
7
7
|
import {
|
|
8
8
|
useThreadMessagesQuery,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from '
|
|
9
|
+
THREAD_CREATED_UPDATED,
|
|
10
|
+
useThreadCreatedUpdatedSubscription,
|
|
11
|
+
} from '../../../queries/inboxQueries';
|
|
12
12
|
import { userSelector } from '@adminide-stack/user-auth0-client';
|
|
13
13
|
import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
|
|
14
14
|
import { ThreadViewItem } from '../components/ThreadsViewItem';
|
|
15
15
|
import { config } from '../config';
|
|
16
|
+
import { Actions } from '../workflow/dialog-threads-xstate';
|
|
16
17
|
const { MESSAGES_PER_PAGE } = config;
|
|
17
18
|
|
|
18
19
|
export interface ThreadsViewProps {
|
|
@@ -49,27 +50,46 @@ const ThreadsViewComponent = ({
|
|
|
49
50
|
const navigation = useNavigation<any>();
|
|
50
51
|
const isFocused = useIsFocused();
|
|
51
52
|
const [refreshing, setRefresh] = useState<boolean>(false);
|
|
52
|
-
const [threadData, setThreadsData] = useState<any>([]);
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
// Use thread subscription for real-time updates
|
|
55
|
+
const { data: threadCreatedUpdated } = useThreadCreatedUpdatedSubscription({
|
|
56
|
+
variables: { channelId: channelId?.toString() },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Subscribe to thread updates
|
|
60
|
+
const subscribeToNewMessages = useCallback(() => {
|
|
61
|
+
return subscribeToMore({
|
|
62
|
+
document: THREAD_CREATED_UPDATED,
|
|
63
|
+
variables: { channelId: channelId?.toString() },
|
|
64
|
+
updateQuery: (prev: any, { subscriptionData }: any) => {
|
|
65
|
+
if (!subscriptionData.data) return prev;
|
|
66
|
+
|
|
67
|
+
const newThread = subscriptionData.data.threadCreatedUpdated.data;
|
|
68
|
+
if (!newThread) return prev;
|
|
69
|
+
|
|
70
|
+
const threads = prev.threadMessages.data || [];
|
|
71
|
+
const index = threads.findIndex((t: any) => t.id === newThread.id);
|
|
72
|
+
|
|
73
|
+
let updatedThreads;
|
|
74
|
+
if (index > -1) {
|
|
75
|
+
// Update existing thread
|
|
76
|
+
updatedThreads = [...threads];
|
|
77
|
+
updatedThreads[index] = newThread;
|
|
78
|
+
} else {
|
|
79
|
+
// Add new thread
|
|
80
|
+
updatedThreads = [newThread, ...threads];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
...prev,
|
|
85
|
+
threadMessages: {
|
|
86
|
+
...prev.threadMessages,
|
|
87
|
+
data: uniqBy(updatedThreads, 'id'),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}, [channelId, subscribeToMore]);
|
|
73
93
|
|
|
74
94
|
useFocusEffect(
|
|
75
95
|
React.useCallback(() => {
|
|
@@ -81,64 +101,25 @@ const ThreadsViewComponent = ({
|
|
|
81
101
|
limit: MESSAGES_PER_PAGE,
|
|
82
102
|
repliesLimit2: 5,
|
|
83
103
|
});
|
|
84
|
-
// .then(({ data }) => {
|
|
85
|
-
// if (!data?.threadMessages?.data) {
|
|
86
|
-
// return;
|
|
87
|
-
// }
|
|
88
104
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
// setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
|
|
92
|
-
// }
|
|
93
|
-
// });
|
|
105
|
+
// Setup subscription
|
|
106
|
+
const unsubscribe = subscribeToNewMessages();
|
|
94
107
|
|
|
95
108
|
return () => {
|
|
96
|
-
//
|
|
97
|
-
|
|
109
|
+
// Unsubscribe on cleanup
|
|
110
|
+
if (unsubscribe) unsubscribe();
|
|
98
111
|
};
|
|
99
112
|
}, []),
|
|
100
113
|
);
|
|
101
114
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// React.useEffect(() => {
|
|
110
|
-
// if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
|
|
111
|
-
// const { data: newThreads } = threadCreatedUpdated?.threadCreatedUpdated;
|
|
112
|
-
|
|
113
|
-
// setThreadsData((oldThreads: any) => {
|
|
114
|
-
// const i = oldThreads.findIndex((el: any) => el.id === newThreads?.id);
|
|
115
|
-
// if (i > -1) oldThreads[i] = newThreads; // (2)
|
|
116
|
-
// else oldThreads.push(newThreads);
|
|
117
|
-
// return oldThreads;
|
|
118
|
-
// });
|
|
119
|
-
// // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
|
|
120
|
-
// }
|
|
121
|
-
// }, [threadCreatedUpdated]);
|
|
122
|
-
|
|
123
|
-
const setData = React.useCallback((newThreads: any) => {
|
|
124
|
-
setThreadsData((oldThreads: any) => {
|
|
125
|
-
const i = oldThreads.findIndex((el: any) => el.id === newThreads?.id);
|
|
126
|
-
if (i > -1) oldThreads[i] = newThreads; // (2)
|
|
127
|
-
else oldThreads.push(newThreads);
|
|
128
|
-
return oldThreads;
|
|
129
|
-
});
|
|
130
|
-
// setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
|
|
131
|
-
}, []);
|
|
132
|
-
|
|
133
|
-
// const threads = React.useMemo(() => {
|
|
134
|
-
// if (!threadData?.length) return null;
|
|
135
|
-
// return orderBy(threadData, ['updatedAt'], ['desc']) || [];
|
|
136
|
-
// //return threadData || [];
|
|
137
|
-
// }, [threadData]);
|
|
115
|
+
// Effect for thread updates from subscription
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
|
|
118
|
+
// The subscription handler will handle updates
|
|
119
|
+
}
|
|
120
|
+
}, [threadCreatedUpdated]);
|
|
138
121
|
|
|
139
122
|
const threads = React.useMemo(() => {
|
|
140
|
-
// if (!data?.threadMessages?.data?.length) return null;
|
|
141
|
-
// const { data: newThreads } = data?.threadMessages;
|
|
142
123
|
if (data?.threadMessages?.data?.length == 0) return [];
|
|
143
124
|
const threadsFiltered = data?.threadMessages?.data
|
|
144
125
|
? uniqBy([...data?.threadMessages?.data], ({ id }: any) => id)
|
|
@@ -149,7 +130,6 @@ const ThreadsViewComponent = ({
|
|
|
149
130
|
const threadReplies = React.useMemo(() => {
|
|
150
131
|
if (!threads?.length) return null;
|
|
151
132
|
return threads?.map((t: any) => t?.replies)?.flat(1) || [];
|
|
152
|
-
//return threadData || [];
|
|
153
133
|
}, [threads]);
|
|
154
134
|
|
|
155
135
|
const handleSelectThread = useCallback((id: any, title: any, postParentId: any) => {
|
|
@@ -160,153 +140,85 @@ const ThreadsViewComponent = ({
|
|
|
160
140
|
postParentId: postParentId,
|
|
161
141
|
hideTabBar: true,
|
|
162
142
|
});
|
|
163
|
-
// if (params?.channelId) {
|
|
164
|
-
// navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
|
|
165
|
-
// channelId: params?.channelId,
|
|
166
|
-
// title: params?.title ?? null,
|
|
167
|
-
// postParentId: postParentId,
|
|
168
|
-
// hideTabBar: true,
|
|
169
|
-
// });
|
|
170
|
-
// } else {
|
|
171
|
-
// navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
|
|
172
|
-
// channelId: id,
|
|
173
|
-
// title: title,
|
|
174
|
-
// postParentId: postParentId,
|
|
175
|
-
// hideTabBar: true,
|
|
176
|
-
// });
|
|
177
|
-
// }
|
|
178
143
|
}, []);
|
|
179
144
|
|
|
180
145
|
const handleRefresh = useCallback(() => {
|
|
146
|
+
setRefresh(true);
|
|
181
147
|
refetch({
|
|
182
148
|
channelId: channelId?.toString(),
|
|
183
149
|
role: role?.toString(),
|
|
184
150
|
limit: MESSAGES_PER_PAGE,
|
|
185
151
|
repliesLimit2: 5,
|
|
152
|
+
}).finally(() => {
|
|
153
|
+
setRefresh(false);
|
|
186
154
|
});
|
|
187
|
-
// .then(({ data }) => {
|
|
188
|
-
// if (!data?.threadMessages?.data) {
|
|
189
|
-
// return;
|
|
190
|
-
// }
|
|
191
|
-
|
|
192
|
-
// if (data?.threadMessages?.data?.length) {
|
|
193
|
-
// const { data: newThreads } = data?.threadMessages;
|
|
194
|
-
// setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
|
|
195
|
-
// }
|
|
196
|
-
// });
|
|
197
155
|
}, []);
|
|
198
156
|
|
|
199
157
|
const fetchMoreThreads = useCallback(() => {
|
|
200
158
|
refetch({
|
|
201
159
|
channelId: channelId?.toString(),
|
|
202
160
|
role: role?.toString(),
|
|
203
|
-
|
|
161
|
+
limit: MESSAGES_PER_PAGE,
|
|
162
|
+
repliesLimit2: 5,
|
|
204
163
|
});
|
|
205
164
|
}, []);
|
|
206
165
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
166
|
+
if (error) {
|
|
167
|
+
return (
|
|
168
|
+
<Box style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
169
|
+
<Text>Error loading threads. {error.message}</Text>
|
|
170
|
+
<Button onPress={handleRefresh} style={{ marginTop: 4 }}>
|
|
171
|
+
<Text>Try Again</Text>
|
|
172
|
+
</Button>
|
|
173
|
+
</Box>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
215
176
|
|
|
216
177
|
return (
|
|
217
|
-
<Box
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
key={index}
|
|
235
|
-
onOpen={handleSelectThread}
|
|
236
|
-
currentUser={auth}
|
|
237
|
-
thread={thread}
|
|
238
|
-
role={role}
|
|
239
|
-
setData={setData}
|
|
240
|
-
/>
|
|
241
|
-
)}
|
|
242
|
-
ListEmptyComponent={() => (
|
|
243
|
-
<>
|
|
244
|
-
{/* {!threadLoading || threads?.length == 0} */}
|
|
245
|
-
{!threadLoading && threads?.length == 0 && (
|
|
246
|
-
<Box p={'$5'}>
|
|
247
|
-
<Center mt={'$6'}>
|
|
248
|
-
<Ionicons name="chatbubbles" size={50} />
|
|
249
|
-
<Text>You don't have any message yet!</Text>
|
|
250
|
-
</Center>
|
|
251
|
-
</Box>
|
|
252
|
-
)}
|
|
253
|
-
</>
|
|
254
|
-
)}
|
|
255
|
-
ListFooterComponent={() => (
|
|
256
|
-
<>
|
|
257
|
-
<SubscriptionHandler
|
|
178
|
+
<Box style={{ flex: 1 }}>
|
|
179
|
+
{threadLoading && !threads?.length ? (
|
|
180
|
+
<Center style={{ flex: 1 }}>
|
|
181
|
+
<Spinner size="large" />
|
|
182
|
+
</Center>
|
|
183
|
+
) : threads?.length === 0 ? (
|
|
184
|
+
<Box style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
185
|
+
<Text>No threads found</Text>
|
|
186
|
+
</Box>
|
|
187
|
+
) : (
|
|
188
|
+
<FlatList
|
|
189
|
+
data={threads}
|
|
190
|
+
keyExtractor={(item) => item.id.toString()}
|
|
191
|
+
renderItem={({ item }) => (
|
|
192
|
+
<ThreadViewItem
|
|
193
|
+
{...item}
|
|
194
|
+
onPress={handleSelectThread}
|
|
258
195
|
channelId={channelId}
|
|
259
|
-
|
|
260
|
-
subscribeToMore({
|
|
261
|
-
document: THREAD_CHAT_ADDED,
|
|
262
|
-
variables: {
|
|
263
|
-
channelId: channelId?.toString(),
|
|
264
|
-
postParentId: null,
|
|
265
|
-
},
|
|
266
|
-
updateQuery: (prev, { subscriptionData }: any) => {
|
|
267
|
-
if (!subscriptionData.data) return prev;
|
|
268
|
-
const newPostThreadData: any =
|
|
269
|
-
subscriptionData?.data?.threadCreatedUpdated?.data;
|
|
270
|
-
const newMessage: any =
|
|
271
|
-
subscriptionData?.data?.threadCreatedUpdated?.lastMessage;
|
|
272
|
-
const data = prev?.threadMessages?.data?.map((t: any) =>
|
|
273
|
-
t.id === newPostThreadData?.id
|
|
274
|
-
? {
|
|
275
|
-
...t,
|
|
276
|
-
replies: [newMessage, ...t?.replies],
|
|
277
|
-
replyCount: newPostThreadData?.replyCount,
|
|
278
|
-
lastReplyAt: newPostThreadData?.lastReplyAt,
|
|
279
|
-
updatedAt: newPostThreadData?.updatedAt,
|
|
280
|
-
}
|
|
281
|
-
: t,
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
return Object.assign({}, prev, {
|
|
285
|
-
threadMessages: {
|
|
286
|
-
...prev?.threadMessages,
|
|
287
|
-
// totalCount: prev?.threadMessages?.totalCount + 1,
|
|
288
|
-
data: data,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
},
|
|
292
|
-
})
|
|
293
|
-
}
|
|
196
|
+
channelsDetail={channelsDetail}
|
|
294
197
|
/>
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
198
|
+
)}
|
|
199
|
+
refreshing={refreshing}
|
|
200
|
+
onRefresh={handleRefresh}
|
|
201
|
+
onEndReached={fetchMoreThreads}
|
|
202
|
+
onEndReachedThreshold={0.5}
|
|
203
|
+
contentContainerStyle={{ padding: 16 }}
|
|
204
|
+
ItemSeparatorComponent={() => <Box style={{ height: 3 }} />}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
<SubscriptionHandler subscribeToNewMessages={subscribeToNewMessages} channelId={channelId} />
|
|
301
208
|
</Box>
|
|
302
209
|
);
|
|
303
210
|
};
|
|
304
211
|
|
|
212
|
+
// Component to handle subscription logic
|
|
305
213
|
const SubscriptionHandler = ({ subscribeToNewMessages, channelId }: IThreadSubscriptionHandlerProps) => {
|
|
306
|
-
useEffect(() =>
|
|
307
|
-
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
const unsubscribe = subscribeToNewMessages();
|
|
216
|
+
return () => {
|
|
217
|
+
if (unsubscribe) unsubscribe();
|
|
218
|
+
};
|
|
219
|
+
}, [channelId]);
|
|
220
|
+
|
|
221
|
+
return null;
|
|
308
222
|
};
|
|
309
223
|
|
|
310
224
|
export const ThreadsView = ThreadsViewComponent;
|
|
311
|
-
|
|
312
|
-
// export const ThreadsView = React.memo(ThreadsViewComponent);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApolloError, FetchResult, SingleExecutionResult } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
// Accept any promise-like object with a data field
|
|
4
|
+
export const newHandleMutationResult = async (
|
|
5
|
+
promise: Promise<any>,
|
|
6
|
+
transformer: (result: any) => any,
|
|
7
|
+
): Promise<any> => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await promise;
|
|
10
|
+
if (result.errors) {
|
|
11
|
+
throw result.errors;
|
|
12
|
+
}
|
|
13
|
+
if (!result.data) {
|
|
14
|
+
throw new Error('No data returned from query');
|
|
15
|
+
}
|
|
16
|
+
return transformer(result.data);
|
|
17
|
+
} catch (error: any) {
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|