@pradip1995/segment-product-card 0.3.9 → 0.3.11
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/package.json +8 -8
- package/src/product-card-actions.tsx +16 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-product-card",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"./product-scroll": "./src/product-scroll.tsx",
|
|
18
18
|
"./product-rail-variants": "./src/product-rail-variants.tsx"
|
|
19
19
|
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"lint": "tsc --noEmit"
|
|
23
|
+
},
|
|
20
24
|
"peerDependencies": {
|
|
21
25
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
22
26
|
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
@@ -25,17 +29,13 @@
|
|
|
25
29
|
"next": ">=15"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@pradip1995/segment-primitives": "^0.
|
|
29
|
-
"@pradip1995/segment-tokens": "^0.3.
|
|
32
|
+
"@pradip1995/segment-primitives": "^0.4.0",
|
|
33
|
+
"@pradip1995/segment-tokens": "^0.3.7"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
36
|
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
33
37
|
"@types/react": "^19",
|
|
34
38
|
"react": "19.0.3",
|
|
35
39
|
"typescript": "^5.7.2"
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"typecheck": "tsc --noEmit",
|
|
39
|
-
"lint": "tsc --noEmit"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
|
@@ -52,14 +52,11 @@ export default function ProductCardActions({ product, countryCode, wishlistProdu
|
|
|
52
52
|
useEffect(() => {
|
|
53
53
|
if (!product.id) return
|
|
54
54
|
|
|
55
|
+
// Prefer server-provided IDs. Do not fan out getWishlistProductIds() per card
|
|
56
|
+
// on home — resolve lazily on first heart click when IDs were not passed.
|
|
55
57
|
if (wishlistProductIds !== undefined) {
|
|
56
58
|
setWishlisted(wishlistProductIds.includes(product.id))
|
|
57
|
-
return
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
getWishlistProductIds()
|
|
61
|
-
.then((ids) => setWishlisted(ids.includes(product.id!)))
|
|
62
|
-
.catch(() => {})
|
|
63
60
|
}, [product.id, wishlistProductIds])
|
|
64
61
|
|
|
65
62
|
useEffect(() => {
|
|
@@ -91,12 +88,24 @@ export default function ProductCardActions({ product, countryCode, wishlistProdu
|
|
|
91
88
|
|
|
92
89
|
setWishlistLoading(true)
|
|
93
90
|
try {
|
|
94
|
-
|
|
91
|
+
// Lazy-resolve wishlist state when layout did not pass IDs (anonymous / slim layout).
|
|
92
|
+
let currentlyWishlisted = wishlisted
|
|
93
|
+
if (wishlistProductIds === undefined) {
|
|
94
|
+
try {
|
|
95
|
+
const ids = await getWishlistProductIds()
|
|
96
|
+
currentlyWishlisted = ids.includes(product.id)
|
|
97
|
+
setWishlisted(currentlyWishlisted)
|
|
98
|
+
} catch {
|
|
99
|
+
currentlyWishlisted = false
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const result = currentlyWishlisted
|
|
95
104
|
? await removeFromWishlist(product.id)
|
|
96
105
|
: await addToWishlist(product.id)
|
|
97
106
|
|
|
98
107
|
if (result.success) {
|
|
99
|
-
setWishlisted(!
|
|
108
|
+
setWishlisted(!currentlyWishlisted)
|
|
100
109
|
router.refresh()
|
|
101
110
|
return
|
|
102
111
|
}
|