@mordn/chat-widget 0.4.1 → 0.4.2
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.js +28 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1679,31 +1679,28 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1679
1679
|
useEffect4(() => {
|
|
1680
1680
|
if (hasInitialized.current) return;
|
|
1681
1681
|
const loadInitialTabs = () => {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
title: "New Chat",
|
|
1696
|
-
isActive: true
|
|
1697
|
-
};
|
|
1698
|
-
setTabs([currentTab]);
|
|
1699
|
-
setActiveTabId(initialTabId);
|
|
1700
|
-
setInitialTabCreated(true);
|
|
1701
|
-
}
|
|
1702
|
-
} finally {
|
|
1682
|
+
const savedTabs = localStorage.getItem(storageKey("tabs"));
|
|
1683
|
+
const savedActiveTabId = localStorage.getItem(storageKey("active-tab-id"));
|
|
1684
|
+
if (savedTabs && savedTabs !== "[]") {
|
|
1685
|
+
const parsedTabs = JSON.parse(savedTabs);
|
|
1686
|
+
setTabs(parsedTabs);
|
|
1687
|
+
const activeId = savedActiveTabId || parsedTabs[0]?.id;
|
|
1688
|
+
setActiveTabId(activeId);
|
|
1689
|
+
setInitialTabCreated(true);
|
|
1690
|
+
} else if (!initialTabCreated && tabs.length === 0) {
|
|
1691
|
+
const initialTabId = `chat-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
1692
|
+
setTabs([{ id: initialTabId, title: "New Chat", isActive: true }]);
|
|
1693
|
+
setActiveTabId(initialTabId);
|
|
1694
|
+
setInitialTabCreated(true);
|
|
1703
1695
|
setIsInitializing(false);
|
|
1704
1696
|
}
|
|
1705
1697
|
};
|
|
1706
|
-
|
|
1698
|
+
try {
|
|
1699
|
+
loadInitialTabs();
|
|
1700
|
+
} catch (err) {
|
|
1701
|
+
console.error("[chat-widget] init failed, falling back to clean start:", err);
|
|
1702
|
+
setIsInitializing(false);
|
|
1703
|
+
}
|
|
1707
1704
|
hasInitialized.current = true;
|
|
1708
1705
|
}, []);
|
|
1709
1706
|
const hasLoadedInitialMessages = useRef3(false);
|
|
@@ -1711,10 +1708,15 @@ function ChatInterface({ id, initialMessages, config, onClose, headerActions } =
|
|
|
1711
1708
|
if (hasLoadedInitialMessages.current) return;
|
|
1712
1709
|
if (!config?.userId) return;
|
|
1713
1710
|
if (!activeTabId) return;
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1711
|
+
(async () => {
|
|
1712
|
+
try {
|
|
1713
|
+
await loadConversation(activeTabId);
|
|
1714
|
+
} finally {
|
|
1715
|
+
hasLoadedInitialMessages.current = true;
|
|
1716
|
+
setIsInitializing(false);
|
|
1717
|
+
}
|
|
1718
|
+
})();
|
|
1719
|
+
}, [config?.userId, activeTabId]);
|
|
1718
1720
|
useEffect4(() => {
|
|
1719
1721
|
if (isInitializing) return;
|
|
1720
1722
|
if (activeTabId && tabs.length > 0 && activeTabId !== lastSyncedTabId.current) {
|