@messenger-box/tailwind-ui-inbox 10.0.3-alpha.70 → 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 +8 -0
- package/lib/components/AIAgent/AIAgent.d.ts +14 -0
- package/lib/components/AIAgent/AIAgent.d.ts.map +1 -0
- package/lib/components/AIAgent/AIAgent.js +1148 -0
- package/lib/components/AIAgent/AIAgent.js.map +1 -0
- package/lib/components/AIAgent/index.d.ts +2 -0
- package/lib/components/AIAgent/index.d.ts.map +1 -0
- package/lib/components/InboxMessage/InputComponent.d.ts +9 -0
- package/lib/components/InboxMessage/InputComponent.d.ts.map +1 -0
- package/lib/components/InboxMessage/InputComponent.js +210 -0
- package/lib/components/InboxMessage/InputComponent.js.map +1 -0
- package/lib/components/InboxMessage/LeftSidebar.d.ts +2 -0
- package/lib/components/InboxMessage/LeftSidebar.d.ts.map +1 -1
- package/lib/components/InboxMessage/LeftSidebar.js +16 -5
- package/lib/components/InboxMessage/LeftSidebar.js.map +1 -1
- package/lib/components/InboxMessage/MessageInput.d.ts.map +1 -1
- package/lib/components/InboxMessage/MessageInput.js +14 -10
- package/lib/components/InboxMessage/MessageInput.js.map +1 -1
- package/lib/components/InboxMessage/MessageInputComponent.d.ts +9 -0
- package/lib/components/InboxMessage/MessageInputComponent.d.ts.map +1 -0
- package/lib/components/InboxMessage/MessageInputComponent.js +173 -0
- package/lib/components/InboxMessage/MessageInputComponent.js.map +1 -0
- package/lib/components/InboxMessage/Messages.d.ts +3 -1
- package/lib/components/InboxMessage/Messages.d.ts.map +1 -1
- package/lib/components/InboxMessage/Messages.js +16 -60
- package/lib/components/InboxMessage/Messages.js.map +1 -1
- package/lib/components/InboxMessage/MessagesBuilderUi.d.ts +17 -0
- package/lib/components/InboxMessage/MessagesBuilderUi.d.ts.map +1 -0
- package/lib/components/InboxMessage/MessagesBuilderUi.js +162 -0
- package/lib/components/InboxMessage/MessagesBuilderUi.js.map +1 -0
- package/lib/components/InboxMessage/UploadImageButton.d.ts +1 -0
- package/lib/components/InboxMessage/UploadImageButton.d.ts.map +1 -1
- package/lib/components/InboxMessage/UploadImageButton.js +3 -3
- package/lib/components/InboxMessage/UploadImageButton.js.map +1 -1
- package/lib/components/InboxMessage/index.d.ts +3 -0
- package/lib/components/InboxMessage/index.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/CommonMessage.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/CommonMessage.js +11 -6
- package/lib/components/InboxMessage/message-widgets/CommonMessage.js.map +1 -1
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts +14 -0
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts.map +1 -0
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js +1525 -0
- package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js.map +1 -0
- package/lib/components/InboxMessage/message-widgets/PlainMessage.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/PlainMessage.js +6 -3
- package/lib/components/InboxMessage/message-widgets/PlainMessage.js.map +1 -1
- package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts +2 -0
- package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts.map +1 -1
- package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js +225 -26
- package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js.map +1 -1
- package/lib/components/InboxMessage/message-widgets/index.d.ts +1 -0
- package/lib/components/InboxMessage/message-widgets/index.d.ts.map +1 -1
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.d.ts.map +1 -1
- package/lib/compute.d.ts.map +1 -1
- package/lib/compute.js +79 -3
- package/lib/compute.js.map +1 -1
- package/lib/config/env-config.d.ts +6 -0
- package/lib/config/env-config.d.ts.map +1 -1
- package/lib/config/env-config.js +19 -1
- package/lib/config/env-config.js.map +1 -1
- package/lib/container/AiInbox.d.ts +15 -0
- package/lib/container/AiInbox.d.ts.map +1 -0
- package/lib/container/AiInbox.js +1520 -0
- package/lib/container/AiInbox.js.map +1 -0
- package/lib/container/AiInboxWithLoader.d.ts +36 -0
- package/lib/container/AiInboxWithLoader.d.ts.map +1 -0
- package/lib/container/AiInboxWithLoader.js +300 -0
- package/lib/container/AiInboxWithLoader.js.map +1 -0
- package/lib/container/AiLandingInput.d.ts +4 -0
- package/lib/container/AiLandingInput.d.ts.map +1 -0
- package/lib/container/AiLandingInput.js +164 -0
- package/lib/container/AiLandingInput.js.map +1 -0
- package/lib/container/Inbox.d.ts.map +1 -1
- package/lib/container/Inbox.js +177 -58
- package/lib/container/Inbox.js.map +1 -1
- package/lib/container/InboxAiMessagesLoader.d.ts +36 -0
- package/lib/container/InboxAiMessagesLoader.d.ts.map +1 -0
- package/lib/container/InboxAiMessagesLoader.js +47 -0
- package/lib/container/InboxAiMessagesLoader.js.map +1 -0
- package/lib/container/InboxContainer.d.ts +12 -0
- package/lib/container/InboxContainer.d.ts.map +1 -0
- package/lib/container/InboxContainer.js +31 -0
- package/lib/container/InboxContainer.js.map +1 -0
- package/lib/container/InboxTemplate1.d.ts +15 -0
- package/lib/container/InboxTemplate1.d.ts.map +1 -0
- package/lib/container/InboxTemplate1.js +1375 -0
- package/lib/container/InboxTemplate1.js.map +1 -0
- package/lib/container/InboxTemplate1WithLoader.d.ts +36 -0
- package/lib/container/InboxTemplate1WithLoader.d.ts.map +1 -0
- package/lib/container/InboxTemplate2.d.ts +15 -0
- package/lib/container/InboxTemplate2.d.ts.map +1 -0
- package/lib/container/InboxTemplate2.js +1426 -0
- package/lib/container/InboxTemplate2.js.map +1 -0
- package/lib/container/InboxWithAiLoader.d.ts +15 -0
- package/lib/container/InboxWithAiLoader.d.ts.map +1 -0
- package/lib/container/InboxWithAiLoader.js +56 -0
- package/lib/container/InboxWithAiLoader.js.map +1 -0
- package/lib/container/ServiceInbox.js +1 -1
- package/lib/container/ServiceInbox.js.map +1 -1
- package/lib/container/ThreadMessages.js +1 -1
- package/lib/container/ThreadMessages.js.map +1 -1
- package/lib/container/ThreadMessagesInbox.js +1 -1
- package/lib/container/ThreadMessagesInbox.js.map +1 -1
- package/lib/container/Threads.js +1 -1
- package/lib/container/Threads.js.map +1 -1
- package/lib/container/index.d.ts +4 -1
- package/lib/container/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/machines/aiAgentMachine.d.ts +3 -0
- package/lib/machines/aiAgentMachine.d.ts.map +1 -0
- package/lib/machines/aiAgentMachine.js +1040 -0
- package/lib/machines/aiAgentMachine.js.map +1 -0
- package/lib/machines/types.d.ts +77 -0
- package/lib/machines/types.d.ts.map +1 -0
- package/lib/routes.json +40 -0
- package/lib/templates/InboxWithAi.d.ts +15 -0
- package/lib/templates/InboxWithAi.d.ts.map +1 -0
- package/lib/templates/InboxWithAi.js +405 -0
- package/lib/templates/InboxWithAi.js.map +1 -0
- package/lib/templates/InboxWithAi.tsx +502 -0
- package/package.json +7 -5
- package/src/components/AIAgent/AIAgent.tsx +1351 -0
- package/src/components/AIAgent/README.md +82 -0
- package/src/components/AIAgent/index.ts +1 -0
- package/src/components/InboxMessage/InputComponent.tsx +263 -0
- package/src/components/InboxMessage/LeftSidebar.tsx +14 -4
- package/src/components/InboxMessage/MessageInput.tsx +73 -66
- package/src/components/InboxMessage/MessageInputComponent.tsx +245 -0
- package/src/components/InboxMessage/Messages.tsx +24 -68
- package/src/components/InboxMessage/MessagesBuilderUi.tsx +205 -0
- package/src/components/InboxMessage/UploadImageButton.tsx +3 -2
- package/src/components/InboxMessage/index.ts +3 -0
- package/src/components/InboxMessage/message-widgets/CommonMessage.tsx +39 -21
- package/src/components/InboxMessage/message-widgets/ModernMessageGroup.tsx +1968 -0
- package/src/components/InboxMessage/message-widgets/PlainMessage.tsx +6 -2
- package/src/components/InboxMessage/message-widgets/SlackLikeMessageGroup.tsx +337 -53
- package/src/components/InboxMessage/message-widgets/index.ts +1 -0
- package/src/components/index.ts +4 -0
- package/src/compute.ts +83 -2
- package/src/config/env-config.ts +6 -0
- package/src/container/AiInbox.tsx +1796 -0
- package/src/container/AiInboxWithLoader.tsx +356 -0
- package/src/container/AiLandingInput.tsx +168 -0
- package/src/container/Inbox.tsx +280 -130
- package/src/container/InboxAiMessagesLoader.tsx +68 -0
- package/src/container/InboxContainer.tsx +35 -0
- package/src/container/InboxTemplate1.tsx +1542 -0
- package/src/container/InboxTemplate1WithLoader.tsx +338 -0
- package/src/container/InboxTemplate2.tsx +1606 -0
- package/src/container/InboxWithAiLoader.tsx +76 -0
- package/src/container/index.ts +15 -1
- package/src/machines/aiAgentMachine.ts +1248 -0
- package/src/machines/types.ts +59 -0
- package/src/templates/InboxWithAi.tsx +502 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import React, { useMemo, useCallback } from 'react';
|
|
2
|
+
import { useParams, useLocation } from '@remix-run/react';
|
|
3
|
+
import {
|
|
4
|
+
useGetChannelsByUserQuery,
|
|
5
|
+
useGetChannelsByUserWithLastMessageQuery,
|
|
6
|
+
useMessagesQuery,
|
|
7
|
+
useViewChannelDetailQuery,
|
|
8
|
+
} from 'common/graphql';
|
|
9
|
+
import { RoomType } from 'common';
|
|
10
|
+
import { config } from '../config';
|
|
11
|
+
import AiInbox from './AiInbox';
|
|
12
|
+
const { MESSAGES_PER_PAGE } = config;
|
|
13
|
+
|
|
14
|
+
// Enhanced query parameters generator with better typing and flexibility
|
|
15
|
+
export const queryParamsGenerator = (params: {
|
|
16
|
+
role?: string;
|
|
17
|
+
criteria?: Record<string, any>;
|
|
18
|
+
supportServices?: boolean;
|
|
19
|
+
orgName?: string;
|
|
20
|
+
}) => ({
|
|
21
|
+
variable1: {
|
|
22
|
+
role: params.role,
|
|
23
|
+
criteria: {
|
|
24
|
+
...params.criteria,
|
|
25
|
+
...(params.orgName && { orgName: params.orgName }),
|
|
26
|
+
},
|
|
27
|
+
supportServices: params.supportServices ? true : false,
|
|
28
|
+
supportServiceCriteria: params.supportServices
|
|
29
|
+
? {
|
|
30
|
+
type: RoomType.Service,
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
orderBy: {
|
|
34
|
+
lastPostAt: 'desc',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Enhanced Skeleton Components
|
|
40
|
+
const InboxSkeleton = React.memo(({ showRightSidebar = false }: { showRightSidebar?: boolean }) => (
|
|
41
|
+
<div
|
|
42
|
+
className="h-full border-t border-gray-300 flex overflow-hidden animate-pulse"
|
|
43
|
+
style={{ height: '100vh !important' }}
|
|
44
|
+
>
|
|
45
|
+
{/* Left Sidebar Skeleton */}
|
|
46
|
+
<div className="flex-shrink-0 w-full md:w-80 lg:w-96 xl:w-[420px] bg-gray-50 border-r border-gray-300 overflow-hidden">
|
|
47
|
+
{/* Header skeleton */}
|
|
48
|
+
<div className="p-4 border-b border-gray-200">
|
|
49
|
+
<div className="flex items-center justify-between mb-4">
|
|
50
|
+
<div className="h-6 bg-gray-300 rounded w-24"></div>
|
|
51
|
+
<div className="h-8 w-8 bg-gray-300 rounded-full"></div>
|
|
52
|
+
</div>
|
|
53
|
+
{/* Search bar skeleton */}
|
|
54
|
+
<div className="h-10 bg-gray-300 rounded-lg w-full"></div>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
{/* Conversation list skeleton */}
|
|
58
|
+
<div className="p-4 space-y-3">
|
|
59
|
+
{Array.from({ length: 8 }).map((_, index) => (
|
|
60
|
+
<div key={index} className="flex items-center space-x-3 p-3 rounded-lg">
|
|
61
|
+
{/* Avatar skeleton */}
|
|
62
|
+
<div className="h-12 w-12 bg-gray-300 rounded-full flex-shrink-0"></div>
|
|
63
|
+
<div className="flex-1 min-w-0">
|
|
64
|
+
{/* Name skeleton */}
|
|
65
|
+
<div className="h-4 bg-gray-300 rounded w-3/4 mb-2"></div>
|
|
66
|
+
{/* Message preview skeleton */}
|
|
67
|
+
<div className="h-3 bg-gray-200 rounded w-full"></div>
|
|
68
|
+
</div>
|
|
69
|
+
<div className="flex flex-col items-end space-y-1">
|
|
70
|
+
{/* Time skeleton */}
|
|
71
|
+
<div className="h-3 bg-gray-200 rounded w-12"></div>
|
|
72
|
+
{/* Badge skeleton */}
|
|
73
|
+
<div className="h-4 w-4 bg-gray-300 rounded-full"></div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
{/* Main Content Area Skeleton */}
|
|
81
|
+
<div className="flex-1 min-w-0 overflow-hidden">
|
|
82
|
+
<div className="flex h-full">
|
|
83
|
+
{/* Chat content skeleton */}
|
|
84
|
+
<div className="flex-1 flex flex-col">
|
|
85
|
+
{/* Header skeleton */}
|
|
86
|
+
<div className="px-6 py-4 border-b border-gray-200 bg-white flex-shrink-0">
|
|
87
|
+
<div className="flex items-center justify-between">
|
|
88
|
+
<div className="h-6 bg-gray-300 rounded w-32"></div>
|
|
89
|
+
<div className="h-8 bg-gray-300 rounded w-20"></div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
{/* Messages area skeleton */}
|
|
94
|
+
<div className="flex-1 p-4 space-y-4 overflow-hidden">
|
|
95
|
+
{Array.from({ length: 6 }).map((_, index) => (
|
|
96
|
+
<div key={index} className={`flex ${index % 2 === 0 ? 'justify-start' : 'justify-end'}`}>
|
|
97
|
+
<div
|
|
98
|
+
className={`flex items-start space-x-2 max-w-xs lg:max-w-md ${
|
|
99
|
+
index % 2 === 0 ? '' : 'flex-row-reverse space-x-reverse'
|
|
100
|
+
}`}
|
|
101
|
+
>
|
|
102
|
+
{index % 2 === 0 && (
|
|
103
|
+
<div className="h-8 w-8 bg-gray-300 rounded-full flex-shrink-0"></div>
|
|
104
|
+
)}
|
|
105
|
+
<div
|
|
106
|
+
className={`px-4 py-2 rounded-lg ${
|
|
107
|
+
index % 2 === 0 ? 'bg-gray-200' : 'bg-gray-300'
|
|
108
|
+
}`}
|
|
109
|
+
>
|
|
110
|
+
<div className="h-4 bg-gray-400 rounded w-32 mb-1"></div>
|
|
111
|
+
<div className="h-3 bg-gray-400 rounded w-20"></div>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
{/* Message input skeleton */}
|
|
119
|
+
<div className="p-4 border-t border-gray-200 bg-white">
|
|
120
|
+
<div className="flex items-center space-x-2">
|
|
121
|
+
<div className="h-10 bg-gray-300 rounded-full w-10"></div>
|
|
122
|
+
<div className="flex-1 h-10 bg-gray-300 rounded-lg"></div>
|
|
123
|
+
<div className="h-10 w-10 bg-gray-300 rounded-full"></div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
{/* Right Sidebar Skeleton - Desktop only, conditionally rendered */}
|
|
129
|
+
{showRightSidebar && (
|
|
130
|
+
<div className="hidden xl:block w-72 lg:w-80 xl:w-96 border-l border-gray-200 bg-white flex-shrink-0">
|
|
131
|
+
<div className="p-4">
|
|
132
|
+
{/* Right sidebar header */}
|
|
133
|
+
<div className="h-6 bg-gray-300 rounded w-24 mb-4"></div>
|
|
134
|
+
|
|
135
|
+
{/* Right sidebar content */}
|
|
136
|
+
<div className="space-y-3">
|
|
137
|
+
{Array.from({ length: 4 }).map((_, index) => (
|
|
138
|
+
<div key={index} className="p-3 border border-gray-200 rounded-lg">
|
|
139
|
+
<div className="h-4 bg-gray-300 rounded w-3/4 mb-2"></div>
|
|
140
|
+
<div className="h-3 bg-gray-200 rounded w-full mb-1"></div>
|
|
141
|
+
<div className="h-3 bg-gray-200 rounded w-2/3"></div>
|
|
142
|
+
</div>
|
|
143
|
+
))}
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
));
|
|
152
|
+
|
|
153
|
+
const TailwindSpinner = React.memo(() => (
|
|
154
|
+
<div className="flex items-center justify-center min-h-screen">
|
|
155
|
+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
|
|
156
|
+
</div>
|
|
157
|
+
));
|
|
158
|
+
|
|
159
|
+
interface TailwindAlertProps {
|
|
160
|
+
children: React.ReactNode;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const TailwindAlert = React.memo(({ children }: TailwindAlertProps) => (
|
|
164
|
+
<div className="flex items-center justify-center min-h-screen">
|
|
165
|
+
<div
|
|
166
|
+
className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative max-w-md mx-auto"
|
|
167
|
+
role="alert"
|
|
168
|
+
>
|
|
169
|
+
<span className="block sm:inline">{children}</span>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
));
|
|
173
|
+
|
|
174
|
+
interface InboxWithLoaderProps {
|
|
175
|
+
channelFilters?: Record<string, any>;
|
|
176
|
+
channelRole?: string;
|
|
177
|
+
supportServices?: boolean;
|
|
178
|
+
pathPrefix?: string;
|
|
179
|
+
orgName?: string;
|
|
180
|
+
[key: string]: any; // Allow other props to be passed through to Inbox
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const InboxTemplate1WithLoader = (props: InboxWithLoaderProps) => {
|
|
184
|
+
const { channelFilters: channelFilterProp, channelRole: channelRoleProp, supportServices, pathPrefix } = props;
|
|
185
|
+
const { orgName, channelRole: channelRoleParam } = useParams();
|
|
186
|
+
const channelRole = channelRoleParam || channelRoleProp;
|
|
187
|
+
|
|
188
|
+
// Create new props object with orgName instead of mutating original props
|
|
189
|
+
const inboxProps = useMemo(
|
|
190
|
+
() => ({
|
|
191
|
+
...props,
|
|
192
|
+
orgName: orgName || '',
|
|
193
|
+
pathPrefix: pathPrefix || '',
|
|
194
|
+
}),
|
|
195
|
+
[props, orgName, pathPrefix],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const { id: pathChannelId } = useParams();
|
|
199
|
+
|
|
200
|
+
// Enhanced query variables with better filtering and stable references
|
|
201
|
+
const channelsQueryVariables = useMemo(() => {
|
|
202
|
+
const channelFilters = { ...channelFilterProp };
|
|
203
|
+
const channelType = channelFilters?.type ?? RoomType.Direct;
|
|
204
|
+
const baseFilters = {
|
|
205
|
+
...channelFilters,
|
|
206
|
+
type: supportServices ? [channelType, RoomType.Service] : channelType,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return queryParamsGenerator({
|
|
210
|
+
role: channelRole,
|
|
211
|
+
criteria: baseFilters,
|
|
212
|
+
supportServices,
|
|
213
|
+
orgName: orgName || '',
|
|
214
|
+
}).variable1;
|
|
215
|
+
}, [channelRole, channelFilterProp, supportServices, orgName]);
|
|
216
|
+
|
|
217
|
+
const messagesQueryVariables = useMemo(
|
|
218
|
+
() => ({
|
|
219
|
+
channelId: pathChannelId?.toString(),
|
|
220
|
+
parentId: null,
|
|
221
|
+
limit: MESSAGES_PER_PAGE,
|
|
222
|
+
}),
|
|
223
|
+
[pathChannelId],
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const channelDetailQueryVariables = useMemo(
|
|
227
|
+
() => ({
|
|
228
|
+
id: pathChannelId?.toString(),
|
|
229
|
+
}),
|
|
230
|
+
[pathChannelId],
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
// Enhanced Apollo queries with better cache policies and error handling
|
|
234
|
+
const channelsQuery = useGetChannelsByUserQuery({
|
|
235
|
+
variables: channelsQueryVariables,
|
|
236
|
+
fetchPolicy: 'cache-and-network', // Better for real-time updates
|
|
237
|
+
errorPolicy: 'all',
|
|
238
|
+
notifyOnNetworkStatusChange: false,
|
|
239
|
+
returnPartialData: true,
|
|
240
|
+
// Add context for better cache management
|
|
241
|
+
context: {
|
|
242
|
+
cacheKey: 'channels-list',
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const messagesQuery = useMessagesQuery({
|
|
247
|
+
variables: messagesQueryVariables,
|
|
248
|
+
skip: !pathChannelId,
|
|
249
|
+
fetchPolicy: 'cache-and-network', // Better for real-time messaging
|
|
250
|
+
errorPolicy: 'all',
|
|
251
|
+
notifyOnNetworkStatusChange: true,
|
|
252
|
+
returnPartialData: true,
|
|
253
|
+
// Disable polling to allow subscriptions to work properly
|
|
254
|
+
pollInterval: 0,
|
|
255
|
+
// Add context for better cache management
|
|
256
|
+
context: {
|
|
257
|
+
cacheKey: 'messages-list',
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const channelDetailQuery = useViewChannelDetailQuery({
|
|
262
|
+
variables: channelDetailQueryVariables,
|
|
263
|
+
skip: !pathChannelId,
|
|
264
|
+
fetchPolicy: 'cache-first', // Channel details don't change often
|
|
265
|
+
errorPolicy: 'all',
|
|
266
|
+
notifyOnNetworkStatusChange: false, // No need for real-time updates
|
|
267
|
+
returnPartialData: true,
|
|
268
|
+
// Add context for better cache management
|
|
269
|
+
context: {
|
|
270
|
+
cacheKey: 'channel-detail',
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Enhanced error handling with retry logic
|
|
275
|
+
const handleRetry = useCallback(() => {
|
|
276
|
+
if (channelsQuery.error) {
|
|
277
|
+
channelsQuery.refetch();
|
|
278
|
+
}
|
|
279
|
+
if (messagesQuery.error) {
|
|
280
|
+
messagesQuery.refetch();
|
|
281
|
+
}
|
|
282
|
+
if (channelDetailQuery.error) {
|
|
283
|
+
channelDetailQuery.refetch();
|
|
284
|
+
}
|
|
285
|
+
}, [channelsQuery, messagesQuery, channelDetailQuery]);
|
|
286
|
+
|
|
287
|
+
// Create loader data array for Inbox component with better error handling
|
|
288
|
+
const loaderData = useMemo(
|
|
289
|
+
() => [channelsQuery, messagesQuery, channelDetailQuery],
|
|
290
|
+
[channelsQuery, messagesQuery, channelDetailQuery],
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
// Enhanced loading states with better UX
|
|
294
|
+
if (channelsQuery.loading && !pathChannelId && !channelsQuery.data) {
|
|
295
|
+
return <InboxSkeleton showRightSidebar={false} />;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Show skeleton during initial channel loading
|
|
299
|
+
if (
|
|
300
|
+
pathChannelId &&
|
|
301
|
+
(messagesQuery.loading || channelDetailQuery.loading) &&
|
|
302
|
+
!messagesQuery.data &&
|
|
303
|
+
!channelDetailQuery.data
|
|
304
|
+
) {
|
|
305
|
+
return <InboxSkeleton showRightSidebar={true} />;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Enhanced error handling with retry option
|
|
309
|
+
if (channelsQuery.error && !channelsQuery.data) {
|
|
310
|
+
return (
|
|
311
|
+
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
|
312
|
+
<TailwindAlert>Error loading channels: {channelsQuery.error.message}</TailwindAlert>
|
|
313
|
+
<button
|
|
314
|
+
onClick={handleRetry}
|
|
315
|
+
className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
316
|
+
>
|
|
317
|
+
Retry
|
|
318
|
+
</button>
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Handle individual query errors gracefully
|
|
324
|
+
if (messagesQuery.error && !messagesQuery.data && pathChannelId) {
|
|
325
|
+
console.warn('Messages query error:', messagesQuery.error);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (channelDetailQuery.error && !channelDetailQuery.data && pathChannelId) {
|
|
329
|
+
console.warn('Channel detail query error:', channelDetailQuery.error);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return <AiInbox data={loaderData} {...inboxProps} />;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// Display name for debugging
|
|
336
|
+
InboxTemplate1WithLoader.displayName = 'InboxTemplate1WithLoader';
|
|
337
|
+
|
|
338
|
+
export default React.memo(InboxTemplate1WithLoader);
|