@tiledev/sdk-shopify 0.2.6 → 0.2.7
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.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/useCollectionProducts.d.ts +43 -0
- package/dist/react/useCollectionProducts.d.ts.map +1 -0
- package/dist/react/useCollectionProducts.js +151 -0
- package/dist/react/useCollectionProducts.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export { classifyAuthFailure, isOutOfStockError, isUserErrorRejection, userError
|
|
|
7
7
|
export { TileCreditClient, configureTileCredit, getTileCreditClient, redeemAndApplyToCart, centsToMoney, moneyToCents, } from './tileCredit';
|
|
8
8
|
export { TileCreditError } from './types';
|
|
9
9
|
export type * from './types';
|
|
10
|
-
export { ShopifyProvider, useShopify, useCart, useWishlist, useCustomer, useCheckout, useShopifyMessage, useTileCredit, type ShopifyProviderProps, type ShopifyEvent, type ShopifyEventType, type CartState, type WishlistState, type CustomerState, type CheckoutState, type UseTileCreditOptions, type UseTileCreditState, } from './react';
|
|
10
|
+
export { ShopifyProvider, useShopify, useCart, useWishlist, useCustomer, useCheckout, useShopifyMessage, useTileCredit, useCollectionProducts, COLLECTION_PAGE_SIZE, type ShopifyProviderProps, type ShopifyEvent, type ShopifyEventType, type CartState, type WishlistState, type CustomerState, type CheckoutState, type UseTileCreditOptions, type UseTileCreditState, type CollectionSort, type UseCollectionProductsOptions, type CollectionProductsState, type UseCollectionProductsResult, } from './react';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,mBAAmB,SAAS,CAAC;AAO7B,OAAO,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,mBAAmB,SAAS,CAAC;AAO7B,OAAO,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTileCredit = exports.useShopifyMessage = exports.useCheckout = exports.useCustomer = exports.useWishlist = exports.useCart = exports.useShopify = exports.ShopifyProvider = exports.TileCreditError = exports.moneyToCents = exports.centsToMoney = exports.redeemAndApplyToCart = exports.getTileCreditClient = exports.configureTileCredit = exports.TileCreditClient = exports.userErrorsOf = exports.isUserErrorRejection = exports.isOutOfStockError = exports.classifyAuthFailure = exports.wouldExceedLineLimit = exports.projectedLineCount = exports.maxLineItems = exports.getCartPolicy = exports.setCartPolicy = exports.limitExceededMessage = exports.setMessageResolver = exports.patchMessages = exports.setMessages = exports.getMessages = exports.message = exports.DEFAULT_MESSAGES = exports.getCurrencyCode = exports.getMoneyFormat = exports.shop = exports.applyMoneyFormat = exports.formatMoney = exports.default = exports.shopify = void 0;
|
|
3
|
+
exports.COLLECTION_PAGE_SIZE = exports.useCollectionProducts = exports.useTileCredit = exports.useShopifyMessage = exports.useCheckout = exports.useCustomer = exports.useWishlist = exports.useCart = exports.useShopify = exports.ShopifyProvider = exports.TileCreditError = exports.moneyToCents = exports.centsToMoney = exports.redeemAndApplyToCart = exports.getTileCreditClient = exports.configureTileCredit = exports.TileCreditClient = exports.userErrorsOf = exports.isUserErrorRejection = exports.isOutOfStockError = exports.classifyAuthFailure = exports.wouldExceedLineLimit = exports.projectedLineCount = exports.maxLineItems = exports.getCartPolicy = exports.setCartPolicy = exports.limitExceededMessage = exports.setMessageResolver = exports.patchMessages = exports.setMessages = exports.getMessages = exports.message = exports.DEFAULT_MESSAGES = exports.getCurrencyCode = exports.getMoneyFormat = exports.shop = exports.applyMoneyFormat = exports.formatMoney = exports.default = exports.shopify = void 0;
|
|
4
4
|
var shopify_1 = require("./shopify");
|
|
5
5
|
Object.defineProperty(exports, "shopify", { enumerable: true, get: function () { return shopify_1.shopify; } });
|
|
6
6
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return shopify_1.shopify; } });
|
|
@@ -53,4 +53,6 @@ Object.defineProperty(exports, "useCustomer", { enumerable: true, get: function
|
|
|
53
53
|
Object.defineProperty(exports, "useCheckout", { enumerable: true, get: function () { return react_1.useCheckout; } });
|
|
54
54
|
Object.defineProperty(exports, "useShopifyMessage", { enumerable: true, get: function () { return react_1.useShopifyMessage; } });
|
|
55
55
|
Object.defineProperty(exports, "useTileCredit", { enumerable: true, get: function () { return react_1.useTileCredit; } });
|
|
56
|
+
Object.defineProperty(exports, "useCollectionProducts", { enumerable: true, get: function () { return react_1.useCollectionProducts; } });
|
|
57
|
+
Object.defineProperty(exports, "COLLECTION_PAGE_SIZE", { enumerable: true, get: function () { return react_1.COLLECTION_PAGE_SIZE; } });
|
|
56
58
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAwD;AAA/C,kGAAA,OAAO,OAAA;AAAE,kGAAA,OAAO,OAAW;AACpC,iCAA8D;AAArD,oGAAA,WAAW,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,6FAAA,IAAI,OAAA;AAC5C,mCAA2D;AAAlD,wGAAA,cAAc,OAAA;AAAE,yGAAA,eAAe,OAAA;AACxC,uCAQoB;AAPlB,4GAAA,gBAAgB,OAAA;AAChB,mGAAA,OAAO,OAAA;AACP,uGAAA,WAAW,OAAA;AACX,uGAAA,WAAW,OAAA;AACX,yGAAA,aAAa,OAAA;AACb,8GAAA,kBAAkB,OAAA;AAClB,gHAAA,oBAAoB,OAAA;AAEtB,2CAMsB;AALpB,2GAAA,aAAa,OAAA;AACb,2GAAA,aAAa,OAAA;AACb,0GAAA,YAAY,OAAA;AACZ,gHAAA,kBAAkB,OAAA;AAClB,kHAAA,oBAAoB,OAAA;AAEtB,mCAKkB;AAJhB,6GAAA,mBAAmB,OAAA;AACnB,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AACpB,sGAAA,YAAY,OAAA;AAEd,2CAOsB;AANpB,8GAAA,gBAAgB,OAAA;AAChB,iHAAA,mBAAmB,OAAA;AACnB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,0GAAA,YAAY,OAAA;A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,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,gGAAA,OAAO,OAAA;AACP,oGAAA,WAAW,OAAA;AACX,oGAAA,WAAW,OAAA;AACX,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AACjB,sGAAA,aAAa,OAAA;AACb,8GAAA,qBAAqB,OAAA;AACrB,6GAAA,oBAAoB,OAAA"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { ShopifyProvider, useShopify, useCart, useWishlist, useCustomer, useCheckout, useShopifyMessage, type ShopifyProviderProps, type ShopifyEvent, type ShopifyEventType, type CartState, type WishlistState, type CustomerState, type CheckoutState, } from "./ShopifyProvider";
|
|
2
2
|
export { useTileCredit, type UseTileCreditOptions, type UseTileCreditState, } from "./useTileCredit";
|
|
3
|
+
export { useCollectionProducts, COLLECTION_PAGE_SIZE, type CollectionSort, type UseCollectionProductsOptions, type CollectionProductsState, type UseCollectionProductsResult, } from "./useCollectionProducts";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTileCredit = exports.useShopifyMessage = exports.useCheckout = exports.useCustomer = exports.useWishlist = exports.useCart = exports.useShopify = exports.ShopifyProvider = void 0;
|
|
3
|
+
exports.COLLECTION_PAGE_SIZE = exports.useCollectionProducts = exports.useTileCredit = exports.useShopifyMessage = exports.useCheckout = exports.useCustomer = exports.useWishlist = exports.useCart = exports.useShopify = exports.ShopifyProvider = void 0;
|
|
4
4
|
var ShopifyProvider_1 = require("./ShopifyProvider");
|
|
5
5
|
Object.defineProperty(exports, "ShopifyProvider", { enumerable: true, get: function () { return ShopifyProvider_1.ShopifyProvider; } });
|
|
6
6
|
Object.defineProperty(exports, "useShopify", { enumerable: true, get: function () { return ShopifyProvider_1.useShopify; } });
|
|
@@ -11,4 +11,7 @@ Object.defineProperty(exports, "useCheckout", { enumerable: true, get: function
|
|
|
11
11
|
Object.defineProperty(exports, "useShopifyMessage", { enumerable: true, get: function () { return ShopifyProvider_1.useShopifyMessage; } });
|
|
12
12
|
var useTileCredit_1 = require("./useTileCredit");
|
|
13
13
|
Object.defineProperty(exports, "useTileCredit", { enumerable: true, get: function () { return useTileCredit_1.useTileCredit; } });
|
|
14
|
+
var useCollectionProducts_1 = require("./useCollectionProducts");
|
|
15
|
+
Object.defineProperty(exports, "useCollectionProducts", { enumerable: true, get: function () { return useCollectionProducts_1.useCollectionProducts; } });
|
|
16
|
+
Object.defineProperty(exports, "COLLECTION_PAGE_SIZE", { enumerable: true, get: function () { return useCollectionProducts_1.COLLECTION_PAGE_SIZE; } });
|
|
14
17
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":";;;AAAA,qDAe2B;AAdzB,kHAAA,eAAe,OAAA;AACf,6GAAA,UAAU,OAAA;AACV,0GAAA,OAAO,OAAA;AACP,8GAAA,WAAW,OAAA;AACX,8GAAA,WAAW,OAAA;AACX,8GAAA,WAAW,OAAA;AACX,oHAAA,iBAAiB,OAAA;AASnB,iDAIyB;AAHvB,8GAAA,aAAa,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":";;;AAAA,qDAe2B;AAdzB,kHAAA,eAAe,OAAA;AACf,6GAAA,UAAU,OAAA;AACV,0GAAA,OAAO,OAAA;AACP,8GAAA,WAAW,OAAA;AACX,8GAAA,WAAW,OAAA;AACX,8GAAA,WAAW,OAAA;AACX,oHAAA,iBAAiB,OAAA;AASnB,iDAIyB;AAHvB,8GAAA,aAAa,OAAA;AAIf,iEAOiC;AAN/B,8HAAA,qBAAqB,OAAA;AACrB,6HAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Filter, Product, ProductFilter } from '../types';
|
|
2
|
+
/** How a collection is ordered. `key` is a Storefront `ProductCollectionSortKeys` value. */
|
|
3
|
+
export interface CollectionSort {
|
|
4
|
+
key: string;
|
|
5
|
+
reverse?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Default page size — 12 is six rows of two, a full first screenful on a phone. */
|
|
8
|
+
export declare const COLLECTION_PAGE_SIZE = 12;
|
|
9
|
+
export interface UseCollectionProductsOptions {
|
|
10
|
+
handle: string | null | undefined;
|
|
11
|
+
/** Storefront sort. Omit for the merchant's own collection order. */
|
|
12
|
+
sort?: CollectionSort;
|
|
13
|
+
/** Shopify's own product filters — a `FilterValue.input` parsed and handed back, never hand-built. */
|
|
14
|
+
filters?: ProductFilter[];
|
|
15
|
+
pageSize?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Called with any transport error (first page or paging) so the host app can log it — the hook has
|
|
18
|
+
* no logger of its own. Optional; when omitted the error only surfaces as `error` / a stopped feed.
|
|
19
|
+
*/
|
|
20
|
+
onError?: (error: unknown, context: {
|
|
21
|
+
at: string;
|
|
22
|
+
handle: string;
|
|
23
|
+
}) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface CollectionProductsState {
|
|
26
|
+
products: Product[];
|
|
27
|
+
/** Null until the first read resolves, so a screen can render its own heading first. */
|
|
28
|
+
title: string | null;
|
|
29
|
+
/** The facets Shopify offers for this collection under the current filters. */
|
|
30
|
+
availableFilters: Filter[];
|
|
31
|
+
/** A first page is in flight: the grid has nothing to show yet. */
|
|
32
|
+
loading: boolean;
|
|
33
|
+
/** A later page is in flight: the grid keeps what it has and shows a footer spinner. */
|
|
34
|
+
loadingMore: boolean;
|
|
35
|
+
hasMore: boolean;
|
|
36
|
+
error: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface UseCollectionProductsResult extends CollectionProductsState {
|
|
39
|
+
loadMore: () => void;
|
|
40
|
+
retry: () => void;
|
|
41
|
+
}
|
|
42
|
+
export declare function useCollectionProducts({ handle, sort, filters, pageSize, onError, }: UseCollectionProductsOptions): UseCollectionProductsResult;
|
|
43
|
+
//# sourceMappingURL=useCollectionProducts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCollectionProducts.d.ts","sourceRoot":"","sources":["../../src/react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B,GAAG,2BAA2B,CAwH5D"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COLLECTION_PAGE_SIZE = void 0;
|
|
4
|
+
exports.useCollectionProducts = useCollectionProducts;
|
|
5
|
+
/**
|
|
6
|
+
* useCollectionProducts — one collection's products, cursor-paginated.
|
|
7
|
+
*
|
|
8
|
+
* Pages on a cursor (`after: endCursor`) and APPENDS, rather than growing `first` and refetching the
|
|
9
|
+
* whole list each step. Growing `first` breaks on large collections: the Storefront API rejects
|
|
10
|
+
* `first > 250`, so a shopper scrolling deep eventually sends an over-cap request that errors — and a
|
|
11
|
+
* screen that replaces its grid on that error destroys everything already loaded, with a retry that
|
|
12
|
+
* re-sends the same failing request. Cursor paging has no such cap, never re-downloads earlier pages,
|
|
13
|
+
* and — because `loadMore` failing only stops growth — leaves the loaded products in place.
|
|
14
|
+
*
|
|
15
|
+
* Every response is checked against the request that is current (`requestId`), so a page resolving
|
|
16
|
+
* after the sort or filters changed cannot merge into the new list.
|
|
17
|
+
*/
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
const shopify_1 = require("../shopify");
|
|
20
|
+
const ShopifyProvider_1 = require("./ShopifyProvider");
|
|
21
|
+
/** Default page size — 12 is six rows of two, a full first screenful on a phone. */
|
|
22
|
+
exports.COLLECTION_PAGE_SIZE = 12;
|
|
23
|
+
const IDLE = {
|
|
24
|
+
products: [],
|
|
25
|
+
title: null,
|
|
26
|
+
availableFilters: [],
|
|
27
|
+
loading: false,
|
|
28
|
+
loadingMore: false,
|
|
29
|
+
hasMore: false,
|
|
30
|
+
error: false,
|
|
31
|
+
};
|
|
32
|
+
function useCollectionProducts({ handle, sort, filters, pageSize = exports.COLLECTION_PAGE_SIZE, onError, }) {
|
|
33
|
+
const { ready } = (0, ShopifyProvider_1.useShopify)();
|
|
34
|
+
const [state, setState] = (0, react_1.useState)(IDLE);
|
|
35
|
+
const [attempt, setAttempt] = (0, react_1.useState)(0);
|
|
36
|
+
/**
|
|
37
|
+
* Identifies the request the state belongs to. Bumped on every fresh read; an append carries the
|
|
38
|
+
* value it started with, so a response whose counter has moved on is dropped rather than merged.
|
|
39
|
+
*/
|
|
40
|
+
const requestId = (0, react_1.useRef)(0);
|
|
41
|
+
/** The cursor for the next page, held in a ref so `loadMore` does not need a fresh callback. */
|
|
42
|
+
const cursor = (0, react_1.useRef)(null);
|
|
43
|
+
/**
|
|
44
|
+
* The filter array and sort object are rebuilt on every render of the screen that owns them, so the
|
|
45
|
+
* effect depends on their serialisation rather than their identity — otherwise every keystroke
|
|
46
|
+
* elsewhere on the screen would refetch.
|
|
47
|
+
*/
|
|
48
|
+
const filterKey = (filters === null || filters === void 0 ? void 0 : filters.length) ? JSON.stringify(filters) : '';
|
|
49
|
+
const sortKey = sort ? `${sort.key}:${sort.reverse ? 'desc' : 'asc'}` : '';
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
var _a;
|
|
52
|
+
// A client that is not up yet, or no handle to read, is not a failed load — it is no load.
|
|
53
|
+
if (!ready || !handle) {
|
|
54
|
+
requestId.current += 1;
|
|
55
|
+
cursor.current = null;
|
|
56
|
+
setState(IDLE);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const id = (requestId.current += 1);
|
|
60
|
+
cursor.current = null;
|
|
61
|
+
setState({ ...IDLE, loading: true });
|
|
62
|
+
shopify_1.shopify.collections
|
|
63
|
+
.products(handle, {
|
|
64
|
+
first: pageSize,
|
|
65
|
+
sortKey: sort === null || sort === void 0 ? void 0 : sort.key,
|
|
66
|
+
reverse: (_a = sort === null || sort === void 0 ? void 0 : sort.reverse) !== null && _a !== void 0 ? _a : false,
|
|
67
|
+
filters: (filters === null || filters === void 0 ? void 0 : filters.length) ? filters : undefined,
|
|
68
|
+
})
|
|
69
|
+
.then((page) => {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
if (requestId.current !== id)
|
|
72
|
+
return;
|
|
73
|
+
cursor.current = page.pageInfo.endCursor;
|
|
74
|
+
setState({
|
|
75
|
+
products: page.nodes,
|
|
76
|
+
title: (_b = (_a = page.collection) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : null,
|
|
77
|
+
availableFilters: (_c = page.filters) !== null && _c !== void 0 ? _c : [],
|
|
78
|
+
loading: false,
|
|
79
|
+
loadingMore: false,
|
|
80
|
+
hasMore: page.pageInfo.hasNextPage,
|
|
81
|
+
error: false,
|
|
82
|
+
});
|
|
83
|
+
})
|
|
84
|
+
.catch((caught) => {
|
|
85
|
+
onError === null || onError === void 0 ? void 0 : onError(caught, { at: 'useCollectionProducts', handle });
|
|
86
|
+
if (requestId.current !== id)
|
|
87
|
+
return;
|
|
88
|
+
// A first-page failure genuinely has nothing to show, so the consumer renders its error state.
|
|
89
|
+
setState({ ...IDLE, error: true });
|
|
90
|
+
});
|
|
91
|
+
// Keyed on the serialised filters and sort; both change identity every render.
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
}, [ready, handle, sortKey, filterKey, pageSize, attempt]);
|
|
94
|
+
/**
|
|
95
|
+
* Guarded on both in-flight flags as well as on `hasMore`: a list's `onEndReached` fires every
|
|
96
|
+
* time the end stays in view, so an ungated version would run through the collection a page a frame.
|
|
97
|
+
*/
|
|
98
|
+
const loadMore = (0, react_1.useCallback)(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
if (state.loading || state.loadingMore || !state.hasMore || !cursor.current)
|
|
101
|
+
return;
|
|
102
|
+
const id = requestId.current;
|
|
103
|
+
const after = cursor.current;
|
|
104
|
+
// Claim the cursor synchronously. `onEndReached` fires repeatedly and the `loadingMore` guard
|
|
105
|
+
// reads a `state` snapshot that is stale until the next render, so a second call in the same frame
|
|
106
|
+
// would otherwise fetch this SAME page again and append it twice — duplicate keys. Nulling the ref
|
|
107
|
+
// now makes the re-entrant call bail on `!cursor.current`; the fetch restores it, a failure leaves
|
|
108
|
+
// it null (paging has stopped anyway).
|
|
109
|
+
cursor.current = null;
|
|
110
|
+
setState((current) => ({ ...current, loadingMore: true }));
|
|
111
|
+
shopify_1.shopify.collections
|
|
112
|
+
.products(handle, {
|
|
113
|
+
first: pageSize,
|
|
114
|
+
after,
|
|
115
|
+
sortKey: sort === null || sort === void 0 ? void 0 : sort.key,
|
|
116
|
+
reverse: (_a = sort === null || sort === void 0 ? void 0 : sort.reverse) !== null && _a !== void 0 ? _a : false,
|
|
117
|
+
filters: (filters === null || filters === void 0 ? void 0 : filters.length) ? filters : undefined,
|
|
118
|
+
})
|
|
119
|
+
.then((page) => {
|
|
120
|
+
if (requestId.current !== id)
|
|
121
|
+
return;
|
|
122
|
+
cursor.current = page.pageInfo.endCursor;
|
|
123
|
+
setState((current) => {
|
|
124
|
+
// Defensive against any overlap between pages: never append a product already held.
|
|
125
|
+
const seen = new Set(current.products.map((p) => p.id));
|
|
126
|
+
const fresh = page.nodes.filter((p) => !seen.has(p.id));
|
|
127
|
+
return {
|
|
128
|
+
...current,
|
|
129
|
+
products: fresh.length ? [...current.products, ...fresh] : current.products,
|
|
130
|
+
loadingMore: false,
|
|
131
|
+
hasMore: page.pageInfo.hasNextPage,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
})
|
|
135
|
+
.catch((caught) => {
|
|
136
|
+
onError === null || onError === void 0 ? void 0 : onError(caught, { at: 'useCollectionProducts.loadMore', handle: handle });
|
|
137
|
+
if (requestId.current !== id)
|
|
138
|
+
return;
|
|
139
|
+
// A failed page is not a failed collection: what is on screen stays, and the end simply stops
|
|
140
|
+
// growing rather than the grid being replaced by an error.
|
|
141
|
+
setState((current) => ({ ...current, loadingMore: false, hasMore: false }));
|
|
142
|
+
});
|
|
143
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
144
|
+
}, [state.loading, state.loadingMore, state.hasMore, handle, sortKey, filterKey, pageSize]);
|
|
145
|
+
return {
|
|
146
|
+
...state,
|
|
147
|
+
loadMore,
|
|
148
|
+
retry: () => setAttempt((n) => n + 1),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=useCollectionProducts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCollectionProducts.js","sourceRoot":"","sources":["../../src/react/useCollectionProducts.ts"],"names":[],"mappings":";;;AAsEA,sDA8HC;AApMD;;;;;;;;;;;;GAYG;AACH,iCAAiE;AACjE,wCAAqC;AACrC,uDAA+C;AAS/C,oFAAoF;AACvE,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAmCvC,MAAM,IAAI,GAA4B;IACpC,QAAQ,EAAE,EAAE;IACZ,KAAK,EAAE,IAAI;IACX,gBAAgB,EAAE,EAAE;IACpB,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,SAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,IAAI,EACJ,OAAO,EACP,QAAQ,GAAG,4BAAoB,EAC/B,OAAO,GACsB;IAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,4BAAU,GAAE,CAAC;IAE/B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAA0B,IAAI,CAAC,CAAC;IAClE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IAE1C;;;OAGG;IACH,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,CAAC,CAAC,CAAC;IAC5B,gGAAgG;IAChG,MAAM,MAAM,GAAG,IAAA,cAAM,EAAgB,IAAI,CAAC,CAAC;IAE3C;;;;OAIG;IACH,MAAM,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,C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AC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,MAAM,EAAE,EAAE,EAAE,EAAE,gCAAgC,EAAE,MAAM,EAAE,MAAgB,EAAE,CAAC,CAAC;YACtF,IAAI,SAAS,CAAC,OAAO,KAAK,EAAE;gBAAE,OAAO;YACrC,8FAA8F;YAC9F,2DAA2D;YAC3D,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9E,CAAC,CAAC,CAAC;QACL,uDAAuD;IACzD,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE5F,OAAO;QACL,GAAG,KAAK;QACR,QAAQ;QACR,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;KACtC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledev/sdk-shopify",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Type-safe Shopify Storefront API client for React Native (web, iOS, Android). Products, collections, cart, customer session, blogs, a local-storage-backed wishlist, and configurable shopper alerts. Zero deps beyond fetch.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|