@messenger-box/platform-mobile 10.0.3-alpha.23 → 10.0.3-alpha.232
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/lib/components/messages-container-ui/BuildModeView.js +428 -0
- package/lib/components/messages-container-ui/BuildModeView.js.map +1 -0
- package/lib/components/messages-container-ui/MessagesContainerUI.js +55 -0
- package/lib/components/messages-container-ui/MessagesContainerUI.js.map +1 -0
- package/lib/components/messages-container-ui/PlanModeView.js +336 -0
- package/lib/components/messages-container-ui/PlanModeView.js.map +1 -0
- package/lib/compute.js +2 -3
- package/lib/compute.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/module.js.map +1 -1
- package/lib/queries/inboxQueries.js +62 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogMessages.js +8 -3
- package/lib/screens/inbox/DialogMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreadMessages.js +6 -11
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +9 -11
- package/lib/screens/inbox/DialogThreads.js.map +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 +125 -96
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogItem.js +160 -0
- package/lib/screens/inbox/components/DialogItem.js.map +1 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +315 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js +3 -1
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js +194 -0
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +149 -36
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js +4 -5
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +22 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/components/ThreadsViewItem.js +2 -4
- package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
- package/lib/screens/inbox/config/config.js +4 -2
- package/lib/screens/inbox/config/config.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +1093 -1090
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +130 -577
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +864 -1408
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +9 -15
- 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 +1 -1
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -1
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -1
- package/package.json +10 -8
- package/CHANGELOG.md +0 -172
- package/jest.config.js +0 -24
- package/lib/screens/inbox/components/DialogsListItem.js +0 -548
- package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -489
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +0 -175
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +0 -191
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js +0 -380
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +0 -211
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js +0 -438
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js.map +0 -1
- package/rollup.config.mjs +0 -45
- package/src/components/index.ts +0 -0
- package/src/compute.ts +0 -63
- package/src/index.ts +0 -7
- package/src/module.ts +0 -10
- package/src/navigation/InboxNavigation.tsx +0 -102
- package/src/navigation/index.ts +0 -1
- package/src/screens/inbox/DialogMessages.tsx +0 -21
- package/src/screens/inbox/DialogThreadMessages.tsx +0 -97
- package/src/screens/inbox/DialogThreads.tsx +0 -125
- package/src/screens/inbox/Inbox.tsx +0 -17
- package/src/screens/inbox/components/CachedImage/consts.ts +0 -6
- package/src/screens/inbox/components/CachedImage/index.tsx +0 -223
- package/src/screens/inbox/components/DialogsHeader.tsx +0 -30
- package/src/screens/inbox/components/DialogsListItem.tsx +0 -819
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +0 -679
- package/src/screens/inbox/components/SlackMessageContainer/ImageViewerModal.tsx +0 -113
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +0 -313
- package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +0 -145
- package/src/screens/inbox/components/SlackMessageContainer/index.ts +0 -3
- package/src/screens/inbox/components/SmartLoader.tsx +0 -61
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +0 -301
- package/src/screens/inbox/components/ThreadsViewItem.tsx +0 -233
- package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +0 -145
- package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +0 -159
- package/src/screens/inbox/config/config.ts +0 -15
- package/src/screens/inbox/config/index.ts +0 -1
- package/src/screens/inbox/containers/ConversationView.tsx +0 -1784
- package/src/screens/inbox/containers/Dialogs.tsx +0 -829
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +0 -119
- package/src/screens/inbox/containers/ThreadConversationView.tsx +0 -2295
- package/src/screens/inbox/containers/ThreadsView.tsx +0 -224
- package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +0 -20
- package/src/screens/inbox/containers/workflow/conversation-xstate.ts +0 -313
- package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +0 -196
- package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +0 -401
- package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +0 -136
- package/src/screens/inbox/index.ts +0 -37
- package/src/screens/inbox/machines/threadsMachine.ts +0 -147
- package/src/screens/inbox/workflow/dialog-threads-xstate.ts +0 -163
- package/src/screens/index.ts +0 -4
- package/tsconfig.json +0 -13
- package/webpack.config.js +0 -58
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback, useMemo } from 'react';
|
|
2
|
-
import { BaseState, Actions, dialogThreadsXstate } from '../workflow/dialog-threads-xstate';
|
|
3
|
-
|
|
4
|
-
// Define proper types for the state and context
|
|
5
|
-
export interface DialogThreadsContext {
|
|
6
|
-
channelId?: string;
|
|
7
|
-
postParentId?: string | number;
|
|
8
|
-
role?: string;
|
|
9
|
-
channelsDetail: any;
|
|
10
|
-
threadData: any[];
|
|
11
|
-
loading: boolean;
|
|
12
|
-
error: any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface DialogThreadsState {
|
|
16
|
-
context: DialogThreadsContext;
|
|
17
|
-
value: BaseState;
|
|
18
|
-
matches: (stateValue: string) => boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Define proper action types
|
|
22
|
-
export type DialogThreadsEvent =
|
|
23
|
-
| { type: typeof Actions.INITIALIZE; data: { channelId?: string; postParentId?: string | number; role?: string } }
|
|
24
|
-
| { type: typeof Actions.FETCH_CHANNEL_DETAIL; data: { id: string } }
|
|
25
|
-
| { type: typeof Actions.SET_CHANNEL_DETAIL; data: { channelsDetail: any } }
|
|
26
|
-
| { type: typeof Actions.FETCH_THREADS; data?: any }
|
|
27
|
-
| { type: typeof Actions.SET_THREADS; data: { threadData: any[] } }
|
|
28
|
-
| { type: typeof Actions.ERROR; data: { error: any } };
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Custom hook to safely use the dialog threads state machine
|
|
32
|
-
* This provides a fallback implementation in case useMachine from XState has issues
|
|
33
|
-
*/
|
|
34
|
-
export function useSafeDialogThreadsMachine(): [DialogThreadsState, (event: DialogThreadsEvent) => void] {
|
|
35
|
-
// Initialize with default state from the machine's initial context
|
|
36
|
-
const [state, setState] = useState<DialogThreadsState>({
|
|
37
|
-
context: {
|
|
38
|
-
channelId: undefined,
|
|
39
|
-
postParentId: undefined,
|
|
40
|
-
role: undefined,
|
|
41
|
-
channelsDetail: null,
|
|
42
|
-
threadData: [],
|
|
43
|
-
loading: true,
|
|
44
|
-
error: null,
|
|
45
|
-
},
|
|
46
|
-
value: BaseState.Idle,
|
|
47
|
-
matches: (value: string) => value === BaseState.Idle,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Create a memoized function to determine state matching
|
|
51
|
-
const matches = useCallback((value: string) => value === state.value, [state.value]);
|
|
52
|
-
|
|
53
|
-
// Update the matches function when state changes
|
|
54
|
-
useMemo(() => {
|
|
55
|
-
setState((prev) => ({
|
|
56
|
-
...prev,
|
|
57
|
-
matches,
|
|
58
|
-
}));
|
|
59
|
-
}, [matches]);
|
|
60
|
-
|
|
61
|
-
// Create a safe send function to handle events
|
|
62
|
-
const send = useCallback((event: DialogThreadsEvent) => {
|
|
63
|
-
try {
|
|
64
|
-
// Handle specific events based on the event type
|
|
65
|
-
if (event.type === Actions.INITIALIZE) {
|
|
66
|
-
setState((prev) => ({
|
|
67
|
-
...prev,
|
|
68
|
-
context: {
|
|
69
|
-
...prev.context,
|
|
70
|
-
channelId: event.data?.channelId,
|
|
71
|
-
postParentId: event.data?.postParentId,
|
|
72
|
-
role: event.data?.role,
|
|
73
|
-
loading: true,
|
|
74
|
-
error: null,
|
|
75
|
-
},
|
|
76
|
-
value: BaseState.LoadingChannel,
|
|
77
|
-
}));
|
|
78
|
-
} else if (event.type === Actions.SET_CHANNEL_DETAIL) {
|
|
79
|
-
setState((prev) => ({
|
|
80
|
-
...prev,
|
|
81
|
-
context: {
|
|
82
|
-
...prev.context,
|
|
83
|
-
channelsDetail: event.data?.channelsDetail,
|
|
84
|
-
loading: false,
|
|
85
|
-
},
|
|
86
|
-
value: BaseState.LoadingThreads,
|
|
87
|
-
}));
|
|
88
|
-
} else if (event.type === Actions.SET_THREADS) {
|
|
89
|
-
setState((prev) => ({
|
|
90
|
-
...prev,
|
|
91
|
-
context: {
|
|
92
|
-
...prev.context,
|
|
93
|
-
threadData: event.data?.threadData || [],
|
|
94
|
-
loading: false,
|
|
95
|
-
},
|
|
96
|
-
value: BaseState.Active,
|
|
97
|
-
}));
|
|
98
|
-
} else if (event.type === Actions.FETCH_THREADS) {
|
|
99
|
-
setState((prev) => ({
|
|
100
|
-
...prev,
|
|
101
|
-
context: {
|
|
102
|
-
...prev.context,
|
|
103
|
-
loading: true,
|
|
104
|
-
},
|
|
105
|
-
value: BaseState.LoadingThreads,
|
|
106
|
-
}));
|
|
107
|
-
} else if (event.type === Actions.ERROR) {
|
|
108
|
-
setState((prev) => ({
|
|
109
|
-
...prev,
|
|
110
|
-
context: {
|
|
111
|
-
...prev.context,
|
|
112
|
-
error: event.data?.error,
|
|
113
|
-
loading: false,
|
|
114
|
-
},
|
|
115
|
-
value: BaseState.Error,
|
|
116
|
-
}));
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
// Handle errors gracefully
|
|
120
|
-
setState((prev) => ({
|
|
121
|
-
...prev,
|
|
122
|
-
context: {
|
|
123
|
-
...prev.context,
|
|
124
|
-
error,
|
|
125
|
-
loading: false,
|
|
126
|
-
},
|
|
127
|
-
value: BaseState.Error,
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
}, []);
|
|
131
|
-
|
|
132
|
-
// Return as a tuple to match useMachine API
|
|
133
|
-
return [state, send];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export default useSafeDialogThreadsMachine;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// State machines
|
|
2
|
-
export {
|
|
3
|
-
dialogThreadsXstate,
|
|
4
|
-
Actions as DialogThreadsActions,
|
|
5
|
-
BaseState as DialogThreadsState,
|
|
6
|
-
} from './workflow/dialog-threads-xstate';
|
|
7
|
-
export {
|
|
8
|
-
threadConversationXstate,
|
|
9
|
-
Actions as ThreadConversationActions,
|
|
10
|
-
BaseState as ThreadConversationState,
|
|
11
|
-
} from './containers/workflow/thread-conversation-xstate';
|
|
12
|
-
export {
|
|
13
|
-
conversationXstate,
|
|
14
|
-
Actions as ConversationActions,
|
|
15
|
-
BaseState as ConversationState,
|
|
16
|
-
} from './containers/workflow/conversation-xstate';
|
|
17
|
-
export {
|
|
18
|
-
dialogsXstate,
|
|
19
|
-
Actions as DialogsActions,
|
|
20
|
-
BaseState as DialogsState,
|
|
21
|
-
} from './containers/workflow/dialogs-xstate';
|
|
22
|
-
|
|
23
|
-
// Hooks
|
|
24
|
-
export { default as useSafeDialogThreadsMachine } from './hooks/useSafeDialogThreadsMachine';
|
|
25
|
-
|
|
26
|
-
// Components
|
|
27
|
-
export { DialogThreads } from './DialogThreads';
|
|
28
|
-
export { ThreadsView } from './containers/ThreadsView';
|
|
29
|
-
export { ThreadConversationView } from './containers/ThreadConversationView';
|
|
30
|
-
export { ConversationView } from './containers/ConversationView';
|
|
31
|
-
export { Dialogs } from './containers/Dialogs';
|
|
32
|
-
|
|
33
|
-
// Configuration
|
|
34
|
-
export { config } from './config';
|
|
35
|
-
|
|
36
|
-
// Utility
|
|
37
|
-
export { threadsMachineConfig, setupThreadSubscription } from './machines/threadsMachine';
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { orderBy, uniqBy } from 'lodash-es';
|
|
2
|
-
import { config } from '../config';
|
|
3
|
-
import { OnThreadCreatedUpdatedDocument as THREAD_CHAT_ADDED } from 'common/graphql';
|
|
4
|
-
|
|
5
|
-
const { MESSAGES_PER_PAGE } = config;
|
|
6
|
-
|
|
7
|
-
// Define more specific types for threads and thread data
|
|
8
|
-
export interface Thread {
|
|
9
|
-
id: string;
|
|
10
|
-
updatedAt?: string | number; // Make updatedAt optional to match the GraphQL response
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ThreadsData {
|
|
15
|
-
threadMessages?: {
|
|
16
|
-
data: Thread[] | any[]; // Allow any[] to accommodate GraphQL response types
|
|
17
|
-
};
|
|
18
|
-
[key: string]: any; // Allow additional properties from GraphQL responses
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ThreadsContext {
|
|
22
|
-
threads: Thread[];
|
|
23
|
-
loading: boolean;
|
|
24
|
-
error: any;
|
|
25
|
-
channelId?: string;
|
|
26
|
-
role?: string;
|
|
27
|
-
refreshing: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Type for refetch function
|
|
31
|
-
export type RefetchFunction = (variables: any) => Promise<{ data?: any }>;
|
|
32
|
-
|
|
33
|
-
// Type for subscription function
|
|
34
|
-
export type SubscribeFunction = (options: {
|
|
35
|
-
document: any;
|
|
36
|
-
variables: any;
|
|
37
|
-
updateQuery: (prev: any, { subscriptionData }: any) => any;
|
|
38
|
-
}) => () => void;
|
|
39
|
-
|
|
40
|
-
// Define machine actions and services with proper typing
|
|
41
|
-
export const threadsMachineConfig = {
|
|
42
|
-
// Services
|
|
43
|
-
fetchThreads: (refetch: RefetchFunction, context: ThreadsContext) => {
|
|
44
|
-
if (!context.channelId) return Promise.resolve({ data: undefined });
|
|
45
|
-
|
|
46
|
-
return refetch({
|
|
47
|
-
channelId: context.channelId?.toString(),
|
|
48
|
-
role: context.role?.toString(),
|
|
49
|
-
limit: MESSAGES_PER_PAGE,
|
|
50
|
-
repliesLimit2: 5,
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
fetchMoreThreads: (refetch: RefetchFunction, context: ThreadsContext) => {
|
|
55
|
-
if (!context.channelId || !context.threads?.length) {
|
|
56
|
-
return Promise.resolve({ data: undefined });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return refetch({
|
|
60
|
-
channelId: context.channelId?.toString(),
|
|
61
|
-
role: context.role?.toString(),
|
|
62
|
-
skip: context.threads?.length,
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
refreshThreads: (refetch: RefetchFunction, context: ThreadsContext) => {
|
|
67
|
-
if (!context.channelId) return Promise.resolve({ data: undefined });
|
|
68
|
-
|
|
69
|
-
return refetch({
|
|
70
|
-
channelId: context.channelId?.toString(),
|
|
71
|
-
role: context.role?.toString(),
|
|
72
|
-
limit: MESSAGES_PER_PAGE,
|
|
73
|
-
repliesLimit2: 5,
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
// Actions - optimized for performance with proper type handling
|
|
78
|
-
setThreadData: (data: ThreadsData): Thread[] => {
|
|
79
|
-
if (!data?.threadMessages?.data) return [];
|
|
80
|
-
|
|
81
|
-
const threadsData = data.threadMessages.data;
|
|
82
|
-
if (!threadsData.length) return [];
|
|
83
|
-
|
|
84
|
-
// Use a more efficient process with proper typing
|
|
85
|
-
const threadsFiltered = uniqBy(threadsData, 'id');
|
|
86
|
-
return orderBy(threadsFiltered, ['updatedAt'], ['desc']) || [];
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
appendThreadData: (existingThreads: Thread[], data: ThreadsData): Thread[] => {
|
|
90
|
-
if (!data?.threadMessages?.data) return existingThreads;
|
|
91
|
-
|
|
92
|
-
const newThreads = data.threadMessages.data;
|
|
93
|
-
if (!newThreads.length) return existingThreads;
|
|
94
|
-
|
|
95
|
-
// Use a more efficient combination process
|
|
96
|
-
const combinedThreads = uniqBy([...existingThreads, ...newThreads], 'id');
|
|
97
|
-
return orderBy(combinedThreads, ['updatedAt'], ['desc']) || [];
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
updateThreadData: (oldThreads: Thread[], newThread: Thread | null): Thread[] => {
|
|
101
|
-
if (!newThread) return oldThreads;
|
|
102
|
-
if (!oldThreads?.length) return [newThread]; // Handle empty array case efficiently
|
|
103
|
-
|
|
104
|
-
// Check if thread exists to avoid unnecessary array copy
|
|
105
|
-
const index = oldThreads.findIndex((el) => el.id === newThread.id);
|
|
106
|
-
|
|
107
|
-
let updatedThreads: Thread[];
|
|
108
|
-
if (index > -1) {
|
|
109
|
-
// Create a new array only if we're updating
|
|
110
|
-
updatedThreads = [...oldThreads];
|
|
111
|
-
updatedThreads[index] = newThread;
|
|
112
|
-
} else {
|
|
113
|
-
// Simply add the new thread at the beginning for efficiency
|
|
114
|
-
updatedThreads = [newThread, ...oldThreads];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return orderBy(updatedThreads, ['updatedAt'], ['desc']) || [];
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// Optimized function to subscribe to thread updates
|
|
122
|
-
export const setupThreadSubscription = (
|
|
123
|
-
subscribeToMore: SubscribeFunction | undefined,
|
|
124
|
-
channelId: string | undefined,
|
|
125
|
-
): (() => void) | undefined => {
|
|
126
|
-
if (!subscribeToMore || !channelId) return undefined;
|
|
127
|
-
|
|
128
|
-
return subscribeToMore({
|
|
129
|
-
document: THREAD_CHAT_ADDED,
|
|
130
|
-
variables: { channelId: channelId?.toString() },
|
|
131
|
-
updateQuery: (prev, { subscriptionData }) => {
|
|
132
|
-
if (!subscriptionData?.data) return prev;
|
|
133
|
-
|
|
134
|
-
const newThread = subscriptionData.data.threadCreatedUpdated?.data;
|
|
135
|
-
if (!newThread) return prev;
|
|
136
|
-
|
|
137
|
-
// Only create a new object if needed to optimize for unnecessary renders
|
|
138
|
-
return {
|
|
139
|
-
...prev,
|
|
140
|
-
threadMessages: {
|
|
141
|
-
...prev.threadMessages,
|
|
142
|
-
data: uniqBy([newThread, ...(prev.threadMessages?.data || [])], 'id'),
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
};
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { assign, setup } from 'xstate';
|
|
2
|
-
import { threadsMachineConfig } from '../machines/threadsMachine';
|
|
3
|
-
|
|
4
|
-
export enum BaseState {
|
|
5
|
-
Idle = 'idle',
|
|
6
|
-
LoadingChannel = 'loadingChannel',
|
|
7
|
-
LoadingThreads = 'loadingThreads',
|
|
8
|
-
Active = 'active',
|
|
9
|
-
Error = 'error',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export enum Actions {
|
|
13
|
-
INITIALIZE = 'INITIALIZE',
|
|
14
|
-
FETCH_CHANNEL_DETAIL = 'FETCH_CHANNEL_DETAIL',
|
|
15
|
-
SET_CHANNEL_DETAIL = 'SET_CHANNEL_DETAIL',
|
|
16
|
-
FETCH_THREADS = 'FETCH_THREADS',
|
|
17
|
-
SET_THREADS = 'SET_THREADS',
|
|
18
|
-
ERROR = 'ERROR',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Type definitions for the event data
|
|
22
|
-
type InitializeEventData = { channelId?: string; postParentId?: string; role?: string };
|
|
23
|
-
type ChannelDetailEventData = { id: string };
|
|
24
|
-
type SetChannelDetailEventData = { channelsDetail: any };
|
|
25
|
-
type SetThreadsEventData = { threadData: any[] };
|
|
26
|
-
type ErrorEventData = { error: any };
|
|
27
|
-
|
|
28
|
-
export const dialogThreadsXstate = setup({
|
|
29
|
-
types: {
|
|
30
|
-
context: {} as {
|
|
31
|
-
channelId?: string;
|
|
32
|
-
postParentId?: string;
|
|
33
|
-
role?: string;
|
|
34
|
-
channelsDetail: any;
|
|
35
|
-
threadData: any[];
|
|
36
|
-
loading: boolean;
|
|
37
|
-
error: any;
|
|
38
|
-
},
|
|
39
|
-
events: {} as
|
|
40
|
-
| { type: typeof Actions.INITIALIZE; data: InitializeEventData }
|
|
41
|
-
| { type: typeof Actions.FETCH_CHANNEL_DETAIL; data: ChannelDetailEventData }
|
|
42
|
-
| { type: typeof Actions.SET_CHANNEL_DETAIL; data: SetChannelDetailEventData }
|
|
43
|
-
| { type: typeof Actions.FETCH_THREADS; data?: {} }
|
|
44
|
-
| { type: typeof Actions.SET_THREADS; data: SetThreadsEventData }
|
|
45
|
-
| { type: typeof Actions.ERROR; data: ErrorEventData },
|
|
46
|
-
},
|
|
47
|
-
actions: {
|
|
48
|
-
setInitialContext: assign({
|
|
49
|
-
channelId: ({ event }) => {
|
|
50
|
-
if (event.type === Actions.INITIALIZE) {
|
|
51
|
-
return event.data.channelId;
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
},
|
|
55
|
-
postParentId: ({ event }) => {
|
|
56
|
-
if (event.type === Actions.INITIALIZE) {
|
|
57
|
-
return event.data.postParentId;
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
},
|
|
61
|
-
role: ({ event }) => {
|
|
62
|
-
if (event.type === Actions.INITIALIZE) {
|
|
63
|
-
return event.data.role;
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
66
|
-
},
|
|
67
|
-
loading: true,
|
|
68
|
-
error: null,
|
|
69
|
-
}),
|
|
70
|
-
setChannelDetail: assign({
|
|
71
|
-
channelsDetail: ({ event }) => {
|
|
72
|
-
if (event.type === Actions.SET_CHANNEL_DETAIL) {
|
|
73
|
-
return event.data.channelsDetail;
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
},
|
|
77
|
-
loading: false,
|
|
78
|
-
}),
|
|
79
|
-
setThreads: assign({
|
|
80
|
-
threadData: ({ event }) => {
|
|
81
|
-
if (event.type === Actions.SET_THREADS) {
|
|
82
|
-
return event.data.threadData;
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
},
|
|
86
|
-
loading: false,
|
|
87
|
-
}),
|
|
88
|
-
setError: assign({
|
|
89
|
-
error: ({ event }) => {
|
|
90
|
-
if (event.type === Actions.ERROR) {
|
|
91
|
-
return event.data.error;
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
},
|
|
95
|
-
loading: false,
|
|
96
|
-
}),
|
|
97
|
-
setLoading: assign({
|
|
98
|
-
loading: true,
|
|
99
|
-
}),
|
|
100
|
-
},
|
|
101
|
-
}).createMachine({
|
|
102
|
-
id: 'dialogThreads',
|
|
103
|
-
initial: BaseState.Idle,
|
|
104
|
-
context: {
|
|
105
|
-
channelId: undefined,
|
|
106
|
-
postParentId: undefined,
|
|
107
|
-
role: undefined,
|
|
108
|
-
channelsDetail: null,
|
|
109
|
-
threadData: [],
|
|
110
|
-
loading: true,
|
|
111
|
-
error: null,
|
|
112
|
-
},
|
|
113
|
-
states: {
|
|
114
|
-
[BaseState.Idle]: {
|
|
115
|
-
on: {
|
|
116
|
-
[Actions.INITIALIZE]: {
|
|
117
|
-
target: BaseState.LoadingChannel,
|
|
118
|
-
actions: 'setInitialContext',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
[BaseState.LoadingChannel]: {
|
|
123
|
-
on: {
|
|
124
|
-
[Actions.SET_CHANNEL_DETAIL]: {
|
|
125
|
-
target: BaseState.LoadingThreads,
|
|
126
|
-
actions: 'setChannelDetail',
|
|
127
|
-
},
|
|
128
|
-
[Actions.ERROR]: {
|
|
129
|
-
target: BaseState.Error,
|
|
130
|
-
actions: 'setError',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
[BaseState.LoadingThreads]: {
|
|
135
|
-
on: {
|
|
136
|
-
[Actions.SET_THREADS]: {
|
|
137
|
-
target: BaseState.Active,
|
|
138
|
-
actions: 'setThreads',
|
|
139
|
-
},
|
|
140
|
-
[Actions.ERROR]: {
|
|
141
|
-
target: BaseState.Error,
|
|
142
|
-
actions: 'setError',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
[BaseState.Active]: {
|
|
147
|
-
on: {
|
|
148
|
-
[Actions.FETCH_THREADS]: {
|
|
149
|
-
target: BaseState.LoadingThreads,
|
|
150
|
-
actions: 'setLoading',
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
[BaseState.Error]: {
|
|
155
|
-
on: {
|
|
156
|
-
[Actions.INITIALIZE]: {
|
|
157
|
-
target: BaseState.LoadingChannel,
|
|
158
|
-
actions: 'setInitialContext',
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
});
|
package/src/screens/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "lib",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationDir": "lib",
|
|
8
|
-
"types": ["@types/node", "@types/jest", "../../../typings"],
|
|
9
|
-
"skipLibCheck": true
|
|
10
|
-
},
|
|
11
|
-
"include": ["src"],
|
|
12
|
-
"exclude": ["../../../node_modules", "node_modules", "lib", "lib", "webpack.config.js", "rollup.config.mjs"]
|
|
13
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const nodeExternals = require('webpack-node-externals');
|
|
2
|
-
const webpack = require('webpack');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
|
|
6
|
-
const webpackOpts = {
|
|
7
|
-
mode: 'development',
|
|
8
|
-
entry: './src/index.ts',
|
|
9
|
-
target: 'node',
|
|
10
|
-
output: {
|
|
11
|
-
path: path.join(__dirname, 'lib'),
|
|
12
|
-
filename: 'index.js',
|
|
13
|
-
libraryTarget: 'commonjs2',
|
|
14
|
-
},
|
|
15
|
-
node: {
|
|
16
|
-
__dirname: false,
|
|
17
|
-
},
|
|
18
|
-
resolve: {
|
|
19
|
-
extensions: ['.ts', '.tsx', '.graphql', '.gql'],
|
|
20
|
-
},
|
|
21
|
-
plugins: [
|
|
22
|
-
new webpack.LoaderOptionsPlugin({
|
|
23
|
-
options: {
|
|
24
|
-
test: /\.tsx?$/,
|
|
25
|
-
ts: {
|
|
26
|
-
compiler: 'typescript',
|
|
27
|
-
configFile: 'tsconfig.json',
|
|
28
|
-
},
|
|
29
|
-
tslint: {
|
|
30
|
-
emitErrors: true,
|
|
31
|
-
failOnHint: true,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
devtool: 'source-map',
|
|
37
|
-
module: {
|
|
38
|
-
rules: [
|
|
39
|
-
{
|
|
40
|
-
test: /\.tsx?$/,
|
|
41
|
-
use: 'ts-loader',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
test: /\.graphql?/,
|
|
45
|
-
exclude: /node_modules/,
|
|
46
|
-
use: 'raw-loader',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
test: /\.(gql)$/,
|
|
50
|
-
exclude: /node_modules/,
|
|
51
|
-
use: ['graphql-tag/loader'],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
externals: [nodeExternals({ modulesDir: '../../../node_modules' }), nodeExternals()],
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
module.exports = webpackOpts;
|