@gem-sdk/core 1.21.10 → 1.21.12
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.
|
@@ -28,11 +28,32 @@ const useQuantity = ()=>{
|
|
|
28
28
|
const decrement = ProductContext.useProductStore((s)=>s.decrementQuantity);
|
|
29
29
|
const increment = ProductContext.useProductStore((s)=>s.incrementQuantity);
|
|
30
30
|
const updateQuantity = ProductContext.useProductStore((s)=>s.setQuantity);
|
|
31
|
+
const isSyncProduct = ProductContext.useProductStore((s)=>s.isSyncProduct);
|
|
32
|
+
const product = ProductContext.useProductStore((s)=>s.product);
|
|
33
|
+
const productId = product?.id;
|
|
31
34
|
const reset = react.useCallback(()=>{
|
|
32
35
|
updateQuantity(1);
|
|
33
36
|
}, [
|
|
34
37
|
updateQuantity
|
|
35
38
|
]);
|
|
39
|
+
react.useEffect(()=>{
|
|
40
|
+
if (isSyncProduct) {
|
|
41
|
+
const setOption = new CustomEvent('set-product-quantity', {
|
|
42
|
+
bubbles: true,
|
|
43
|
+
cancelable: true,
|
|
44
|
+
composed: true,
|
|
45
|
+
detail: {
|
|
46
|
+
quantity,
|
|
47
|
+
productId
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
window.dispatchEvent(setOption);
|
|
51
|
+
}
|
|
52
|
+
}, [
|
|
53
|
+
quantity,
|
|
54
|
+
isSyncProduct,
|
|
55
|
+
productId
|
|
56
|
+
]);
|
|
36
57
|
return react.useMemo(()=>({
|
|
37
58
|
quantity,
|
|
38
59
|
increment,
|
|
@@ -51,8 +72,9 @@ const useSelectedOption = ()=>{
|
|
|
51
72
|
const setSelectedOption = ProductContext.useProductStore((s)=>s.setSelectedOption);
|
|
52
73
|
const selectedOptions = ProductContext.useProductStore((s)=>s.selectedOptions);
|
|
53
74
|
const forceSelectedOption = ProductContext.useProductStore((s)=>s.forceSelectedOption);
|
|
75
|
+
const isSyncProduct = ProductContext.useProductStore((s)=>s.isSyncProduct);
|
|
54
76
|
const updateOption = react.useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
55
|
-
if (!noEmit) {
|
|
77
|
+
if (!noEmit && isSyncProduct) {
|
|
56
78
|
const setOption = new CustomEvent('set-selected-option', {
|
|
57
79
|
bubbles: true,
|
|
58
80
|
cancelable: true,
|
|
@@ -67,10 +89,11 @@ const useSelectedOption = ()=>{
|
|
|
67
89
|
}
|
|
68
90
|
setSelectedOption(optionId, optionValue);
|
|
69
91
|
}, [
|
|
70
|
-
setSelectedOption
|
|
92
|
+
setSelectedOption,
|
|
93
|
+
isSyncProduct
|
|
71
94
|
]);
|
|
72
95
|
const forceOption = react.useCallback((selectedOption, productId, noEmit)=>{
|
|
73
|
-
if (!noEmit) {
|
|
96
|
+
if (!noEmit && isSyncProduct) {
|
|
74
97
|
const forceOption = new CustomEvent('force-selected-option', {
|
|
75
98
|
bubbles: true,
|
|
76
99
|
cancelable: true,
|
|
@@ -84,7 +107,8 @@ const useSelectedOption = ()=>{
|
|
|
84
107
|
}
|
|
85
108
|
forceSelectedOption(selectedOption);
|
|
86
109
|
}, [
|
|
87
|
-
forceSelectedOption
|
|
110
|
+
forceSelectedOption,
|
|
111
|
+
isSyncProduct
|
|
88
112
|
]);
|
|
89
113
|
return react.useMemo(()=>({
|
|
90
114
|
selectedOptions,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
2
|
import { useProductStore } from '../contexts/ProductContext.js';
|
|
3
3
|
import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
4
4
|
import 'swr';
|
|
@@ -26,11 +26,32 @@ const useQuantity = ()=>{
|
|
|
26
26
|
const decrement = useProductStore((s)=>s.decrementQuantity);
|
|
27
27
|
const increment = useProductStore((s)=>s.incrementQuantity);
|
|
28
28
|
const updateQuantity = useProductStore((s)=>s.setQuantity);
|
|
29
|
+
const isSyncProduct = useProductStore((s)=>s.isSyncProduct);
|
|
30
|
+
const product = useProductStore((s)=>s.product);
|
|
31
|
+
const productId = product?.id;
|
|
29
32
|
const reset = useCallback(()=>{
|
|
30
33
|
updateQuantity(1);
|
|
31
34
|
}, [
|
|
32
35
|
updateQuantity
|
|
33
36
|
]);
|
|
37
|
+
useEffect(()=>{
|
|
38
|
+
if (isSyncProduct) {
|
|
39
|
+
const setOption = new CustomEvent('set-product-quantity', {
|
|
40
|
+
bubbles: true,
|
|
41
|
+
cancelable: true,
|
|
42
|
+
composed: true,
|
|
43
|
+
detail: {
|
|
44
|
+
quantity,
|
|
45
|
+
productId
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
window.dispatchEvent(setOption);
|
|
49
|
+
}
|
|
50
|
+
}, [
|
|
51
|
+
quantity,
|
|
52
|
+
isSyncProduct,
|
|
53
|
+
productId
|
|
54
|
+
]);
|
|
34
55
|
return useMemo(()=>({
|
|
35
56
|
quantity,
|
|
36
57
|
increment,
|
|
@@ -49,8 +70,9 @@ const useSelectedOption = ()=>{
|
|
|
49
70
|
const setSelectedOption = useProductStore((s)=>s.setSelectedOption);
|
|
50
71
|
const selectedOptions = useProductStore((s)=>s.selectedOptions);
|
|
51
72
|
const forceSelectedOption = useProductStore((s)=>s.forceSelectedOption);
|
|
73
|
+
const isSyncProduct = useProductStore((s)=>s.isSyncProduct);
|
|
52
74
|
const updateOption = useCallback((optionId, optionValue, productId, noEmit)=>{
|
|
53
|
-
if (!noEmit) {
|
|
75
|
+
if (!noEmit && isSyncProduct) {
|
|
54
76
|
const setOption = new CustomEvent('set-selected-option', {
|
|
55
77
|
bubbles: true,
|
|
56
78
|
cancelable: true,
|
|
@@ -65,10 +87,11 @@ const useSelectedOption = ()=>{
|
|
|
65
87
|
}
|
|
66
88
|
setSelectedOption(optionId, optionValue);
|
|
67
89
|
}, [
|
|
68
|
-
setSelectedOption
|
|
90
|
+
setSelectedOption,
|
|
91
|
+
isSyncProduct
|
|
69
92
|
]);
|
|
70
93
|
const forceOption = useCallback((selectedOption, productId, noEmit)=>{
|
|
71
|
-
if (!noEmit) {
|
|
94
|
+
if (!noEmit && isSyncProduct) {
|
|
72
95
|
const forceOption = new CustomEvent('force-selected-option', {
|
|
73
96
|
bubbles: true,
|
|
74
97
|
cancelable: true,
|
|
@@ -82,7 +105,8 @@ const useSelectedOption = ()=>{
|
|
|
82
105
|
}
|
|
83
106
|
forceSelectedOption(selectedOption);
|
|
84
107
|
}, [
|
|
85
|
-
forceSelectedOption
|
|
108
|
+
forceSelectedOption,
|
|
109
|
+
isSyncProduct
|
|
86
110
|
]);
|
|
87
111
|
return useMemo(()=>({
|
|
88
112
|
selectedOptions,
|