@messenger-box/platform-mobile 10.0.3-alpha.22 → 10.0.3-alpha.23
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 +4 -0
- package/lib/screens/inbox/DialogThreads.js +52 -12
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/components/ThreadsViewItem.js +66 -44
- package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +36 -34
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +82 -37
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +282 -219
- 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/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 +2 -2
- package/src/screens/inbox/DialogThreads.tsx +49 -53
- package/src/screens/inbox/components/SmartLoader.tsx +61 -0
- package/src/screens/inbox/components/ThreadsViewItem.tsx +177 -265
- package/src/screens/inbox/containers/ConversationView.tsx +32 -30
- package/src/screens/inbox/containers/Dialogs.tsx +57 -22
- package/src/screens/inbox/containers/ThreadConversationView.tsx +467 -484
- package/src/screens/inbox/containers/ThreadsView.tsx +102 -183
- 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
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
});
|