@cstar.help/react 0.10.1 → 0.10.3
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/README.md +32 -21
- package/dist/index.cjs +178 -163
- package/dist/index.d.cts +19 -12
- package/dist/index.d.ts +19 -12
- package/dist/index.js +80 -64
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -81,32 +82,51 @@ function useCommunityClient() {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
// src/chat/CStarChatProvider.tsx
|
|
84
|
-
var
|
|
85
|
+
var import_react3 = require("react");
|
|
85
86
|
var import_chat = require("@cstar.help/js/chat");
|
|
87
|
+
|
|
88
|
+
// src/useDisconnectOnUnmount.ts
|
|
89
|
+
var import_react2 = require("react");
|
|
90
|
+
function useDisconnectOnUnmount(target, disconnect) {
|
|
91
|
+
const pending = (0, import_react2.useRef)(null);
|
|
92
|
+
const disconnectRef = (0, import_react2.useRef)(disconnect);
|
|
93
|
+
disconnectRef.current = disconnect;
|
|
94
|
+
(0, import_react2.useEffect)(() => {
|
|
95
|
+
if (target === null) return;
|
|
96
|
+
if (pending.current?.target === target) {
|
|
97
|
+
clearTimeout(pending.current.timer);
|
|
98
|
+
pending.current = null;
|
|
99
|
+
}
|
|
100
|
+
return () => {
|
|
101
|
+
const timer = setTimeout(() => {
|
|
102
|
+
if (pending.current?.target === target) pending.current = null;
|
|
103
|
+
disconnectRef.current(target);
|
|
104
|
+
}, 0);
|
|
105
|
+
pending.current = { target, timer };
|
|
106
|
+
};
|
|
107
|
+
}, [target]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/chat/CStarChatProvider.tsx
|
|
86
111
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
87
112
|
function CStarChatProvider({ children, ...config }) {
|
|
88
|
-
const clientRef = (0,
|
|
113
|
+
const clientRef = (0, import_react3.useRef)(null);
|
|
89
114
|
if (!clientRef.current) {
|
|
90
115
|
clientRef.current = new import_chat.ChatClient(config);
|
|
91
116
|
}
|
|
92
|
-
(
|
|
93
|
-
return () => {
|
|
94
|
-
clientRef.current?.disconnect();
|
|
95
|
-
clientRef.current = null;
|
|
96
|
-
};
|
|
97
|
-
}, []);
|
|
117
|
+
useDisconnectOnUnmount(clientRef.current, (client) => client.disconnect());
|
|
98
118
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CStarChatContext.Provider, { value: clientRef.current, children });
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
// src/chat/useChat.ts
|
|
102
|
-
var
|
|
122
|
+
var import_react4 = require("react");
|
|
103
123
|
function useChat() {
|
|
104
124
|
const client = useChatClient();
|
|
105
|
-
const [isAuthenticated, setIsAuthenticated] = (0,
|
|
106
|
-
const [authMode, setAuthMode] = (0,
|
|
107
|
-
const [isRealtimeReady, setIsRealtimeReady] = (0,
|
|
108
|
-
const [error, setError] = (0,
|
|
109
|
-
(0,
|
|
125
|
+
const [isAuthenticated, setIsAuthenticated] = (0, import_react4.useState)(false);
|
|
126
|
+
const [authMode, setAuthMode] = (0, import_react4.useState)(() => client.getAuthMode());
|
|
127
|
+
const [isRealtimeReady, setIsRealtimeReady] = (0, import_react4.useState)(false);
|
|
128
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
129
|
+
(0, import_react4.useEffect)(() => {
|
|
110
130
|
const subscribe = client.subscribe?.bind(client);
|
|
111
131
|
if (!subscribe) return;
|
|
112
132
|
return subscribe(() => {
|
|
@@ -115,11 +135,11 @@ function useChat() {
|
|
|
115
135
|
setIsAuthenticated(mode !== null);
|
|
116
136
|
});
|
|
117
137
|
}, [client]);
|
|
118
|
-
const wireRealtime = (0,
|
|
138
|
+
const wireRealtime = (0, import_react4.useCallback)(() => {
|
|
119
139
|
client.waitForRealtime().then(() => setIsRealtimeReady(true)).catch(() => {
|
|
120
140
|
});
|
|
121
141
|
}, [client]);
|
|
122
|
-
const identify = (0,
|
|
142
|
+
const identify = (0, import_react4.useCallback)(
|
|
123
143
|
async (customer, signature) => {
|
|
124
144
|
setError(null);
|
|
125
145
|
try {
|
|
@@ -136,7 +156,7 @@ function useChat() {
|
|
|
136
156
|
},
|
|
137
157
|
[client, wireRealtime]
|
|
138
158
|
);
|
|
139
|
-
const loginWithCredentials = (0,
|
|
159
|
+
const loginWithCredentials = (0, import_react4.useCallback)(
|
|
140
160
|
async (params) => {
|
|
141
161
|
setError(null);
|
|
142
162
|
try {
|
|
@@ -153,7 +173,7 @@ function useChat() {
|
|
|
153
173
|
},
|
|
154
174
|
[client, wireRealtime]
|
|
155
175
|
);
|
|
156
|
-
const loginWithSession = (0,
|
|
176
|
+
const loginWithSession = (0, import_react4.useCallback)(
|
|
157
177
|
async (params) => {
|
|
158
178
|
setError(null);
|
|
159
179
|
try {
|
|
@@ -169,7 +189,7 @@ function useChat() {
|
|
|
169
189
|
},
|
|
170
190
|
[client, wireRealtime]
|
|
171
191
|
);
|
|
172
|
-
const disconnect = (0,
|
|
192
|
+
const disconnect = (0, import_react4.useCallback)(() => {
|
|
173
193
|
client.disconnect();
|
|
174
194
|
setIsAuthenticated(false);
|
|
175
195
|
setAuthMode(null);
|
|
@@ -190,15 +210,15 @@ function useChat() {
|
|
|
190
210
|
}
|
|
191
211
|
|
|
192
212
|
// src/chat/useTickets.ts
|
|
193
|
-
var
|
|
213
|
+
var import_react5 = require("react");
|
|
194
214
|
function useTickets() {
|
|
195
215
|
const client = useChatClient();
|
|
196
|
-
const [tickets, setTickets] = (0,
|
|
197
|
-
const [isLoading, setIsLoading] = (0,
|
|
198
|
-
const [error, setError] = (0,
|
|
199
|
-
const [hasMore, setHasMore] = (0,
|
|
200
|
-
const mountedRef = (0,
|
|
201
|
-
const refresh = (0,
|
|
216
|
+
const [tickets, setTickets] = (0, import_react5.useState)([]);
|
|
217
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(true);
|
|
218
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
219
|
+
const [hasMore, setHasMore] = (0, import_react5.useState)(false);
|
|
220
|
+
const mountedRef = (0, import_react5.useRef)(true);
|
|
221
|
+
const refresh = (0, import_react5.useCallback)(async () => {
|
|
202
222
|
setIsLoading(true);
|
|
203
223
|
setError(null);
|
|
204
224
|
try {
|
|
@@ -217,14 +237,14 @@ function useTickets() {
|
|
|
217
237
|
}
|
|
218
238
|
}
|
|
219
239
|
}, [client]);
|
|
220
|
-
(0,
|
|
240
|
+
(0, import_react5.useEffect)(() => {
|
|
221
241
|
mountedRef.current = true;
|
|
222
242
|
refresh();
|
|
223
243
|
return () => {
|
|
224
244
|
mountedRef.current = false;
|
|
225
245
|
};
|
|
226
246
|
}, [refresh]);
|
|
227
|
-
const create = (0,
|
|
247
|
+
const create = (0, import_react5.useCallback)(
|
|
228
248
|
async (params) => {
|
|
229
249
|
const ticket = await client.tickets.create(params);
|
|
230
250
|
if (mountedRef.current) {
|
|
@@ -238,18 +258,18 @@ function useTickets() {
|
|
|
238
258
|
}
|
|
239
259
|
|
|
240
260
|
// src/chat/useMessages.ts
|
|
241
|
-
var
|
|
261
|
+
var import_react6 = require("react");
|
|
242
262
|
function useMessages(ticketId) {
|
|
243
263
|
const client = useChatClient();
|
|
244
|
-
const [messages, setMessages] = (0,
|
|
245
|
-
const [isLoading, setIsLoading] = (0,
|
|
246
|
-
const [error, setError] = (0,
|
|
247
|
-
const mountedRef = (0,
|
|
248
|
-
const seenIdsRef = (0,
|
|
249
|
-
const requestRef = (0,
|
|
250
|
-
const scopeRef = (0,
|
|
251
|
-
const optimisticRef = (0,
|
|
252
|
-
const refresh = (0,
|
|
264
|
+
const [messages, setMessages] = (0, import_react6.useState)([]);
|
|
265
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
|
|
266
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
267
|
+
const mountedRef = (0, import_react6.useRef)(true);
|
|
268
|
+
const seenIdsRef = (0, import_react6.useRef)(/* @__PURE__ */ new Set());
|
|
269
|
+
const requestRef = (0, import_react6.useRef)(0);
|
|
270
|
+
const scopeRef = (0, import_react6.useRef)(0);
|
|
271
|
+
const optimisticRef = (0, import_react6.useRef)(0);
|
|
272
|
+
const refresh = (0, import_react6.useCallback)(async () => {
|
|
253
273
|
if (!ticketId) return;
|
|
254
274
|
const request = ++requestRef.current;
|
|
255
275
|
setIsLoading(true);
|
|
@@ -270,7 +290,7 @@ function useMessages(ticketId) {
|
|
|
270
290
|
}
|
|
271
291
|
}
|
|
272
292
|
}, [client, ticketId]);
|
|
273
|
-
(0,
|
|
293
|
+
(0, import_react6.useEffect)(() => {
|
|
274
294
|
mountedRef.current = true;
|
|
275
295
|
const scope = ++scopeRef.current;
|
|
276
296
|
seenIdsRef.current = /* @__PURE__ */ new Set();
|
|
@@ -309,7 +329,7 @@ function useMessages(ticketId) {
|
|
|
309
329
|
unsubscribe();
|
|
310
330
|
};
|
|
311
331
|
}, [client, ticketId, refresh]);
|
|
312
|
-
const send = (0,
|
|
332
|
+
const send = (0, import_react6.useCallback)(
|
|
313
333
|
async (content) => {
|
|
314
334
|
if (!ticketId) throw new Error("No ticket selected");
|
|
315
335
|
const scope = scopeRef.current;
|
|
@@ -342,14 +362,14 @@ function useMessages(ticketId) {
|
|
|
342
362
|
}
|
|
343
363
|
|
|
344
364
|
// src/chat/useTyping.ts
|
|
345
|
-
var
|
|
365
|
+
var import_react7 = require("react");
|
|
346
366
|
var TYPING_TIMEOUT = 4e3;
|
|
347
367
|
function useTyping(ticketId) {
|
|
348
368
|
const client = useChatClient();
|
|
349
|
-
const [typingAgents, setTypingAgents] = (0,
|
|
350
|
-
const timersRef = (0,
|
|
351
|
-
const mountedRef = (0,
|
|
352
|
-
(0,
|
|
369
|
+
const [typingAgents, setTypingAgents] = (0, import_react7.useState)([]);
|
|
370
|
+
const timersRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
371
|
+
const mountedRef = (0, import_react7.useRef)(true);
|
|
372
|
+
(0, import_react7.useEffect)(() => {
|
|
353
373
|
mountedRef.current = true;
|
|
354
374
|
if (!ticketId) {
|
|
355
375
|
setTypingAgents([]);
|
|
@@ -386,7 +406,7 @@ function useTyping(ticketId) {
|
|
|
386
406
|
timersRef.current.clear();
|
|
387
407
|
};
|
|
388
408
|
}, [client, ticketId]);
|
|
389
|
-
const sendTyping = (0,
|
|
409
|
+
const sendTyping = (0, import_react7.useCallback)(
|
|
390
410
|
async (isTyping) => {
|
|
391
411
|
if (!ticketId) return;
|
|
392
412
|
await client.sendTyping(ticketId, isTyping);
|
|
@@ -397,11 +417,11 @@ function useTyping(ticketId) {
|
|
|
397
417
|
}
|
|
398
418
|
|
|
399
419
|
// src/library/CStarLibraryProvider.tsx
|
|
400
|
-
var
|
|
420
|
+
var import_react8 = require("react");
|
|
401
421
|
var import_library = require("@cstar.help/js/library");
|
|
402
422
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
403
423
|
function CStarLibraryProvider({ children, ...config }) {
|
|
404
|
-
const clientRef = (0,
|
|
424
|
+
const clientRef = (0, import_react8.useRef)(null);
|
|
405
425
|
if (!clientRef.current) {
|
|
406
426
|
clientRef.current = new import_library.LibraryClient(config);
|
|
407
427
|
}
|
|
@@ -409,14 +429,14 @@ function CStarLibraryProvider({ children, ...config }) {
|
|
|
409
429
|
}
|
|
410
430
|
|
|
411
431
|
// src/library/useCategories.ts
|
|
412
|
-
var
|
|
432
|
+
var import_react9 = require("react");
|
|
413
433
|
function useCategories() {
|
|
414
434
|
const client = useLibraryClient();
|
|
415
|
-
const [categories, setCategories] = (0,
|
|
416
|
-
const [isLoading, setIsLoading] = (0,
|
|
417
|
-
const [error, setError] = (0,
|
|
418
|
-
const mountedRef = (0,
|
|
419
|
-
const refresh = (0,
|
|
435
|
+
const [categories, setCategories] = (0, import_react9.useState)([]);
|
|
436
|
+
const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
|
|
437
|
+
const [error, setError] = (0, import_react9.useState)(null);
|
|
438
|
+
const mountedRef = (0, import_react9.useRef)(true);
|
|
439
|
+
const refresh = (0, import_react9.useCallback)(async () => {
|
|
420
440
|
setIsLoading(true);
|
|
421
441
|
setError(null);
|
|
422
442
|
try {
|
|
@@ -434,7 +454,7 @@ function useCategories() {
|
|
|
434
454
|
}
|
|
435
455
|
}
|
|
436
456
|
}, [client]);
|
|
437
|
-
(0,
|
|
457
|
+
(0, import_react9.useEffect)(() => {
|
|
438
458
|
mountedRef.current = true;
|
|
439
459
|
refresh();
|
|
440
460
|
return () => {
|
|
@@ -445,17 +465,17 @@ function useCategories() {
|
|
|
445
465
|
}
|
|
446
466
|
|
|
447
467
|
// src/library/useArticles.ts
|
|
448
|
-
var
|
|
468
|
+
var import_react10 = require("react");
|
|
449
469
|
function useArticles(params) {
|
|
450
470
|
const client = useLibraryClient();
|
|
451
|
-
const [articles, setArticles] = (0,
|
|
452
|
-
const [isLoading, setIsLoading] = (0,
|
|
453
|
-
const [error, setError] = (0,
|
|
454
|
-
const mountedRef = (0,
|
|
471
|
+
const [articles, setArticles] = (0, import_react10.useState)([]);
|
|
472
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(true);
|
|
473
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
474
|
+
const mountedRef = (0, import_react10.useRef)(true);
|
|
455
475
|
const categorySlug = params?.categorySlug;
|
|
456
476
|
const limit = params?.limit;
|
|
457
477
|
const offset = params?.offset;
|
|
458
|
-
const refresh = (0,
|
|
478
|
+
const refresh = (0, import_react10.useCallback)(async () => {
|
|
459
479
|
setIsLoading(true);
|
|
460
480
|
setError(null);
|
|
461
481
|
try {
|
|
@@ -473,7 +493,7 @@ function useArticles(params) {
|
|
|
473
493
|
}
|
|
474
494
|
}
|
|
475
495
|
}, [client, categorySlug, limit, offset]);
|
|
476
|
-
(0,
|
|
496
|
+
(0, import_react10.useEffect)(() => {
|
|
477
497
|
mountedRef.current = true;
|
|
478
498
|
refresh();
|
|
479
499
|
return () => {
|
|
@@ -484,14 +504,14 @@ function useArticles(params) {
|
|
|
484
504
|
}
|
|
485
505
|
|
|
486
506
|
// src/library/useArticle.ts
|
|
487
|
-
var
|
|
507
|
+
var import_react11 = require("react");
|
|
488
508
|
function useArticle(slug) {
|
|
489
509
|
const client = useLibraryClient();
|
|
490
|
-
const [article, setArticle] = (0,
|
|
491
|
-
const [isLoading, setIsLoading] = (0,
|
|
492
|
-
const [error, setError] = (0,
|
|
493
|
-
const mountedRef = (0,
|
|
494
|
-
const refresh = (0,
|
|
510
|
+
const [article, setArticle] = (0, import_react11.useState)(null);
|
|
511
|
+
const [isLoading, setIsLoading] = (0, import_react11.useState)(true);
|
|
512
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
513
|
+
const mountedRef = (0, import_react11.useRef)(true);
|
|
514
|
+
const refresh = (0, import_react11.useCallback)(async () => {
|
|
495
515
|
if (!slug) return;
|
|
496
516
|
setIsLoading(true);
|
|
497
517
|
setError(null);
|
|
@@ -510,14 +530,14 @@ function useArticle(slug) {
|
|
|
510
530
|
}
|
|
511
531
|
}
|
|
512
532
|
}, [client, slug]);
|
|
513
|
-
const recordView = (0,
|
|
533
|
+
const recordView = (0, import_react11.useCallback)(async () => {
|
|
514
534
|
if (!slug) return;
|
|
515
535
|
try {
|
|
516
536
|
await client.recordView(slug);
|
|
517
537
|
} catch {
|
|
518
538
|
}
|
|
519
539
|
}, [client, slug]);
|
|
520
|
-
(0,
|
|
540
|
+
(0, import_react11.useEffect)(() => {
|
|
521
541
|
mountedRef.current = true;
|
|
522
542
|
if (!slug) {
|
|
523
543
|
setArticle(null);
|
|
@@ -533,16 +553,16 @@ function useArticle(slug) {
|
|
|
533
553
|
}
|
|
534
554
|
|
|
535
555
|
// src/library/useArticleSearch.ts
|
|
536
|
-
var
|
|
556
|
+
var import_react12 = require("react");
|
|
537
557
|
var DEBOUNCE_MS = 300;
|
|
538
558
|
function useArticleSearch(query) {
|
|
539
559
|
const client = useLibraryClient();
|
|
540
|
-
const [results, setResults] = (0,
|
|
541
|
-
const [totalCount, setTotalCount] = (0,
|
|
542
|
-
const [isLoading, setIsLoading] = (0,
|
|
543
|
-
const [error, setError] = (0,
|
|
544
|
-
const mountedRef = (0,
|
|
545
|
-
(0,
|
|
560
|
+
const [results, setResults] = (0, import_react12.useState)([]);
|
|
561
|
+
const [totalCount, setTotalCount] = (0, import_react12.useState)(0);
|
|
562
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
563
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
564
|
+
const mountedRef = (0, import_react12.useRef)(true);
|
|
565
|
+
(0, import_react12.useEffect)(() => {
|
|
546
566
|
mountedRef.current = true;
|
|
547
567
|
const trimmed = query.trim();
|
|
548
568
|
if (!trimmed) {
|
|
@@ -580,11 +600,11 @@ function useArticleSearch(query) {
|
|
|
580
600
|
}
|
|
581
601
|
|
|
582
602
|
// src/community/CStarCommunityProvider.tsx
|
|
583
|
-
var
|
|
603
|
+
var import_react13 = require("react");
|
|
584
604
|
var import_community = require("@cstar.help/js/community");
|
|
585
605
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
586
606
|
function CStarCommunityProvider({ children, ...config }) {
|
|
587
|
-
const clientRef = (0,
|
|
607
|
+
const clientRef = (0, import_react13.useRef)(null);
|
|
588
608
|
if (!clientRef.current) {
|
|
589
609
|
clientRef.current = new import_community.CommunityClient(config);
|
|
590
610
|
}
|
|
@@ -592,14 +612,14 @@ function CStarCommunityProvider({ children, ...config }) {
|
|
|
592
612
|
}
|
|
593
613
|
|
|
594
614
|
// src/community/useTopics.ts
|
|
595
|
-
var
|
|
615
|
+
var import_react14 = require("react");
|
|
596
616
|
function useTopics() {
|
|
597
617
|
const client = useCommunityClient();
|
|
598
|
-
const [topics, setTopics] = (0,
|
|
599
|
-
const [isLoading, setIsLoading] = (0,
|
|
600
|
-
const [error, setError] = (0,
|
|
601
|
-
const mountedRef = (0,
|
|
602
|
-
const refresh = (0,
|
|
618
|
+
const [topics, setTopics] = (0, import_react14.useState)([]);
|
|
619
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(true);
|
|
620
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
621
|
+
const mountedRef = (0, import_react14.useRef)(true);
|
|
622
|
+
const refresh = (0, import_react14.useCallback)(async () => {
|
|
603
623
|
setIsLoading(true);
|
|
604
624
|
setError(null);
|
|
605
625
|
try {
|
|
@@ -617,7 +637,7 @@ function useTopics() {
|
|
|
617
637
|
}
|
|
618
638
|
}
|
|
619
639
|
}, [client]);
|
|
620
|
-
(0,
|
|
640
|
+
(0, import_react14.useEffect)(() => {
|
|
621
641
|
mountedRef.current = true;
|
|
622
642
|
refresh();
|
|
623
643
|
return () => {
|
|
@@ -628,20 +648,20 @@ function useTopics() {
|
|
|
628
648
|
}
|
|
629
649
|
|
|
630
650
|
// src/community/usePosts.ts
|
|
631
|
-
var
|
|
651
|
+
var import_react15 = require("react");
|
|
632
652
|
function usePosts(params) {
|
|
633
653
|
const client = useCommunityClient();
|
|
634
|
-
const [posts, setPosts] = (0,
|
|
635
|
-
const [count, setCount] = (0,
|
|
636
|
-
const [isLoading, setIsLoading] = (0,
|
|
637
|
-
const [error, setError] = (0,
|
|
638
|
-
const mountedRef = (0,
|
|
654
|
+
const [posts, setPosts] = (0, import_react15.useState)([]);
|
|
655
|
+
const [count, setCount] = (0, import_react15.useState)(0);
|
|
656
|
+
const [isLoading, setIsLoading] = (0, import_react15.useState)(true);
|
|
657
|
+
const [error, setError] = (0, import_react15.useState)(null);
|
|
658
|
+
const mountedRef = (0, import_react15.useRef)(true);
|
|
639
659
|
const topicSlug = params?.topicSlug;
|
|
640
660
|
const status = params?.status;
|
|
641
661
|
const sort = params?.sort;
|
|
642
662
|
const limit = params?.limit;
|
|
643
663
|
const offset = params?.offset;
|
|
644
|
-
const refresh = (0,
|
|
664
|
+
const refresh = (0, import_react15.useCallback)(async () => {
|
|
645
665
|
setIsLoading(true);
|
|
646
666
|
setError(null);
|
|
647
667
|
try {
|
|
@@ -660,7 +680,7 @@ function usePosts(params) {
|
|
|
660
680
|
}
|
|
661
681
|
}
|
|
662
682
|
}, [client, topicSlug, status, sort, limit, offset]);
|
|
663
|
-
(0,
|
|
683
|
+
(0, import_react15.useEffect)(() => {
|
|
664
684
|
mountedRef.current = true;
|
|
665
685
|
refresh();
|
|
666
686
|
return () => {
|
|
@@ -671,14 +691,14 @@ function usePosts(params) {
|
|
|
671
691
|
}
|
|
672
692
|
|
|
673
693
|
// src/community/usePost.ts
|
|
674
|
-
var
|
|
694
|
+
var import_react16 = require("react");
|
|
675
695
|
function usePost(slug) {
|
|
676
696
|
const client = useCommunityClient();
|
|
677
|
-
const [data, setData] = (0,
|
|
678
|
-
const [isLoading, setIsLoading] = (0,
|
|
679
|
-
const [error, setError] = (0,
|
|
680
|
-
const mountedRef = (0,
|
|
681
|
-
const refresh = (0,
|
|
697
|
+
const [data, setData] = (0, import_react16.useState)(null);
|
|
698
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(true);
|
|
699
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
700
|
+
const mountedRef = (0, import_react16.useRef)(true);
|
|
701
|
+
const refresh = (0, import_react16.useCallback)(async () => {
|
|
682
702
|
setIsLoading(true);
|
|
683
703
|
setError(null);
|
|
684
704
|
try {
|
|
@@ -696,7 +716,7 @@ function usePost(slug) {
|
|
|
696
716
|
}
|
|
697
717
|
}
|
|
698
718
|
}, [client, slug]);
|
|
699
|
-
(0,
|
|
719
|
+
(0, import_react16.useEffect)(() => {
|
|
700
720
|
mountedRef.current = true;
|
|
701
721
|
refresh();
|
|
702
722
|
return () => {
|
|
@@ -707,20 +727,20 @@ function usePost(slug) {
|
|
|
707
727
|
}
|
|
708
728
|
|
|
709
729
|
// src/community/useCommunitySearch.ts
|
|
710
|
-
var
|
|
730
|
+
var import_react17 = require("react");
|
|
711
731
|
function useCommunitySearch() {
|
|
712
732
|
const client = useCommunityClient();
|
|
713
|
-
const [results, setResults] = (0,
|
|
714
|
-
const [isLoading, setIsLoading] = (0,
|
|
715
|
-
const [error, setError] = (0,
|
|
716
|
-
const mountedRef = (0,
|
|
717
|
-
(0,
|
|
733
|
+
const [results, setResults] = (0, import_react17.useState)(null);
|
|
734
|
+
const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
|
|
735
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
736
|
+
const mountedRef = (0, import_react17.useRef)(true);
|
|
737
|
+
(0, import_react17.useEffect)(() => {
|
|
718
738
|
mountedRef.current = true;
|
|
719
739
|
return () => {
|
|
720
740
|
mountedRef.current = false;
|
|
721
741
|
};
|
|
722
742
|
}, []);
|
|
723
|
-
const search = (0,
|
|
743
|
+
const search = (0, import_react17.useCallback)(
|
|
724
744
|
async (query) => {
|
|
725
745
|
if (!query.trim()) {
|
|
726
746
|
setResults(null);
|
|
@@ -749,10 +769,10 @@ function useCommunitySearch() {
|
|
|
749
769
|
}
|
|
750
770
|
|
|
751
771
|
// src/dashboard/CStarDashboardProvider.tsx
|
|
752
|
-
var
|
|
772
|
+
var import_react18 = require("react");
|
|
753
773
|
var import_js = require("@cstar.help/js");
|
|
754
774
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
755
|
-
var CStarDashboardContext = (0,
|
|
775
|
+
var CStarDashboardContext = (0, import_react18.createContext)(null);
|
|
756
776
|
function CStarDashboardProvider({
|
|
757
777
|
config,
|
|
758
778
|
client: providedClient,
|
|
@@ -760,10 +780,10 @@ function CStarDashboardProvider({
|
|
|
760
780
|
}) {
|
|
761
781
|
if (!config && !providedClient) {
|
|
762
782
|
throw new Error(
|
|
763
|
-
"CStarDashboardProvider requires either a `config` prop (`{ apiKey, teamId }
|
|
783
|
+
"CStarDashboardProvider requires either a `config` prop (`{ apiKey, teamId }`, recommended) or a `client` prop (a pre-built CStarClient instance, deprecated). See https://www.cstar.help/developers/sdk/react#dashboard"
|
|
764
784
|
);
|
|
765
785
|
}
|
|
766
|
-
const client = (0,
|
|
786
|
+
const client = (0, import_react18.useMemo)(() => {
|
|
767
787
|
if (providedClient) return providedClient;
|
|
768
788
|
return new import_js.CStarClient(config);
|
|
769
789
|
}, [
|
|
@@ -775,17 +795,12 @@ function CStarDashboardProvider({
|
|
|
775
795
|
config?.maxRetries,
|
|
776
796
|
config?.timeout
|
|
777
797
|
]);
|
|
778
|
-
const contextValue = (0,
|
|
779
|
-
(
|
|
780
|
-
if (providedClient) return;
|
|
781
|
-
return () => {
|
|
782
|
-
client?.realtime?.disconnect?.();
|
|
783
|
-
};
|
|
784
|
-
}, [client, providedClient]);
|
|
798
|
+
const contextValue = (0, import_react18.useMemo)(() => ({ client }), [client]);
|
|
799
|
+
useDisconnectOnUnmount(providedClient ? null : client, (owned) => owned.realtime?.disconnect?.());
|
|
785
800
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CStarDashboardContext.Provider, { value: contextValue, children });
|
|
786
801
|
}
|
|
787
802
|
function useDashboardClient() {
|
|
788
|
-
const ctx = (0,
|
|
803
|
+
const ctx = (0, import_react18.useContext)(CStarDashboardContext);
|
|
789
804
|
if (!ctx) {
|
|
790
805
|
throw new Error("useDashboardClient must be used within a <CStarDashboardProvider>");
|
|
791
806
|
}
|
|
@@ -793,7 +808,7 @@ function useDashboardClient() {
|
|
|
793
808
|
}
|
|
794
809
|
|
|
795
810
|
// src/dashboard/useCStarQuery.ts
|
|
796
|
-
var
|
|
811
|
+
var import_react19 = require("react");
|
|
797
812
|
var import_js2 = require("@cstar.help/js");
|
|
798
813
|
function resolveResource(client, path) {
|
|
799
814
|
const parts = path.split(".");
|
|
@@ -812,12 +827,12 @@ function useCStarQuery(resource, params) {
|
|
|
812
827
|
);
|
|
813
828
|
}
|
|
814
829
|
const client = useDashboardClient();
|
|
815
|
-
const [data, setData] = (0,
|
|
816
|
-
const [loading, setLoading] = (0,
|
|
817
|
-
const [error, setError] = (0,
|
|
818
|
-
const subscriptionRef = (0,
|
|
830
|
+
const [data, setData] = (0, import_react19.useState)(null);
|
|
831
|
+
const [loading, setLoading] = (0, import_react19.useState)(true);
|
|
832
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
833
|
+
const subscriptionRef = (0, import_react19.useRef)(null);
|
|
819
834
|
const paramsKey = params ? JSON.stringify(params) : "";
|
|
820
|
-
(0,
|
|
835
|
+
(0, import_react19.useEffect)(() => {
|
|
821
836
|
const resolved = resolveResource(client, resource);
|
|
822
837
|
if (!resolved) {
|
|
823
838
|
setError(new Error(`Invalid resource path: ${resource}. Expected format: 'tickets.list'`));
|
|
@@ -840,7 +855,7 @@ function useCStarQuery(resource, params) {
|
|
|
840
855
|
subscriptionRef.current = null;
|
|
841
856
|
};
|
|
842
857
|
}, [client, resource, paramsKey]);
|
|
843
|
-
const refresh = (0,
|
|
858
|
+
const refresh = (0, import_react19.useCallback)(async () => {
|
|
844
859
|
if (subscriptionRef.current) {
|
|
845
860
|
await subscriptionRef.current.refresh();
|
|
846
861
|
}
|
|
@@ -849,7 +864,7 @@ function useCStarQuery(resource, params) {
|
|
|
849
864
|
}
|
|
850
865
|
|
|
851
866
|
// src/dashboard/useCStarMutation.ts
|
|
852
|
-
var
|
|
867
|
+
var import_react20 = require("react");
|
|
853
868
|
function resolveMutation(client, path) {
|
|
854
869
|
const parts = path.split(".");
|
|
855
870
|
if (parts.length < 2) return null;
|
|
@@ -877,9 +892,9 @@ function resolveMutation(client, path) {
|
|
|
877
892
|
}
|
|
878
893
|
function useCStarMutation(resource) {
|
|
879
894
|
const client = useDashboardClient();
|
|
880
|
-
const [loading, setLoading] = (0,
|
|
881
|
-
const [error, setError] = (0,
|
|
882
|
-
const mutate = (0,
|
|
895
|
+
const [loading, setLoading] = (0, import_react20.useState)(false);
|
|
896
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
897
|
+
const mutate = (0, import_react20.useCallback)(
|
|
883
898
|
async (params) => {
|
|
884
899
|
const fn = resolveMutation(client, resource);
|
|
885
900
|
if (!fn) {
|
|
@@ -904,14 +919,14 @@ function useCStarMutation(resource) {
|
|
|
904
919
|
}
|
|
905
920
|
|
|
906
921
|
// src/dashboard/useCStarEvents.ts
|
|
907
|
-
var
|
|
922
|
+
var import_react21 = require("react");
|
|
908
923
|
var MAX_EVENTS = 100;
|
|
909
924
|
function useCStarEvents(types) {
|
|
910
925
|
const client = useDashboardClient();
|
|
911
|
-
const [events, setEvents] = (0,
|
|
912
|
-
const [connected, setConnected] = (0,
|
|
926
|
+
const [events, setEvents] = (0, import_react21.useState)([]);
|
|
927
|
+
const [connected, setConnected] = (0, import_react21.useState)(false);
|
|
913
928
|
const typesKey = types ? types.join(",") : "";
|
|
914
|
-
(0,
|
|
929
|
+
(0, import_react21.useEffect)(() => {
|
|
915
930
|
const realtime = client.realtime;
|
|
916
931
|
const handler = (event) => {
|
|
917
932
|
if (types && types.length > 0) {
|
|
@@ -943,14 +958,14 @@ function useCStarEvents(types) {
|
|
|
943
958
|
}
|
|
944
959
|
|
|
945
960
|
// src/dashboard/useBossBattle.ts
|
|
946
|
-
var
|
|
961
|
+
var import_react22 = require("react");
|
|
947
962
|
function useBossBattle() {
|
|
948
963
|
const client = useDashboardClient();
|
|
949
|
-
const [boss, setBoss] = (0,
|
|
950
|
-
const [loading, setLoading] = (0,
|
|
951
|
-
const [error, setError] = (0,
|
|
952
|
-
const subRef = (0,
|
|
953
|
-
(0,
|
|
964
|
+
const [boss, setBoss] = (0, import_react22.useState)(null);
|
|
965
|
+
const [loading, setLoading] = (0, import_react22.useState)(true);
|
|
966
|
+
const [error, setError] = (0, import_react22.useState)(null);
|
|
967
|
+
const subRef = (0, import_react22.useRef)(null);
|
|
968
|
+
(0, import_react22.useEffect)(() => {
|
|
954
969
|
const sub = client.game.subscribeBoss(client.realtime);
|
|
955
970
|
subRef.current = sub;
|
|
956
971
|
sub.on("change", (data) => {
|
|
@@ -967,21 +982,21 @@ function useBossBattle() {
|
|
|
967
982
|
subRef.current = null;
|
|
968
983
|
};
|
|
969
984
|
}, [client]);
|
|
970
|
-
const refresh = (0,
|
|
985
|
+
const refresh = (0, import_react22.useCallback)(async () => {
|
|
971
986
|
if (subRef.current) await subRef.current.refresh();
|
|
972
987
|
}, []);
|
|
973
988
|
return { boss, active: boss?.active ?? false, loading, error, refresh };
|
|
974
989
|
}
|
|
975
990
|
|
|
976
991
|
// src/dashboard/usePlayerStats.ts
|
|
977
|
-
var
|
|
992
|
+
var import_react23 = require("react");
|
|
978
993
|
function usePlayerStats(memberId) {
|
|
979
994
|
const client = useDashboardClient();
|
|
980
|
-
const [player, setPlayer] = (0,
|
|
981
|
-
const [loading, setLoading] = (0,
|
|
982
|
-
const [error, setError] = (0,
|
|
983
|
-
const subRef = (0,
|
|
984
|
-
(0,
|
|
995
|
+
const [player, setPlayer] = (0, import_react23.useState)(null);
|
|
996
|
+
const [loading, setLoading] = (0, import_react23.useState)(true);
|
|
997
|
+
const [error, setError] = (0, import_react23.useState)(null);
|
|
998
|
+
const subRef = (0, import_react23.useRef)(null);
|
|
999
|
+
(0, import_react23.useEffect)(() => {
|
|
985
1000
|
const sub = client.game.subscribePlayer(client.realtime, memberId);
|
|
986
1001
|
subRef.current = sub;
|
|
987
1002
|
sub.on("change", (data) => {
|
|
@@ -998,21 +1013,21 @@ function usePlayerStats(memberId) {
|
|
|
998
1013
|
subRef.current = null;
|
|
999
1014
|
};
|
|
1000
1015
|
}, [client, memberId]);
|
|
1001
|
-
const refresh = (0,
|
|
1016
|
+
const refresh = (0, import_react23.useCallback)(async () => {
|
|
1002
1017
|
if (subRef.current) await subRef.current.refresh();
|
|
1003
1018
|
}, []);
|
|
1004
1019
|
return { player, loading, error, refresh };
|
|
1005
1020
|
}
|
|
1006
1021
|
|
|
1007
1022
|
// src/dashboard/useLeaderboard.ts
|
|
1008
|
-
var
|
|
1023
|
+
var import_react24 = require("react");
|
|
1009
1024
|
function useLeaderboard(period) {
|
|
1010
1025
|
const client = useDashboardClient();
|
|
1011
|
-
const [entries, setEntries] = (0,
|
|
1012
|
-
const [loading, setLoading] = (0,
|
|
1013
|
-
const [error, setError] = (0,
|
|
1014
|
-
const subRef = (0,
|
|
1015
|
-
(0,
|
|
1026
|
+
const [entries, setEntries] = (0, import_react24.useState)([]);
|
|
1027
|
+
const [loading, setLoading] = (0, import_react24.useState)(true);
|
|
1028
|
+
const [error, setError] = (0, import_react24.useState)(null);
|
|
1029
|
+
const subRef = (0, import_react24.useRef)(null);
|
|
1030
|
+
(0, import_react24.useEffect)(() => {
|
|
1016
1031
|
const sub = client.game.subscribeLeaderboard(client.realtime, period ? { period } : void 0);
|
|
1017
1032
|
subRef.current = sub;
|
|
1018
1033
|
sub.on("change", (data) => {
|
|
@@ -1029,21 +1044,21 @@ function useLeaderboard(period) {
|
|
|
1029
1044
|
subRef.current = null;
|
|
1030
1045
|
};
|
|
1031
1046
|
}, [client, period]);
|
|
1032
|
-
const refresh = (0,
|
|
1047
|
+
const refresh = (0, import_react24.useCallback)(async () => {
|
|
1033
1048
|
if (subRef.current) await subRef.current.refresh();
|
|
1034
1049
|
}, []);
|
|
1035
1050
|
return { entries, loading, error, refresh };
|
|
1036
1051
|
}
|
|
1037
1052
|
|
|
1038
1053
|
// src/dashboard/useGameActivity.ts
|
|
1039
|
-
var
|
|
1054
|
+
var import_react25 = require("react");
|
|
1040
1055
|
function useGameActivity() {
|
|
1041
1056
|
const client = useDashboardClient();
|
|
1042
|
-
const [events, setEvents] = (0,
|
|
1043
|
-
const [loading, setLoading] = (0,
|
|
1044
|
-
const [error, setError] = (0,
|
|
1045
|
-
const subRef = (0,
|
|
1046
|
-
(0,
|
|
1057
|
+
const [events, setEvents] = (0, import_react25.useState)([]);
|
|
1058
|
+
const [loading, setLoading] = (0, import_react25.useState)(true);
|
|
1059
|
+
const [error, setError] = (0, import_react25.useState)(null);
|
|
1060
|
+
const subRef = (0, import_react25.useRef)(null);
|
|
1061
|
+
(0, import_react25.useEffect)(() => {
|
|
1047
1062
|
const sub = client.game.subscribeActivity(client.realtime);
|
|
1048
1063
|
subRef.current = sub;
|
|
1049
1064
|
sub.on("change", (data) => {
|
|
@@ -1060,7 +1075,7 @@ function useGameActivity() {
|
|
|
1060
1075
|
subRef.current = null;
|
|
1061
1076
|
};
|
|
1062
1077
|
}, [client]);
|
|
1063
|
-
const refresh = (0,
|
|
1078
|
+
const refresh = (0, import_react25.useCallback)(async () => {
|
|
1064
1079
|
if (subRef.current) await subRef.current.refresh();
|
|
1065
1080
|
}, []);
|
|
1066
1081
|
return { events, loading, error, refresh };
|