@diffsome/react 1.1.3 → 1.2.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.
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +86 -98
- package/dist/index.mjs +298 -310
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { Diffsome, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider,
|
|
4
|
+
import { Diffsome, Cart, WishlistItem, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
|
|
5
5
|
export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
|
|
6
6
|
|
|
7
7
|
interface DiffsomeContextValue {
|
|
8
8
|
client: Diffsome;
|
|
9
9
|
isReady: boolean;
|
|
10
|
+
cart: Cart | null;
|
|
11
|
+
cartLoading: boolean;
|
|
12
|
+
setCart: (cart: Cart | null) => void;
|
|
13
|
+
refreshCart: () => Promise<void>;
|
|
14
|
+
wishlistItems: WishlistItem[];
|
|
15
|
+
wishlistLoading: boolean;
|
|
16
|
+
setWishlistItems: (items: WishlistItem[]) => void;
|
|
17
|
+
refreshWishlist: () => Promise<void>;
|
|
10
18
|
}
|
|
11
19
|
declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
|
|
12
20
|
interface DiffsomeProviderProps {
|
|
@@ -105,7 +113,7 @@ interface UseCartReturn {
|
|
|
105
113
|
/** Full cart object with metadata */
|
|
106
114
|
cart: Cart | null;
|
|
107
115
|
/** Array of cart items */
|
|
108
|
-
items:
|
|
116
|
+
items: Cart['items'];
|
|
109
117
|
/** Number of unique items in cart */
|
|
110
118
|
itemCount: number;
|
|
111
119
|
/** Total quantity of all items */
|
|
@@ -118,8 +126,6 @@ interface UseCartReturn {
|
|
|
118
126
|
total: number;
|
|
119
127
|
/** Whether cart is loading */
|
|
120
128
|
loading: boolean;
|
|
121
|
-
/** Error from last cart operation */
|
|
122
|
-
error: Error | null;
|
|
123
129
|
/**
|
|
124
130
|
* Add product to cart
|
|
125
131
|
* @param productId - Product ID to add
|
|
@@ -160,6 +166,7 @@ interface UseCartReturn {
|
|
|
160
166
|
}
|
|
161
167
|
/**
|
|
162
168
|
* Hook for shopping cart management
|
|
169
|
+
* Uses global state from DiffsomeProvider for consistent cart across all components
|
|
163
170
|
*
|
|
164
171
|
* @example
|
|
165
172
|
* ```tsx
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { Diffsome, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider,
|
|
4
|
+
import { Diffsome, Cart, WishlistItem, DiffsomeConfig, Member, LoginCredentials, AuthResponse, RegisterData, UpdateProfileData, ResetPasswordData, SocialProvider, WishlistToggleResult, WishlistMoveToCartResult, BundlePricing, ProductCategory, Product, PaginationMeta, ProductListParams, ProductType, CreateOrderData, Order, OrderListParams, PaymentStatusResponse, StripeCheckoutResponse, StripeVerifyResponse, TossPaymentReadyResponse, TossPaymentConfirmResponse, Coupon, CouponValidation, MemberSubscription, DigitalDownloadLink, CanReviewResponse, CreateProductReviewData, ProductReview, UpdateProductReviewData, ProductReviewStats, ProductReviewListParams, BlogCategory, BlogListParams, BlogPost, BoardPost, Board, CreateBoardPostData, BoardPostListParams, BoardListParams, Comment, CreateCommentData, Form, FormSubmissionData, FormSubmission, ReservationSlot, CreateReservationData, Reservation, ReservationService, ReservationSettings, ReservationStaff, ReservationListParams, Media, CustomEntity, EntityRecord, EntityListParams } from '@diffsome/sdk';
|
|
5
5
|
export { AddToCartData, AuthResponse, BlogCategory, BlogListParams, BlogPost, Board, BoardListParams, BoardPost, BoardPostListParams, CanReviewResponse, Cart, CartItem, Comment, Coupon, CouponType, CouponValidation, CreateBoardPostData, CreateCommentData, CreateOrderData, CreateProductReviewData, CreateReservationData, CustomEntity, DiffsomeConfig, DigitalDownloadLink, DigitalFile, EntityField, EntityListParams, EntityRecord, EntitySchema, Form, FormSubmission, FormSubmissionData, ListResponse, LoginCredentials, Media, Member, MemberSubscription, Order, OrderItem, OrderListParams, OrderStatus, PaginatedResponse, PaginationMeta, Payment, PaymentMethod, PaymentStatus, PaymentStatusResponse, Product, ProductCategory, ProductListParams, ProductReview, ProductReviewStats, ProductType, ProductVariant, RegisterData, Reservation, ReservationService, ReservationSettings, ReservationSlot, ReservationStaff, ResetPasswordData, SocialAuthUrl, SocialProvider, StripeCheckoutResponse, StripeVerifyResponse, SubscriptionInterval, SubscriptionPlan, SubscriptionStatus, TossPaymentConfirmResponse, TossPaymentReadyResponse, UpdateProfileData, WishlistItem, WishlistMoveToCartResult, WishlistToggleResult } from '@diffsome/sdk';
|
|
6
6
|
|
|
7
7
|
interface DiffsomeContextValue {
|
|
8
8
|
client: Diffsome;
|
|
9
9
|
isReady: boolean;
|
|
10
|
+
cart: Cart | null;
|
|
11
|
+
cartLoading: boolean;
|
|
12
|
+
setCart: (cart: Cart | null) => void;
|
|
13
|
+
refreshCart: () => Promise<void>;
|
|
14
|
+
wishlistItems: WishlistItem[];
|
|
15
|
+
wishlistLoading: boolean;
|
|
16
|
+
setWishlistItems: (items: WishlistItem[]) => void;
|
|
17
|
+
refreshWishlist: () => Promise<void>;
|
|
10
18
|
}
|
|
11
19
|
declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
|
|
12
20
|
interface DiffsomeProviderProps {
|
|
@@ -105,7 +113,7 @@ interface UseCartReturn {
|
|
|
105
113
|
/** Full cart object with metadata */
|
|
106
114
|
cart: Cart | null;
|
|
107
115
|
/** Array of cart items */
|
|
108
|
-
items:
|
|
116
|
+
items: Cart['items'];
|
|
109
117
|
/** Number of unique items in cart */
|
|
110
118
|
itemCount: number;
|
|
111
119
|
/** Total quantity of all items */
|
|
@@ -118,8 +126,6 @@ interface UseCartReturn {
|
|
|
118
126
|
total: number;
|
|
119
127
|
/** Whether cart is loading */
|
|
120
128
|
loading: boolean;
|
|
121
|
-
/** Error from last cart operation */
|
|
122
|
-
error: Error | null;
|
|
123
129
|
/**
|
|
124
130
|
* Add product to cart
|
|
125
131
|
* @param productId - Product ID to add
|
|
@@ -160,6 +166,7 @@ interface UseCartReturn {
|
|
|
160
166
|
}
|
|
161
167
|
/**
|
|
162
168
|
* Hook for shopping cart management
|
|
169
|
+
* Uses global state from DiffsomeProvider for consistent cart across all components
|
|
163
170
|
*
|
|
164
171
|
* @example
|
|
165
172
|
* ```tsx
|
package/dist/index.js
CHANGED
|
@@ -98,6 +98,10 @@ var getEnvVar = (key) => {
|
|
|
98
98
|
};
|
|
99
99
|
function DiffsomeProvider({ children, config = {} }) {
|
|
100
100
|
const [isReady, setIsReady] = (0, import_react.useState)(false);
|
|
101
|
+
const [cart, setCart] = (0, import_react.useState)(null);
|
|
102
|
+
const [cartLoading, setCartLoading] = (0, import_react.useState)(true);
|
|
103
|
+
const [wishlistItems, setWishlistItems] = (0, import_react.useState)([]);
|
|
104
|
+
const [wishlistLoading, setWishlistLoading] = (0, import_react.useState)(true);
|
|
101
105
|
const tenantId = config.tenantId || getEnvVar("DIFFSOME_TENANT_ID");
|
|
102
106
|
const apiKey = config.apiKey || getEnvVar("DIFFSOME_API_KEY");
|
|
103
107
|
const baseUrl = config.baseUrl || getEnvVar("DIFFSOME_BASE_URL");
|
|
@@ -115,13 +119,59 @@ function DiffsomeProvider({ children, config = {} }) {
|
|
|
115
119
|
storageType: config.storageType ?? "localStorage"
|
|
116
120
|
});
|
|
117
121
|
}, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
|
|
122
|
+
const refreshCart = (0, import_react.useCallback)(async () => {
|
|
123
|
+
setCartLoading(true);
|
|
124
|
+
try {
|
|
125
|
+
const cartData = await client.shop.getCart();
|
|
126
|
+
setCart(cartData);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
setCart(null);
|
|
129
|
+
} finally {
|
|
130
|
+
setCartLoading(false);
|
|
131
|
+
}
|
|
132
|
+
}, [client]);
|
|
133
|
+
const refreshWishlist = (0, import_react.useCallback)(async () => {
|
|
134
|
+
if (!client.isAuthenticated()) {
|
|
135
|
+
setWishlistItems([]);
|
|
136
|
+
setWishlistLoading(false);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
setWishlistLoading(true);
|
|
140
|
+
try {
|
|
141
|
+
const response = await client.shop.getWishlist({ per_page: 100 });
|
|
142
|
+
setWishlistItems(response.data);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
setWishlistItems([]);
|
|
145
|
+
} finally {
|
|
146
|
+
setWishlistLoading(false);
|
|
147
|
+
}
|
|
148
|
+
}, [client]);
|
|
118
149
|
(0, import_react.useEffect)(() => {
|
|
119
150
|
setIsReady(true);
|
|
120
|
-
|
|
151
|
+
refreshCart();
|
|
152
|
+
refreshWishlist();
|
|
153
|
+
}, [refreshCart, refreshWishlist]);
|
|
154
|
+
(0, import_react.useEffect)(() => {
|
|
155
|
+
const handleAuthChange = () => {
|
|
156
|
+
refreshWishlist();
|
|
157
|
+
};
|
|
158
|
+
if (typeof window !== "undefined") {
|
|
159
|
+
window.addEventListener("storage", handleAuthChange);
|
|
160
|
+
return () => window.removeEventListener("storage", handleAuthChange);
|
|
161
|
+
}
|
|
162
|
+
}, [refreshWishlist]);
|
|
121
163
|
const value = (0, import_react.useMemo)(() => ({
|
|
122
164
|
client,
|
|
123
|
-
isReady
|
|
124
|
-
|
|
165
|
+
isReady,
|
|
166
|
+
cart,
|
|
167
|
+
cartLoading,
|
|
168
|
+
setCart,
|
|
169
|
+
refreshCart,
|
|
170
|
+
wishlistItems,
|
|
171
|
+
wishlistLoading,
|
|
172
|
+
setWishlistItems,
|
|
173
|
+
refreshWishlist
|
|
174
|
+
}), [client, isReady, cart, cartLoading, refreshCart, wishlistItems, wishlistLoading, refreshWishlist]);
|
|
125
175
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DiffsomeContext.Provider, { value, children });
|
|
126
176
|
}
|
|
127
177
|
function useDiffsome() {
|
|
@@ -280,25 +330,7 @@ function useSocialAuth() {
|
|
|
280
330
|
// src/hooks/useCart.ts
|
|
281
331
|
var import_react4 = require("react");
|
|
282
332
|
function useCart() {
|
|
283
|
-
const client =
|
|
284
|
-
const [cart, setCart] = (0, import_react4.useState)(null);
|
|
285
|
-
const [loading, setLoading] = (0, import_react4.useState)(true);
|
|
286
|
-
const [error, setError] = (0, import_react4.useState)(null);
|
|
287
|
-
const fetchCart = (0, import_react4.useCallback)(async () => {
|
|
288
|
-
try {
|
|
289
|
-
const cartData = await client.shop.getCart();
|
|
290
|
-
setCart(cartData);
|
|
291
|
-
setError(null);
|
|
292
|
-
} catch (err) {
|
|
293
|
-
setCart(null);
|
|
294
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch cart"));
|
|
295
|
-
} finally {
|
|
296
|
-
setLoading(false);
|
|
297
|
-
}
|
|
298
|
-
}, [client]);
|
|
299
|
-
(0, import_react4.useEffect)(() => {
|
|
300
|
-
fetchCart();
|
|
301
|
-
}, [fetchCart]);
|
|
333
|
+
const { client, cart, cartLoading, setCart, refreshCart } = useDiffsome();
|
|
302
334
|
const addToCart = (0, import_react4.useCallback)(async (productId, quantity = 1, variantId, options) => {
|
|
303
335
|
const data = {
|
|
304
336
|
product_id: productId,
|
|
@@ -309,25 +341,21 @@ function useCart() {
|
|
|
309
341
|
const updatedCart = await client.shop.addToCart(data);
|
|
310
342
|
setCart(updatedCart);
|
|
311
343
|
return updatedCart;
|
|
312
|
-
}, [client]);
|
|
344
|
+
}, [client, setCart]);
|
|
313
345
|
const updateItem = (0, import_react4.useCallback)(async (itemId, quantity) => {
|
|
314
346
|
const updatedCart = await client.shop.updateCartItem(itemId, { quantity });
|
|
315
347
|
setCart(updatedCart);
|
|
316
348
|
return updatedCart;
|
|
317
|
-
}, [client]);
|
|
349
|
+
}, [client, setCart]);
|
|
318
350
|
const removeItem = (0, import_react4.useCallback)(async (itemId) => {
|
|
319
351
|
const updatedCart = await client.shop.removeFromCart(itemId);
|
|
320
352
|
setCart(updatedCart);
|
|
321
353
|
return updatedCart;
|
|
322
|
-
}, [client]);
|
|
354
|
+
}, [client, setCart]);
|
|
323
355
|
const clearCart = (0, import_react4.useCallback)(async () => {
|
|
324
356
|
await client.shop.clearCart();
|
|
325
357
|
setCart(null);
|
|
326
|
-
}, [client]);
|
|
327
|
-
const refresh = (0, import_react4.useCallback)(async () => {
|
|
328
|
-
setLoading(true);
|
|
329
|
-
await fetchCart();
|
|
330
|
-
}, [fetchCart]);
|
|
358
|
+
}, [client, setCart]);
|
|
331
359
|
const isInCart = (0, import_react4.useCallback)((productId, variantId) => {
|
|
332
360
|
if (!cart?.items) return false;
|
|
333
361
|
return cart.items.some(
|
|
@@ -349,13 +377,12 @@ function useCart() {
|
|
|
349
377
|
subtotal: cart?.subtotal ?? 0,
|
|
350
378
|
shippingFee: cart?.shipping_fee ?? 0,
|
|
351
379
|
total: cart?.total ?? 0,
|
|
352
|
-
loading,
|
|
353
|
-
error,
|
|
380
|
+
loading: cartLoading,
|
|
354
381
|
addToCart,
|
|
355
382
|
updateItem,
|
|
356
383
|
removeItem,
|
|
357
384
|
clearCart,
|
|
358
|
-
refresh,
|
|
385
|
+
refresh: refreshCart,
|
|
359
386
|
isInCart,
|
|
360
387
|
getItemQuantity
|
|
361
388
|
};
|
|
@@ -364,102 +391,63 @@ function useCart() {
|
|
|
364
391
|
// src/hooks/useWishlist.ts
|
|
365
392
|
var import_react5 = require("react");
|
|
366
393
|
function useWishlist() {
|
|
367
|
-
const client =
|
|
368
|
-
const [items, setItems] = (0, import_react5.useState)([]);
|
|
369
|
-
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
394
|
+
const { client, wishlistItems, wishlistLoading, setWishlistItems, refreshWishlist, setCart } = useDiffsome();
|
|
370
395
|
const [error, setError] = (0, import_react5.useState)(null);
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
try {
|
|
380
|
-
const response = await client.shop.getWishlist({ per_page: 100 });
|
|
381
|
-
setItems(response.data);
|
|
382
|
-
const map = {};
|
|
383
|
-
response.data.forEach((item) => {
|
|
384
|
-
const key = item.variant_id ? `${item.product_id}_${item.variant_id}` : String(item.product_id);
|
|
385
|
-
map[key] = true;
|
|
386
|
-
});
|
|
387
|
-
setWishlistMap(map);
|
|
388
|
-
setError(null);
|
|
389
|
-
} catch (err) {
|
|
390
|
-
setItems([]);
|
|
391
|
-
setWishlistMap({});
|
|
392
|
-
setError(err instanceof Error ? err : new Error("Failed to fetch wishlist"));
|
|
393
|
-
} finally {
|
|
394
|
-
setLoading(false);
|
|
395
|
-
}
|
|
396
|
-
}, [client]);
|
|
397
|
-
(0, import_react5.useEffect)(() => {
|
|
398
|
-
fetchWishlist();
|
|
399
|
-
}, [fetchWishlist]);
|
|
396
|
+
const wishlistMap = (0, import_react5.useMemo)(() => {
|
|
397
|
+
const map = {};
|
|
398
|
+
wishlistItems.forEach((item) => {
|
|
399
|
+
const key = item.variant_id ? `${item.product_id}_${item.variant_id}` : String(item.product_id);
|
|
400
|
+
map[key] = true;
|
|
401
|
+
});
|
|
402
|
+
return map;
|
|
403
|
+
}, [wishlistItems]);
|
|
400
404
|
const isInWishlist = (0, import_react5.useCallback)((productId, variantId) => {
|
|
401
405
|
const key = variantId ? `${productId}_${variantId}` : String(productId);
|
|
402
406
|
return wishlistMap[key] || false;
|
|
403
407
|
}, [wishlistMap]);
|
|
404
408
|
const toggleWishlist = (0, import_react5.useCallback)(async (productId, variantId) => {
|
|
405
409
|
const result = await client.shop.toggleWishlist(productId, variantId);
|
|
406
|
-
const key = variantId ? `${productId}_${variantId}` : String(productId);
|
|
407
|
-
setWishlistMap((prev) => ({
|
|
408
|
-
...prev,
|
|
409
|
-
[key]: result.in_wishlist
|
|
410
|
-
}));
|
|
411
410
|
if (result.action === "added") {
|
|
412
|
-
await
|
|
411
|
+
await refreshWishlist();
|
|
413
412
|
} else {
|
|
414
|
-
|
|
413
|
+
setWishlistItems(wishlistItems.filter(
|
|
415
414
|
(item) => !(item.product_id === productId && item.variant_id === variantId)
|
|
416
415
|
));
|
|
417
416
|
}
|
|
418
417
|
return result;
|
|
419
|
-
}, [client,
|
|
418
|
+
}, [client, refreshWishlist, setWishlistItems, wishlistItems]);
|
|
420
419
|
const addToWishlist = (0, import_react5.useCallback)(async (productId, variantId, note) => {
|
|
421
420
|
const item = await client.shop.addToWishlist({
|
|
422
421
|
product_id: productId,
|
|
423
422
|
variant_id: variantId,
|
|
424
423
|
note
|
|
425
424
|
});
|
|
426
|
-
await
|
|
425
|
+
await refreshWishlist();
|
|
427
426
|
return item;
|
|
428
|
-
}, [client,
|
|
427
|
+
}, [client, refreshWishlist]);
|
|
429
428
|
const removeFromWishlist = (0, import_react5.useCallback)(async (wishlistId) => {
|
|
430
|
-
const item = items.find((i) => i.id === wishlistId);
|
|
431
429
|
await client.shop.removeFromWishlist(wishlistId);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
setWishlistMap((prev) => {
|
|
435
|
-
const next = { ...prev };
|
|
436
|
-
delete next[key];
|
|
437
|
-
return next;
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
setItems((prev) => prev.filter((i) => i.id !== wishlistId));
|
|
441
|
-
}, [client, items]);
|
|
430
|
+
setWishlistItems(wishlistItems.filter((i) => i.id !== wishlistId));
|
|
431
|
+
}, [client, setWishlistItems, wishlistItems]);
|
|
442
432
|
const moveToCart = (0, import_react5.useCallback)(async (wishlistIds) => {
|
|
443
433
|
const result = await client.shop.moveWishlistToCart(wishlistIds);
|
|
444
|
-
await
|
|
434
|
+
await refreshWishlist();
|
|
435
|
+
const cartData = await client.shop.getCart();
|
|
436
|
+
setCart(cartData);
|
|
445
437
|
return result;
|
|
446
|
-
}, [client,
|
|
438
|
+
}, [client, refreshWishlist, setCart]);
|
|
447
439
|
const updateNote = (0, import_react5.useCallback)(async (wishlistId, note) => {
|
|
448
440
|
const item = await client.shop.updateWishlistNote(wishlistId, note);
|
|
449
|
-
|
|
441
|
+
setWishlistItems(wishlistItems.map((i) => i.id === wishlistId ? item : i));
|
|
450
442
|
return item;
|
|
451
|
-
}, [client]);
|
|
443
|
+
}, [client, setWishlistItems, wishlistItems]);
|
|
452
444
|
const getProductWishlistCount = (0, import_react5.useCallback)(async (productSlug) => {
|
|
453
445
|
return await client.shop.getProductWishlistCount(productSlug);
|
|
454
446
|
}, [client]);
|
|
455
|
-
const refresh = (0, import_react5.useCallback)(async () => {
|
|
456
|
-
setLoading(true);
|
|
457
|
-
await fetchWishlist();
|
|
458
|
-
}, [fetchWishlist]);
|
|
459
447
|
return {
|
|
460
|
-
items,
|
|
461
|
-
count:
|
|
462
|
-
loading,
|
|
448
|
+
items: wishlistItems,
|
|
449
|
+
count: wishlistItems.length,
|
|
450
|
+
loading: wishlistLoading,
|
|
463
451
|
error,
|
|
464
452
|
isInWishlist,
|
|
465
453
|
toggleWishlist,
|
|
@@ -468,7 +456,7 @@ function useWishlist() {
|
|
|
468
456
|
moveToCart,
|
|
469
457
|
updateNote,
|
|
470
458
|
getProductWishlistCount,
|
|
471
|
-
refresh
|
|
459
|
+
refresh: refreshWishlist
|
|
472
460
|
};
|
|
473
461
|
}
|
|
474
462
|
|