@baseportal/chat-widget 0.1.0 → 0.1.1
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.js +38 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +39 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +6 -6
- package/dist/index.iife.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -303,7 +303,7 @@ function ChatBubble({
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
// src/ui/components/ChatWindow.tsx
|
|
306
|
-
import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "preact/hooks";
|
|
306
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "preact/hooks";
|
|
307
307
|
|
|
308
308
|
// src/ui/components/ConversationList.tsx
|
|
309
309
|
import { jsx as jsx3, jsxs as jsxs3 } from "preact/jsx-runtime";
|
|
@@ -709,6 +709,8 @@ function ChatWindow({
|
|
|
709
709
|
const [uploading, setUploading] = useState3(false);
|
|
710
710
|
const isOpen = conversation?.open !== false;
|
|
711
711
|
const allowViewHistory = channelInfo.config.allowViewHistory && isAuthenticated;
|
|
712
|
+
const startNewConversationRef = useRef3(async () => {
|
|
713
|
+
});
|
|
712
714
|
useEffect3(() => {
|
|
713
715
|
const init = async () => {
|
|
714
716
|
setLoading(true);
|
|
@@ -795,11 +797,26 @@ function ChatWindow({
|
|
|
795
797
|
);
|
|
796
798
|
if (!conv.open) {
|
|
797
799
|
events.emit("conversation:closed", conv);
|
|
800
|
+
setTimeout(() => {
|
|
801
|
+
realtimeClient.unsubscribe();
|
|
802
|
+
storage.clear();
|
|
803
|
+
setConversation(null);
|
|
804
|
+
setMessages([]);
|
|
805
|
+
if (allowViewHistory) {
|
|
806
|
+
apiClient.getVisitorConversations().then(setConversations).catch(() => {
|
|
807
|
+
});
|
|
808
|
+
setView("conversations");
|
|
809
|
+
} else if (needsPreChat()) {
|
|
810
|
+
setView("prechat");
|
|
811
|
+
} else {
|
|
812
|
+
startNewConversationRef.current();
|
|
813
|
+
}
|
|
814
|
+
}, 2e3);
|
|
798
815
|
}
|
|
799
816
|
}
|
|
800
817
|
});
|
|
801
818
|
},
|
|
802
|
-
[realtimeClient, events]
|
|
819
|
+
[realtimeClient, events, storage, allowViewHistory, apiClient, needsPreChat]
|
|
803
820
|
);
|
|
804
821
|
const openConversation = useCallback3(
|
|
805
822
|
async (conv) => {
|
|
@@ -838,6 +855,7 @@ function ChatWindow({
|
|
|
838
855
|
setLoading(false);
|
|
839
856
|
}
|
|
840
857
|
}, [apiClient, visitor, storage, connectRealtime, events]);
|
|
858
|
+
startNewConversationRef.current = startNewConversation;
|
|
841
859
|
const handlePreChatSubmit = useCallback3(
|
|
842
860
|
async (data) => {
|
|
843
861
|
storage.setVisitor({ ...visitor, ...data });
|
|
@@ -907,11 +925,28 @@ function ChatWindow({
|
|
|
907
925
|
} catch (e) {
|
|
908
926
|
console.error("[BaseportalChat] Error sending message:", e);
|
|
909
927
|
setMessages((prev) => prev.filter((m) => m.id !== tempId));
|
|
910
|
-
|
|
928
|
+
const errMsg = e instanceof Error ? e.message : "";
|
|
929
|
+
if (errMsg.includes("Row not found") || errMsg.includes("404")) {
|
|
930
|
+
realtimeClient.unsubscribe();
|
|
931
|
+
storage.clear();
|
|
932
|
+
setConversation(null);
|
|
933
|
+
setMessages([]);
|
|
934
|
+
if (allowViewHistory) {
|
|
935
|
+
apiClient.getVisitorConversations().then(setConversations).catch(() => {
|
|
936
|
+
});
|
|
937
|
+
setView("conversations");
|
|
938
|
+
} else if (needsPreChat()) {
|
|
939
|
+
setView("prechat");
|
|
940
|
+
} else {
|
|
941
|
+
await startNewConversationRef.current();
|
|
942
|
+
}
|
|
943
|
+
} else {
|
|
944
|
+
setInputValue(content);
|
|
945
|
+
}
|
|
911
946
|
} finally {
|
|
912
947
|
setSending(false);
|
|
913
948
|
}
|
|
914
|
-
}, [inputValue, uploadedFileId, conversation, sending, apiClient, events]);
|
|
949
|
+
}, [inputValue, uploadedFileId, conversation, sending, apiClient, events, realtimeClient, storage, allowViewHistory, needsPreChat]);
|
|
915
950
|
const handleReopen = useCallback3(async () => {
|
|
916
951
|
if (!conversation) return;
|
|
917
952
|
try {
|