@atomic-solutions/woocommerce-react 0.6.2 → 0.7.0

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.
@@ -42,6 +42,8 @@ var StaleTimes = {
42
42
  product: STALE_TIME_SHORT,
43
43
  /** Product categories - always fresh */
44
44
  categories: STALE_TIME_NONE,
45
+ /** Product tags - names rarely change, 1 hour */
46
+ tags: STALE_TIME_LONG,
45
47
  /** Orders - always fresh */
46
48
  orders: STALE_TIME_NONE,
47
49
  /** Default for infinite queries - 1 hour */
@@ -139,6 +141,16 @@ var processCategoriesToTree = (data) => {
139
141
  });
140
142
  return rootCategories?.map(processCategory) ?? [];
141
143
  };
144
+ var useProductTags = (params, options) => {
145
+ const client = useWooCommerceClient();
146
+ const queryKeys = useWooCommerceQueryKeys();
147
+ return reactQuery.useQuery({
148
+ queryKey: queryKeys.products.tags(params),
149
+ queryFn: () => client.products.tags(params),
150
+ staleTime: StaleTimes.tags,
151
+ ...options
152
+ });
153
+ };
142
154
  var useProductCategoryTree = () => {
143
155
  const query = useProductCategories();
144
156
  const flatData = query.data ?? [];
@@ -463,7 +475,9 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
463
475
  list: (params) => [...prefix, "products", "list", params],
464
476
  details: () => [...prefix, "products", "detail"],
465
477
  detail: (id) => [...prefix, "products", "detail", id],
466
- categories: () => [...prefix, "products", "categories"]
478
+ categories: () => [...prefix, "products", "categories"],
479
+ // Params are in the key, so each set of tag ids is cached apart.
480
+ tags: (params) => [...prefix, "products", "tags", params]
467
481
  },
468
482
  // Cart
469
483
  cart: {
@@ -1224,6 +1238,8 @@ function useOrderView(input, options = {}) {
1224
1238
  const storeContext = react.useContext(WooCommerceStoreContext);
1225
1239
  const storeConfig = storeContext?.config;
1226
1240
  const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
1241
+ const { imageSize = "thumbnail" } = options;
1242
+ const getProcessedImageUrl = useProcessedImageUrl(imageSize, options.fallbackImageUrl);
1227
1243
  const { data: rawOrder, isLoading, error } = useOrder(input);
1228
1244
  const order = react.useMemo(() => {
1229
1245
  if (!rawOrder) return void 0;
@@ -1234,7 +1250,7 @@ function useOrderView(input, options = {}) {
1234
1250
  quantity: item.quantity,
1235
1251
  price: formatStoreApiPriceIntl(item.prices.price, currencyCode, localeTag),
1236
1252
  total: formatStoreApiPriceIntl(item.totals.line_total, currencyCode, localeTag),
1237
- imageUrl: item.images?.[0]?.src
1253
+ imageUrl: getProcessedImageUrl(item.images)
1238
1254
  }));
1239
1255
  const status = rawOrder.status;
1240
1256
  return {
@@ -1249,7 +1265,7 @@ function useOrderView(input, options = {}) {
1249
1265
  paymentMethod: rawOrder.payment_method ?? "",
1250
1266
  raw: rawOrder
1251
1267
  };
1252
- }, [rawOrder, localeTag]);
1268
+ }, [rawOrder, localeTag, getProcessedImageUrl]);
1253
1269
  return {
1254
1270
  order,
1255
1271
  isLoading,
@@ -1272,6 +1288,7 @@ exports.useProcessCheckout = useProcessCheckout;
1272
1288
  exports.useProduct = useProduct;
1273
1289
  exports.useProductCategories = useProductCategories;
1274
1290
  exports.useProductCategoryTree = useProductCategoryTree;
1291
+ exports.useProductTags = useProductTags;
1275
1292
  exports.useProductView = useProductView;
1276
1293
  exports.useProducts = useProducts;
1277
1294
  exports.useProductsFeed = useProductsFeed;