@tapcart/mobile-components 0.8.65 → 0.8.66

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.
@@ -1 +1 @@
1
- {"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAK1C,KAAK,GAAG,GAAG,MAAM,CAAA;AACjB,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AACxD,KAAK,gBAAgB,GAAG;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IACjC,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,OAAO,EAAE,GAAG,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1E,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AACD,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;IACrB,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,KAC3B;QACE,EAAE,EAAE,MAAM,CAAA;QACV,M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,CAAA;QACV,MAAM,EAAE,MAAM,CAAA;KACf,GACD,SAAS,CAAA;CACd,CAAA;AAgCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,CAuJ7E"}
@@ -39,6 +39,7 @@ export function useProducts(props) {
39
39
  productIds: props === null || props === void 0 ? void 0 : props.productIds,
40
40
  productHandles: props === null || props === void 0 ? void 0 : props.productHandles,
41
41
  }));
42
+ const [isProductResponseReady, setIsProductResponseReady] = React.useState((productResponse === null || productResponse === void 0 ? void 0 : productResponse.length) > 0);
42
43
  if (isUseProductsProps(props)) {
43
44
  let { baseURL, productIds, variantIds, productHandles, metafields, collection, queryVariables, } = props;
44
45
  if (shouldMockProducts) {
@@ -109,23 +110,29 @@ export function useProducts(props) {
109
110
  const cachedProduct = productsLocalStorage.setCacheItem(product);
110
111
  return cachedProduct;
111
112
  };
112
- // set local state when when SWR data is updated
113
+ /**
114
+ * Sync local state with incoming swr response data.
115
+ * If the response contains a `products` envelope, it will be extracted.
116
+ */
113
117
  React.useEffect(() => {
114
- if (!data)
118
+ if (isLoading) {
115
119
  return;
116
- // Determine the products array from data
117
- const productsArray = Array.isArray(data) ? data : data.products || [];
118
- if (!(productsArray === null || productsArray === void 0 ? void 0 : productsArray.length))
119
- return;
120
- setProductResponse(productsArray);
121
- }, [data]);
120
+ }
121
+ if (data) {
122
+ const productsArray = Array.isArray(data) ? data : data.products || [];
123
+ if (productsArray.length > 0) {
124
+ setProductResponse(productsArray);
125
+ }
126
+ }
127
+ setIsProductResponseReady(true);
128
+ }, [isLoading, data]);
122
129
  return {
123
130
  products: formatProductData({
124
131
  data: productResponse,
125
132
  onlyAvailableProducts: (props === null || props === void 0 ? void 0 : props.mock) && (props === null || props === void 0 ? void 0 : props.onlyAvailableProducts),
126
133
  }),
127
134
  error,
128
- isLoading: !(productResponse === null || productResponse === void 0 ? void 0 : productResponse.length) && isLoading,
135
+ isLoading: !isProductResponseReady,
129
136
  isRefreshing: isLoading,
130
137
  cacheProduct,
131
138
  };
@@ -1,5 +1,7 @@
1
- import { Collection, Product } from "app-studio-types";
1
+ import { Collection, Product, BaseSearchClient } from "app-studio-types";
2
2
  interface UseRecommendationProps {
3
+ searchClient?: BaseSearchClient<Product>;
4
+ query?: string;
3
5
  queryVariables: Record<string, any>;
4
6
  apiURL: string;
5
7
  }
@@ -10,6 +12,6 @@ interface UseRecommendationReturn {
10
12
  isLoading: boolean;
11
13
  error: any;
12
14
  }
13
- declare const useRecommendations: ({ queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
15
+ declare const useRecommendations: ({ searchClient, query, queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
14
16
  export { useRecommendations };
15
17
  //# sourceMappingURL=use-recommendations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAOtD,UAAU,sBAAsB;IAC9B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AASD,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,GAAG,CAAA;CACX;AAiBD,QAAA,MAAM,kBAAkB,gCAGrB,sBAAsB,KAAG,uBA6D3B,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
1
+ {"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxE,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IAGd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AASD,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,GAAG,CAAA;CACX;AAiBD,QAAA,MAAM,kBAAkB,qDAQrB,sBAAsB,KAAG,uBA6F3B,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
@@ -22,13 +22,33 @@ const getCollections = (collections) => {
22
22
  : [];
23
23
  };
24
24
  const recommendationsLocalStorage = new RecommendationsLocalStorage();
25
- const useRecommendations = ({ queryVariables, apiURL, }) => {
25
+ const useRecommendations = ({
26
+ // Search client props
27
+ searchClient, query = "",
28
+ // API props (backwards compatibility)
29
+ queryVariables, apiURL, }) => {
30
+ // When searchClient is provided, use search client approach
31
+ const usingSearchClient = Boolean(searchClient);
26
32
  const searchParams = useSearchParams();
27
- const recommendation = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("recommendation")) || "";
33
+ const recommendation = usingSearchClient
34
+ ? query
35
+ : (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("recommendation")) || "";
28
36
  const [cachedRecommendation, setCachedRecommendations] = React.useState(recommendationsLocalStorage.getCacheItem({
29
37
  id: `${recommendation}-${queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language}`,
30
38
  }));
31
- const fetcher = (body) => fetch(constructURL(apiURL), {
39
+ // Search client fetcher
40
+ const searchClientFetcher = () => __awaiter(void 0, void 0, void 0, function* () {
41
+ if (!searchClient)
42
+ return null;
43
+ // Call searchClient.getRecommendations (returns string[] directly)
44
+ const recommendations = yield searchClient.getRecommendations({
45
+ query: recommendation,
46
+ });
47
+ // Format as expected by the hook
48
+ return Object.assign(Object.assign({}, recommendations), { collections: [] });
49
+ });
50
+ // API fetcher (backwards compatibility)
51
+ const apiFetcher = (body) => fetch(constructURL(apiURL), {
32
52
  method: "POST",
33
53
  body: JSON.stringify(body),
34
54
  }).then((res) => __awaiter(void 0, void 0, void 0, function* () {
@@ -38,11 +58,20 @@ const useRecommendations = ({ queryVariables, apiURL, }) => {
38
58
  }
39
59
  return data;
40
60
  }));
41
- const { data, error, isLoading } = useSWR({
42
- appId: queryVariables.appId,
43
- query: recommendation,
44
- language: queryVariables.language,
45
- }, fetcher, {
61
+ // Determine which approach to use
62
+ const swrKey = usingSearchClient
63
+ ? {
64
+ type: "searchClient",
65
+ query: recommendation,
66
+ language: queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language,
67
+ }
68
+ : {
69
+ appId: queryVariables.appId,
70
+ query: recommendation,
71
+ language: queryVariables.language,
72
+ };
73
+ const fetcher = usingSearchClient ? searchClientFetcher : apiFetcher;
74
+ const { data, error, isLoading } = useSWR(swrKey, usingSearchClient ? fetcher : (body) => apiFetcher(body), {
46
75
  revalidateOnFocus: false,
47
76
  revalidateOnReconnect: false,
48
77
  });
package/dist/styles.css CHANGED
@@ -2630,10 +2630,6 @@ body::-webkit-scrollbar {
2630
2630
  background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
2631
2631
  }
2632
2632
 
2633
- .hover\:no-underline:hover {
2634
- text-decoration-line: none;
2635
- }
2636
-
2637
2633
  .hover\:opacity-90:hover {
2638
2634
  opacity: 0.9;
2639
2635
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.8.65",
3
+ "version": "0.8.66",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",