vdb-ai-chat 1.0.4 → 1.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/chat-widget.js +1 -1
- package/lib/commonjs/api.js +19 -4
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/components/ChatWidget.js +26 -7
- package/lib/commonjs/components/ChatWidget.js.map +1 -1
- package/lib/commonjs/components/LazyProductsFetcher.js +3 -2
- package/lib/commonjs/components/LazyProductsFetcher.js.map +1 -1
- package/lib/commonjs/components/utils.js +38 -2
- package/lib/commonjs/components/utils.js.map +1 -1
- package/lib/commonjs/storage.js +13 -0
- package/lib/commonjs/storage.js.map +1 -1
- package/lib/module/api.js +19 -4
- package/lib/module/api.js.map +1 -1
- package/lib/module/components/ChatWidget.js +27 -8
- package/lib/module/components/ChatWidget.js.map +1 -1
- package/lib/module/components/LazyProductsFetcher.js +3 -2
- package/lib/module/components/LazyProductsFetcher.js.map +1 -1
- package/lib/module/components/utils.js +34 -0
- package/lib/module/components/utils.js.map +1 -1
- package/lib/module/storage.js +13 -0
- package/lib/module/storage.js.map +1 -1
- package/lib/typescript/api.d.ts +1 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/components/ChatWidget.d.ts.map +1 -1
- package/lib/typescript/components/LazyProductsFetcher.d.ts +1 -0
- package/lib/typescript/components/LazyProductsFetcher.d.ts.map +1 -1
- package/lib/typescript/components/utils.d.ts +9 -0
- package/lib/typescript/components/utils.d.ts.map +1 -1
- package/lib/typescript/storage.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/api.ts +31 -4
- package/src/components/ChatWidget.tsx +28 -6
- package/src/components/LazyProductsFetcher.tsx +3 -1
- package/src/components/utils.ts +34 -4
- package/src/storage.ts +13 -0
|
@@ -7,12 +7,14 @@ interface LazyProductsFetcherProps {
|
|
|
7
7
|
messageId: string;
|
|
8
8
|
payload: Record<string, any> | undefined | null;
|
|
9
9
|
onFetched: (messageId: string, data: any) => void;
|
|
10
|
+
priceMode: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
const LazyProductsFetcher: React.FC<LazyProductsFetcherProps> = ({
|
|
13
14
|
messageId,
|
|
14
15
|
payload,
|
|
15
16
|
onFetched,
|
|
17
|
+
priceMode,
|
|
16
18
|
}) => {
|
|
17
19
|
const { ref, inView } = useInViewport<HTMLDivElement>();
|
|
18
20
|
const fetchedRef = useRef(false);
|
|
@@ -25,7 +27,7 @@ const LazyProductsFetcher: React.FC<LazyProductsFetcherProps> = ({
|
|
|
25
27
|
fetchedRef.current = true;
|
|
26
28
|
(async () => {
|
|
27
29
|
try {
|
|
28
|
-
const result = await getProducts(payload);
|
|
30
|
+
const result = await getProducts(payload, priceMode as string);
|
|
29
31
|
onFetched(messageId, result);
|
|
30
32
|
} catch (e) {
|
|
31
33
|
// eslint-disable-next-line no-console
|
package/src/components/utils.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { Dimensions } from "react-native";
|
|
1
2
|
import { Storage } from "../storage";
|
|
3
|
+
import { useMediaQuery } from "react-responsive";
|
|
4
|
+
|
|
5
|
+
export const DEVICE_SIZE = Dimensions.get("window");
|
|
2
6
|
|
|
3
7
|
export function formatToTime(timestamp: number): string {
|
|
4
8
|
const date = new Date(timestamp);
|
|
@@ -32,10 +36,7 @@ export const fetchConversationId = async (
|
|
|
32
36
|
|
|
33
37
|
let priceMode = _priceMode;
|
|
34
38
|
if (priceMode === undefined) {
|
|
35
|
-
const userInfo = await Storage.getJSON<UserDetails>(
|
|
36
|
-
"persist:userInfo",
|
|
37
|
-
{}
|
|
38
|
-
);
|
|
39
|
+
const userInfo = await Storage.getJSON<UserDetails>("persist:userInfo", {});
|
|
39
40
|
const userData = userInfo?.user as UserDetails;
|
|
40
41
|
priceMode = String(userData?.price_mode) || "";
|
|
41
42
|
}
|
|
@@ -53,6 +54,7 @@ export interface UserDetails {
|
|
|
53
54
|
price_mode?: string | number;
|
|
54
55
|
plan_details?: any;
|
|
55
56
|
user?: any;
|
|
57
|
+
searchResultViewType?: string;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
export const getUserDetails = async (): Promise<UserDetails | null> => {
|
|
@@ -102,3 +104,31 @@ export enum AnalyticsEventNames {
|
|
|
102
104
|
WIDGET_CLOSED = "ai_chat_widget_closed",
|
|
103
105
|
CHAT_CLEARED = "ai_chat_cleared",
|
|
104
106
|
}
|
|
107
|
+
|
|
108
|
+
export const isIpad = () => {
|
|
109
|
+
// const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
110
|
+
// return (
|
|
111
|
+
// /iPad/.test(userAgent) ||
|
|
112
|
+
// (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)
|
|
113
|
+
// );
|
|
114
|
+
const userAgent =
|
|
115
|
+
navigator.userAgent || navigator.vendor || (window as any).opera;
|
|
116
|
+
return (
|
|
117
|
+
/iPad/.test(userAgent) ||
|
|
118
|
+
(/\bMac/.test(userAgent) &&
|
|
119
|
+
navigator.maxTouchPoints > 0 &&
|
|
120
|
+
!/iPhone/.test(userAgent))
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const useDeviceType = () => {
|
|
125
|
+
const { width } = DEVICE_SIZE;
|
|
126
|
+
const isMobile = useMediaQuery({ maxWidth: 767 }) || width < 767;
|
|
127
|
+
const isTablet =
|
|
128
|
+
useMediaQuery({ minWidth: 767, maxWidth: 1279 }) ||
|
|
129
|
+
(width > 767 && width <= 1279) ||
|
|
130
|
+
isIpad();
|
|
131
|
+
const isDesktop = useMediaQuery({ minWidth: 1279 }) || width > 1279;
|
|
132
|
+
const isLargeScreen = isDesktop && !isTablet && !isMobile;
|
|
133
|
+
return { isMobile, isTablet, isDesktop, isLargeScreen };
|
|
134
|
+
};
|
package/src/storage.ts
CHANGED
|
@@ -15,10 +15,23 @@ function getLocalStorage(): Storage | null {
|
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// Helper to safely get sessionStorage (only available on web)
|
|
19
|
+
function getSessionStorage(): Storage | null {
|
|
20
|
+
if (typeof window !== "undefined" && window.sessionStorage) {
|
|
21
|
+
return window.sessionStorage;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
// Web storage implementation using localStorage (lazy access)
|
|
19
27
|
const webStorage: StorageInterface = {
|
|
20
28
|
getItem: async (key: string) => {
|
|
21
29
|
try {
|
|
30
|
+
// Use sessionStorage for persist:searchFilters key
|
|
31
|
+
if (key === "persist:searchFilters") {
|
|
32
|
+
const sessionStore = getSessionStorage();
|
|
33
|
+
return sessionStore ? sessionStore.getItem(key) : null;
|
|
34
|
+
}
|
|
22
35
|
const storage = getLocalStorage();
|
|
23
36
|
return storage ? storage.getItem(key) : null;
|
|
24
37
|
} catch {
|