@poolse/react-ui 2.0.2 → 2.0.5
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/dist/index.cjs +457 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +112 -2
- package/dist/index.d.ts +112 -2
- package/dist/index.js +456 -9
- package/dist/index.js.map +1 -1
- package/dist/styles.css +405 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useMembers, useAttachmentUpload,
|
|
3
|
-
import { forwardRef, useState, useRef, useImperativeHandle, useEffect, Fragment as Fragment$1
|
|
2
|
+
import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useRealtimeStatus, useReactions, useThread, useAttachmentUrl } from '@poolse/react';
|
|
3
|
+
import { forwardRef, useState, useRef, useImperativeHandle, useEffect, useCallback, useMemo, Fragment as Fragment$1 } from 'react';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import ReactMarkdown from 'react-markdown';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
@@ -2316,6 +2316,62 @@ function ConversationView({
|
|
|
2316
2316
|
) })
|
|
2317
2317
|
] });
|
|
2318
2318
|
}
|
|
2319
|
+
function ChatHeader({
|
|
2320
|
+
conversationId,
|
|
2321
|
+
labelFor,
|
|
2322
|
+
avatarFor,
|
|
2323
|
+
onBack,
|
|
2324
|
+
onPress,
|
|
2325
|
+
onMembersPress,
|
|
2326
|
+
rightSlot
|
|
2327
|
+
}) {
|
|
2328
|
+
const { me } = useMe();
|
|
2329
|
+
const meId = me?.id ?? null;
|
|
2330
|
+
const { conversation: conv } = useConversation(conversationId);
|
|
2331
|
+
const { members } = useMembers(conversationId);
|
|
2332
|
+
const { online } = usePresence(conversationId);
|
|
2333
|
+
const isDirect = conv?.type === "direct";
|
|
2334
|
+
const otherMember = isDirect ? members.find((m) => m.user_id !== meId) : null;
|
|
2335
|
+
const otherExtId = otherMember?.external_id ?? null;
|
|
2336
|
+
const title = isDirect ? otherExtId ? labelFor?.(otherExtId) ?? otherExtId : conv?.name ?? "Direct chat" : conv?.name ?? "Untitled group";
|
|
2337
|
+
const avatarUrl = isDirect && otherExtId ? avatarFor?.(otherExtId) ?? null : null;
|
|
2338
|
+
const otherOnline = isDirect && otherExtId ? online.has(otherExtId) : false;
|
|
2339
|
+
const subtitle = isDirect ? otherOnline ? "Online" : null : `${members.length} member${members.length === 1 ? "" : "s"}`;
|
|
2340
|
+
const isPressable = typeof onPress === "function";
|
|
2341
|
+
const titleContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2342
|
+
/* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name: title, online: otherOnline, size: "md" }),
|
|
2343
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-chat-header__titles", children: [
|
|
2344
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-chat-header__title", children: title }),
|
|
2345
|
+
subtitle ? /* @__PURE__ */ jsx("div", { className: "poolse-chat-header__subtitle", children: subtitle }) : null
|
|
2346
|
+
] })
|
|
2347
|
+
] });
|
|
2348
|
+
return /* @__PURE__ */ jsxs("header", { className: "poolse-chat-header", children: [
|
|
2349
|
+
onBack ? /* @__PURE__ */ jsx(
|
|
2350
|
+
"button",
|
|
2351
|
+
{
|
|
2352
|
+
type: "button",
|
|
2353
|
+
className: "poolse-icon-btn poolse-chat-header__back",
|
|
2354
|
+
onClick: onBack,
|
|
2355
|
+
"aria-label": "Back",
|
|
2356
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "reply", size: 20, label: null })
|
|
2357
|
+
}
|
|
2358
|
+
) : null,
|
|
2359
|
+
isPressable ? /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-chat-header__title-btn", onClick: onPress, children: titleContent }) : /* @__PURE__ */ jsx("div", { className: "poolse-chat-header__title-row", children: titleContent }),
|
|
2360
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-chat-header__actions", children: [
|
|
2361
|
+
!isDirect && onMembersPress ? /* @__PURE__ */ jsx(
|
|
2362
|
+
"button",
|
|
2363
|
+
{
|
|
2364
|
+
type: "button",
|
|
2365
|
+
className: "poolse-icon-btn",
|
|
2366
|
+
onClick: onMembersPress,
|
|
2367
|
+
"aria-label": "View members",
|
|
2368
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "users", size: 20, label: null })
|
|
2369
|
+
}
|
|
2370
|
+
) : null,
|
|
2371
|
+
rightSlot
|
|
2372
|
+
] })
|
|
2373
|
+
] });
|
|
2374
|
+
}
|
|
2319
2375
|
function ConversationList({
|
|
2320
2376
|
selectedId,
|
|
2321
2377
|
onSelect,
|
|
@@ -2324,9 +2380,13 @@ function ConversationList({
|
|
|
2324
2380
|
conversations: controlledConversations,
|
|
2325
2381
|
loading: controlledLoading,
|
|
2326
2382
|
error: controlledError,
|
|
2327
|
-
unreadCounts
|
|
2383
|
+
unreadCounts,
|
|
2384
|
+
labelFor,
|
|
2385
|
+
avatarFor
|
|
2328
2386
|
}) {
|
|
2329
2387
|
const auto = useConversations();
|
|
2388
|
+
const { me } = useMe();
|
|
2389
|
+
const meExternalId = me?.external_id ?? null;
|
|
2330
2390
|
const isControlled = controlledConversations !== void 0;
|
|
2331
2391
|
const conversations = isControlled ? controlledConversations : auto.conversations;
|
|
2332
2392
|
const loading = isControlled ? controlledLoading ?? false : auto.loading;
|
|
@@ -2344,7 +2404,17 @@ function ConversationList({
|
|
|
2344
2404
|
return /* @__PURE__ */ jsx("ul", { className: "poolse-list", role: "listbox", "aria-label": "Conversations", children: conversations.map((conv) => {
|
|
2345
2405
|
const selected = selectedId === conv.id;
|
|
2346
2406
|
const unread = counts?.[conv.id] ?? 0;
|
|
2347
|
-
const content = renderItem ? renderItem(conv, selected) : /* @__PURE__ */ jsx(
|
|
2407
|
+
const content = renderItem ? renderItem(conv, selected) : /* @__PURE__ */ jsx(
|
|
2408
|
+
DefaultRow,
|
|
2409
|
+
{
|
|
2410
|
+
conv,
|
|
2411
|
+
selected,
|
|
2412
|
+
unread,
|
|
2413
|
+
meExternalId,
|
|
2414
|
+
...labelFor ? { labelFor } : {},
|
|
2415
|
+
...avatarFor ? { avatarFor } : {}
|
|
2416
|
+
}
|
|
2417
|
+
);
|
|
2348
2418
|
return /* @__PURE__ */ jsx(
|
|
2349
2419
|
"li",
|
|
2350
2420
|
{
|
|
@@ -2368,19 +2438,26 @@ function ConversationList({
|
|
|
2368
2438
|
function DefaultRow({
|
|
2369
2439
|
conv,
|
|
2370
2440
|
selected: _selected,
|
|
2371
|
-
unread
|
|
2441
|
+
unread,
|
|
2442
|
+
meExternalId,
|
|
2443
|
+
labelFor,
|
|
2444
|
+
avatarFor
|
|
2372
2445
|
}) {
|
|
2373
|
-
const
|
|
2446
|
+
const isDirect = conv.type === "direct";
|
|
2447
|
+
const otherExtId = isDirect && meExternalId ? (conv.member_external_ids ?? []).find((x) => x !== meExternalId) : null;
|
|
2448
|
+
const title = isDirect ? otherExtId ? labelFor?.(otherExtId) ?? otherExtId : conv.name ?? "Direct chat" : conv.name ?? "Untitled group";
|
|
2449
|
+
const avatarUrl = isDirect ? otherExtId ? avatarFor?.(otherExtId) ?? null : conv.avatar_url ?? null : conv.avatar_url ?? null;
|
|
2374
2450
|
const time = conv.last_message_at ? formatRelative(conv.last_message_at) : "";
|
|
2375
2451
|
const hasUnread = unread > 0;
|
|
2452
|
+
const preview = conv.last_message_preview ?? (conv.last_sequence > 0 ? `${conv.last_sequence} message${conv.last_sequence === 1 ? "" : "s"}` : "No messages yet");
|
|
2376
2453
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2377
|
-
/* @__PURE__ */ jsx(Avatar, { src:
|
|
2454
|
+
/* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name: title, size: "md" }),
|
|
2378
2455
|
/* @__PURE__ */ jsxs("div", { className: "poolse-list__body", children: [
|
|
2379
2456
|
/* @__PURE__ */ jsxs("div", { className: "poolse-list__head", children: [
|
|
2380
2457
|
/* @__PURE__ */ jsx("span", { className: `poolse-list__title${hasUnread ? " poolse-list__title--unread" : ""}`, children: title }),
|
|
2381
2458
|
time && /* @__PURE__ */ jsx("span", { className: "poolse-list__time", children: time })
|
|
2382
2459
|
] }),
|
|
2383
|
-
/* @__PURE__ */ jsx("div", { className: "poolse-list__preview", children:
|
|
2460
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-list__preview", children: preview })
|
|
2384
2461
|
] }),
|
|
2385
2462
|
hasUnread && /* @__PURE__ */ jsx(
|
|
2386
2463
|
"span",
|
|
@@ -2479,6 +2556,376 @@ function RoleBadge({ role }) {
|
|
|
2479
2556
|
const mod = role === "owner" ? "owner" : role === "admin" ? "admin" : null;
|
|
2480
2557
|
return /* @__PURE__ */ jsx("span", { className: `poolse-badge${mod ? ` poolse-badge--${mod}` : ""}`, children: role });
|
|
2481
2558
|
}
|
|
2559
|
+
function GroupDetailsSheet({
|
|
2560
|
+
visible,
|
|
2561
|
+
onClose,
|
|
2562
|
+
conversationId,
|
|
2563
|
+
labelFor,
|
|
2564
|
+
avatarFor,
|
|
2565
|
+
footer
|
|
2566
|
+
}) {
|
|
2567
|
+
const { conversation: conv } = useConversation(visible ? conversationId : null);
|
|
2568
|
+
useEffect(() => {
|
|
2569
|
+
if (!visible) return void 0;
|
|
2570
|
+
const onKey = (e) => {
|
|
2571
|
+
if (e.key === "Escape") onClose();
|
|
2572
|
+
};
|
|
2573
|
+
document.addEventListener("keydown", onKey);
|
|
2574
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
2575
|
+
}, [visible, onClose]);
|
|
2576
|
+
if (!visible) return null;
|
|
2577
|
+
const title = conv?.name ?? "Group";
|
|
2578
|
+
const memberCount = conv?.member_external_ids?.length ?? 0;
|
|
2579
|
+
return /* @__PURE__ */ jsx(
|
|
2580
|
+
"div",
|
|
2581
|
+
{
|
|
2582
|
+
className: "poolse-modal",
|
|
2583
|
+
role: "dialog",
|
|
2584
|
+
"aria-modal": "true",
|
|
2585
|
+
"aria-label": "Group details",
|
|
2586
|
+
onClick: (e) => {
|
|
2587
|
+
if (e.target === e.currentTarget) onClose();
|
|
2588
|
+
},
|
|
2589
|
+
children: /* @__PURE__ */ jsxs("div", { className: "poolse-modal__sheet", children: [
|
|
2590
|
+
/* @__PURE__ */ jsxs("header", { className: "poolse-modal__header", children: [
|
|
2591
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-modal__title", children: "Group details" }),
|
|
2592
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "poolse-icon-btn", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 18, label: null }) })
|
|
2593
|
+
] }),
|
|
2594
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-modal__body", children: [
|
|
2595
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-group-details__hero", children: [
|
|
2596
|
+
/* @__PURE__ */ jsx(Avatar, { src: conv?.avatar_url ?? null, name: title, size: "lg" }),
|
|
2597
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-group-details__hero-text", children: [
|
|
2598
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-group-details__title", children: title }),
|
|
2599
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-group-details__subtitle", children: memberCount > 0 ? `${memberCount} member${memberCount === 1 ? "" : "s"}` : "" })
|
|
2600
|
+
] })
|
|
2601
|
+
] }),
|
|
2602
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-group-details__members", children: /* @__PURE__ */ jsx(
|
|
2603
|
+
MemberList,
|
|
2604
|
+
{
|
|
2605
|
+
conversationId,
|
|
2606
|
+
...labelFor ? { labelFor } : {},
|
|
2607
|
+
...avatarFor ? { avatarFor } : {}
|
|
2608
|
+
}
|
|
2609
|
+
) })
|
|
2610
|
+
] }),
|
|
2611
|
+
footer ? /* @__PURE__ */ jsx("footer", { className: "poolse-modal__footer", children: footer }) : null
|
|
2612
|
+
] })
|
|
2613
|
+
}
|
|
2614
|
+
);
|
|
2615
|
+
}
|
|
2616
|
+
function UserPickerSheet({
|
|
2617
|
+
visible,
|
|
2618
|
+
onClose,
|
|
2619
|
+
users,
|
|
2620
|
+
excludeIds = [],
|
|
2621
|
+
mode,
|
|
2622
|
+
onPickDirect,
|
|
2623
|
+
onCreateGroup
|
|
2624
|
+
}) {
|
|
2625
|
+
const [query, setQuery] = useState("");
|
|
2626
|
+
const [selected, setSelected] = useState(/* @__PURE__ */ new Set());
|
|
2627
|
+
const [groupName, setGroupName] = useState("");
|
|
2628
|
+
const searchRef = useRef(null);
|
|
2629
|
+
useEffect(() => {
|
|
2630
|
+
if (visible) {
|
|
2631
|
+
setQuery("");
|
|
2632
|
+
setSelected(/* @__PURE__ */ new Set());
|
|
2633
|
+
setGroupName("");
|
|
2634
|
+
const id = setTimeout(() => searchRef.current?.focus(), 50);
|
|
2635
|
+
return () => clearTimeout(id);
|
|
2636
|
+
}
|
|
2637
|
+
return void 0;
|
|
2638
|
+
}, [visible]);
|
|
2639
|
+
useEffect(() => {
|
|
2640
|
+
if (!visible) return void 0;
|
|
2641
|
+
const onKey = (e) => {
|
|
2642
|
+
if (e.key === "Escape") onClose();
|
|
2643
|
+
};
|
|
2644
|
+
document.addEventListener("keydown", onKey);
|
|
2645
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
2646
|
+
}, [visible, onClose]);
|
|
2647
|
+
const filtered = useMemo(() => {
|
|
2648
|
+
const q = query.trim().toLowerCase();
|
|
2649
|
+
const excluded = new Set(excludeIds);
|
|
2650
|
+
return users.filter((u) => {
|
|
2651
|
+
if (excluded.has(u.externalId)) return false;
|
|
2652
|
+
if (!q) return true;
|
|
2653
|
+
return u.name.toLowerCase().includes(q) || u.externalId.toLowerCase().includes(q) || (u.subtitle ?? "").toLowerCase().includes(q);
|
|
2654
|
+
});
|
|
2655
|
+
}, [users, excludeIds, query]);
|
|
2656
|
+
if (!visible) return null;
|
|
2657
|
+
const toggle = (externalId) => {
|
|
2658
|
+
setSelected((prev) => {
|
|
2659
|
+
const next = new Set(prev);
|
|
2660
|
+
if (next.has(externalId)) next.delete(externalId);
|
|
2661
|
+
else next.add(externalId);
|
|
2662
|
+
return next;
|
|
2663
|
+
});
|
|
2664
|
+
};
|
|
2665
|
+
const canSubmitGroup = mode === "group" && selected.size >= 2 && groupName.trim().length > 0;
|
|
2666
|
+
return /* @__PURE__ */ jsx(
|
|
2667
|
+
"div",
|
|
2668
|
+
{
|
|
2669
|
+
className: "poolse-modal",
|
|
2670
|
+
role: "dialog",
|
|
2671
|
+
"aria-modal": "true",
|
|
2672
|
+
"aria-label": mode === "group" ? "Create group" : "New chat",
|
|
2673
|
+
onClick: (e) => {
|
|
2674
|
+
if (e.target === e.currentTarget) onClose();
|
|
2675
|
+
},
|
|
2676
|
+
children: /* @__PURE__ */ jsxs("div", { className: "poolse-modal__sheet", children: [
|
|
2677
|
+
/* @__PURE__ */ jsxs("header", { className: "poolse-modal__header", children: [
|
|
2678
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-modal__title", children: mode === "group" ? "New group" : "New chat" }),
|
|
2679
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "poolse-icon-btn", onClick: onClose, "aria-label": "Close", children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 18, label: null }) })
|
|
2680
|
+
] }),
|
|
2681
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-modal__body", children: [
|
|
2682
|
+
mode === "group" ? /* @__PURE__ */ jsx(
|
|
2683
|
+
"input",
|
|
2684
|
+
{
|
|
2685
|
+
type: "text",
|
|
2686
|
+
value: groupName,
|
|
2687
|
+
onChange: (e) => setGroupName(e.target.value),
|
|
2688
|
+
placeholder: "Group name",
|
|
2689
|
+
className: "poolse-input",
|
|
2690
|
+
"aria-label": "Group name"
|
|
2691
|
+
}
|
|
2692
|
+
) : null,
|
|
2693
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-modal__search", children: [
|
|
2694
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "search", size: 16, label: null }),
|
|
2695
|
+
/* @__PURE__ */ jsx(
|
|
2696
|
+
"input",
|
|
2697
|
+
{
|
|
2698
|
+
ref: searchRef,
|
|
2699
|
+
type: "text",
|
|
2700
|
+
value: query,
|
|
2701
|
+
onChange: (e) => setQuery(e.target.value),
|
|
2702
|
+
placeholder: "Search by name or id\u2026",
|
|
2703
|
+
className: "poolse-input poolse-input--bare",
|
|
2704
|
+
"aria-label": "Search users"
|
|
2705
|
+
}
|
|
2706
|
+
)
|
|
2707
|
+
] }),
|
|
2708
|
+
/* @__PURE__ */ jsx("ul", { className: "poolse-user-picker", role: "listbox", "aria-label": "Users", children: filtered.length === 0 ? /* @__PURE__ */ jsx("li", { className: "poolse-user-picker__empty", children: "No matching users." }) : filtered.map((u) => {
|
|
2709
|
+
const isSelected = selected.has(u.externalId);
|
|
2710
|
+
return /* @__PURE__ */ jsxs(
|
|
2711
|
+
"li",
|
|
2712
|
+
{
|
|
2713
|
+
role: "option",
|
|
2714
|
+
"aria-selected": isSelected,
|
|
2715
|
+
className: `poolse-user-picker__row${isSelected ? " poolse-user-picker__row--selected" : ""}`,
|
|
2716
|
+
onClick: () => {
|
|
2717
|
+
if (mode === "single") {
|
|
2718
|
+
onPickDirect?.(u.externalId);
|
|
2719
|
+
onClose();
|
|
2720
|
+
} else {
|
|
2721
|
+
toggle(u.externalId);
|
|
2722
|
+
}
|
|
2723
|
+
},
|
|
2724
|
+
children: [
|
|
2725
|
+
/* @__PURE__ */ jsx(Avatar, { src: u.avatarUrl ?? null, name: u.name, size: "md" }),
|
|
2726
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-user-picker__body", children: [
|
|
2727
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-user-picker__name", children: u.name }),
|
|
2728
|
+
u.subtitle ? /* @__PURE__ */ jsx("div", { className: "poolse-user-picker__subtitle", children: u.subtitle }) : null
|
|
2729
|
+
] }),
|
|
2730
|
+
mode === "group" ? /* @__PURE__ */ jsx(
|
|
2731
|
+
"span",
|
|
2732
|
+
{
|
|
2733
|
+
className: `poolse-user-picker__check${isSelected ? " poolse-user-picker__check--on" : ""}`,
|
|
2734
|
+
"aria-hidden": "true",
|
|
2735
|
+
children: isSelected ? "\u2713" : ""
|
|
2736
|
+
}
|
|
2737
|
+
) : null
|
|
2738
|
+
]
|
|
2739
|
+
},
|
|
2740
|
+
u.externalId
|
|
2741
|
+
);
|
|
2742
|
+
}) })
|
|
2743
|
+
] }),
|
|
2744
|
+
mode === "group" ? /* @__PURE__ */ jsxs("footer", { className: "poolse-modal__footer", children: [
|
|
2745
|
+
/* @__PURE__ */ jsxs("span", { className: "poolse-modal__footer-hint", children: [
|
|
2746
|
+
selected.size,
|
|
2747
|
+
" selected",
|
|
2748
|
+
selected.size < 2 ? " (need 2+)" : ""
|
|
2749
|
+
] }),
|
|
2750
|
+
/* @__PURE__ */ jsx(
|
|
2751
|
+
"button",
|
|
2752
|
+
{
|
|
2753
|
+
type: "button",
|
|
2754
|
+
className: "poolse-btn poolse-btn--brand",
|
|
2755
|
+
disabled: !canSubmitGroup,
|
|
2756
|
+
onClick: () => {
|
|
2757
|
+
if (!canSubmitGroup) return;
|
|
2758
|
+
onCreateGroup?.(groupName.trim(), Array.from(selected));
|
|
2759
|
+
onClose();
|
|
2760
|
+
},
|
|
2761
|
+
children: "Create group"
|
|
2762
|
+
}
|
|
2763
|
+
)
|
|
2764
|
+
] }) : null
|
|
2765
|
+
] })
|
|
2766
|
+
}
|
|
2767
|
+
);
|
|
2768
|
+
}
|
|
2769
|
+
var PoolseInbox = forwardRef(function PoolseInbox2({
|
|
2770
|
+
title = "Chats",
|
|
2771
|
+
users,
|
|
2772
|
+
labelFor,
|
|
2773
|
+
avatarFor,
|
|
2774
|
+
renderRightAction,
|
|
2775
|
+
renderConversationRow,
|
|
2776
|
+
emptyState
|
|
2777
|
+
}, ref) {
|
|
2778
|
+
const { me } = useMe();
|
|
2779
|
+
const meExternalId = me?.external_id ?? null;
|
|
2780
|
+
const { conversations, create, unreadCounts } = useConversations();
|
|
2781
|
+
const [activeId, setActiveId] = useState(null);
|
|
2782
|
+
const [userPickerOpen, setUserPickerOpen] = useState(false);
|
|
2783
|
+
const [groupPickerOpen, setGroupPickerOpen] = useState(false);
|
|
2784
|
+
const [groupDetailsOpen, setGroupDetailsOpen] = useState(false);
|
|
2785
|
+
const openDirect = useCallback(
|
|
2786
|
+
async (externalId) => {
|
|
2787
|
+
const conv = await create({
|
|
2788
|
+
type: "direct",
|
|
2789
|
+
member_external_ids: [externalId]
|
|
2790
|
+
});
|
|
2791
|
+
setActiveId(conv.id);
|
|
2792
|
+
},
|
|
2793
|
+
[create]
|
|
2794
|
+
);
|
|
2795
|
+
const openGroup = useCallback(
|
|
2796
|
+
async (name, memberExternalIds) => {
|
|
2797
|
+
const conv = await create({
|
|
2798
|
+
type: "group",
|
|
2799
|
+
name,
|
|
2800
|
+
member_external_ids: memberExternalIds
|
|
2801
|
+
});
|
|
2802
|
+
setActiveId(conv.id);
|
|
2803
|
+
},
|
|
2804
|
+
[create]
|
|
2805
|
+
);
|
|
2806
|
+
useImperativeHandle(
|
|
2807
|
+
ref,
|
|
2808
|
+
() => ({
|
|
2809
|
+
open: setActiveId,
|
|
2810
|
+
openDirect,
|
|
2811
|
+
openGroup,
|
|
2812
|
+
promptNewChat: () => setUserPickerOpen(true),
|
|
2813
|
+
promptNewGroup: () => setGroupPickerOpen(true),
|
|
2814
|
+
close: () => setActiveId(null)
|
|
2815
|
+
}),
|
|
2816
|
+
[openDirect, openGroup]
|
|
2817
|
+
);
|
|
2818
|
+
const renderRow = useMemo(() => {
|
|
2819
|
+
if (!renderConversationRow) return void 0;
|
|
2820
|
+
return (conv, selected) => renderConversationRow(conv, meExternalId, selected);
|
|
2821
|
+
}, [renderConversationRow, meExternalId]);
|
|
2822
|
+
const activeConv = activeId ? conversations.find((c) => c.id === activeId) ?? null : null;
|
|
2823
|
+
const isGroup = activeConv?.type === "group";
|
|
2824
|
+
return /* @__PURE__ */ jsxs("div", { className: `poolse-inbox${activeId ? " poolse-inbox--detail-open" : ""}`, children: [
|
|
2825
|
+
/* @__PURE__ */ jsxs("aside", { className: "poolse-inbox__list-pane", children: [
|
|
2826
|
+
/* @__PURE__ */ jsxs("header", { className: "poolse-inbox__list-header", children: [
|
|
2827
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-inbox__list-title", children: title }),
|
|
2828
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-inbox__list-actions", children: [
|
|
2829
|
+
users ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2830
|
+
/* @__PURE__ */ jsx(
|
|
2831
|
+
"button",
|
|
2832
|
+
{
|
|
2833
|
+
type: "button",
|
|
2834
|
+
className: "poolse-icon-btn",
|
|
2835
|
+
onClick: () => setUserPickerOpen(true),
|
|
2836
|
+
"aria-label": "New chat",
|
|
2837
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "compose", size: 18, label: null })
|
|
2838
|
+
}
|
|
2839
|
+
),
|
|
2840
|
+
/* @__PURE__ */ jsx(
|
|
2841
|
+
"button",
|
|
2842
|
+
{
|
|
2843
|
+
type: "button",
|
|
2844
|
+
className: "poolse-icon-btn",
|
|
2845
|
+
onClick: () => setGroupPickerOpen(true),
|
|
2846
|
+
"aria-label": "New group",
|
|
2847
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "users", size: 18, label: null })
|
|
2848
|
+
}
|
|
2849
|
+
)
|
|
2850
|
+
] }) : null,
|
|
2851
|
+
renderRightAction?.()
|
|
2852
|
+
] })
|
|
2853
|
+
] }),
|
|
2854
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-inbox__list-scroll", children: /* @__PURE__ */ jsx(
|
|
2855
|
+
ConversationList,
|
|
2856
|
+
{
|
|
2857
|
+
selectedId: activeId ?? null,
|
|
2858
|
+
onSelect: (c) => setActiveId(c.id),
|
|
2859
|
+
conversations,
|
|
2860
|
+
unreadCounts,
|
|
2861
|
+
...labelFor ? { labelFor } : {},
|
|
2862
|
+
...avatarFor ? { avatarFor } : {},
|
|
2863
|
+
...renderRow ? { renderItem: renderRow } : {},
|
|
2864
|
+
...emptyState !== void 0 ? { emptyState } : {}
|
|
2865
|
+
}
|
|
2866
|
+
) })
|
|
2867
|
+
] }),
|
|
2868
|
+
/* @__PURE__ */ jsx("section", { className: "poolse-inbox__detail-pane", children: activeId ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2869
|
+
/* @__PURE__ */ jsx(
|
|
2870
|
+
ChatHeader,
|
|
2871
|
+
{
|
|
2872
|
+
conversationId: activeId,
|
|
2873
|
+
onBack: () => setActiveId(null),
|
|
2874
|
+
...labelFor ? { labelFor } : {},
|
|
2875
|
+
...avatarFor ? { avatarFor } : {},
|
|
2876
|
+
...isGroup ? { onMembersPress: () => setGroupDetailsOpen(true) } : {}
|
|
2877
|
+
}
|
|
2878
|
+
),
|
|
2879
|
+
/* @__PURE__ */ jsx(
|
|
2880
|
+
ConversationView,
|
|
2881
|
+
{
|
|
2882
|
+
conversationId: activeId,
|
|
2883
|
+
...labelFor ? { labelFor } : {}
|
|
2884
|
+
},
|
|
2885
|
+
activeId
|
|
2886
|
+
)
|
|
2887
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "poolse-inbox__detail-empty", children: [
|
|
2888
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 32, label: null }),
|
|
2889
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-inbox__detail-empty-title", children: "Pick a conversation" })
|
|
2890
|
+
] }) }),
|
|
2891
|
+
users ? /* @__PURE__ */ jsx(
|
|
2892
|
+
UserPickerSheet,
|
|
2893
|
+
{
|
|
2894
|
+
visible: userPickerOpen,
|
|
2895
|
+
onClose: () => setUserPickerOpen(false),
|
|
2896
|
+
users,
|
|
2897
|
+
excludeIds: meExternalId ? [meExternalId] : [],
|
|
2898
|
+
mode: "single",
|
|
2899
|
+
onPickDirect: (externalId) => {
|
|
2900
|
+
void openDirect(externalId);
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
) : null,
|
|
2904
|
+
users ? /* @__PURE__ */ jsx(
|
|
2905
|
+
UserPickerSheet,
|
|
2906
|
+
{
|
|
2907
|
+
visible: groupPickerOpen,
|
|
2908
|
+
onClose: () => setGroupPickerOpen(false),
|
|
2909
|
+
users,
|
|
2910
|
+
excludeIds: meExternalId ? [meExternalId] : [],
|
|
2911
|
+
mode: "group",
|
|
2912
|
+
onCreateGroup: (name, ids) => {
|
|
2913
|
+
void openGroup(name, ids);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
) : null,
|
|
2917
|
+
activeId && isGroup ? /* @__PURE__ */ jsx(
|
|
2918
|
+
GroupDetailsSheet,
|
|
2919
|
+
{
|
|
2920
|
+
visible: groupDetailsOpen,
|
|
2921
|
+
onClose: () => setGroupDetailsOpen(false),
|
|
2922
|
+
conversationId: activeId,
|
|
2923
|
+
...labelFor ? { labelFor } : {},
|
|
2924
|
+
...avatarFor ? { avatarFor } : {}
|
|
2925
|
+
}
|
|
2926
|
+
) : null
|
|
2927
|
+
] });
|
|
2928
|
+
});
|
|
2482
2929
|
var MARK_PATHS = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2483
2930
|
/* @__PURE__ */ jsx(
|
|
2484
2931
|
"path",
|
|
@@ -2587,6 +3034,6 @@ function PoolseLogo({
|
|
|
2587
3034
|
);
|
|
2588
3035
|
}
|
|
2589
3036
|
|
|
2590
|
-
export { AttachmentPreview, Avatar, ConversationList, ConversationView, EditableMessageBubble, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, useDisplayName, usePoolseFonts };
|
|
3037
|
+
export { AttachmentPreview, Avatar, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts };
|
|
2591
3038
|
//# sourceMappingURL=index.js.map
|
|
2592
3039
|
//# sourceMappingURL=index.js.map
|