@orderingstack/front-hooks 3.8.0 → 3.9.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.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +36 -9
- package/dist/index.es.js.map +1 -1
- package/dist/src/useCms.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1391,6 +1391,19 @@ function isProductEnabled(item, enableKeys) {
|
|
|
1391
1391
|
const itemEnableKeys = enableKey.replace(/\s/g, "").split(",");
|
|
1392
1392
|
return itemEnableKeys.some((key) => enableKeys.includes(key));
|
|
1393
1393
|
}
|
|
1394
|
+
function getProductAcronym(product) {
|
|
1395
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1396
|
+
const arrayName = (_b = (_a = product.details) == null ? void 0 : _a.literals) == null ? void 0 : _b.name.split(" ").filter((string) => string !== "");
|
|
1397
|
+
if (!arrayName)
|
|
1398
|
+
return "";
|
|
1399
|
+
if (arrayName.length === 1) {
|
|
1400
|
+
return ((_f = (_e = (_d = (_c = product.details) == null ? void 0 : _c.literals) == null ? void 0 : _d.name) == null ? void 0 : _e.slice) == null ? void 0 : _f.call(_e, 0, 2)) || "";
|
|
1401
|
+
}
|
|
1402
|
+
if (arrayName.length > 1) {
|
|
1403
|
+
return `${arrayName[0][0]}${arrayName[1][0]}`;
|
|
1404
|
+
}
|
|
1405
|
+
return "";
|
|
1406
|
+
}
|
|
1394
1407
|
function useAvailability(originalMenu, markOnly = false, timeZone = void 0, interval = 60) {
|
|
1395
1408
|
const [menu, setMenu] = useState(originalMenu ? filterTimeAvailabilityOfProducts(originalMenu, timeZone, void 0, markOnly) : originalMenu);
|
|
1396
1409
|
useInterval(checkAvailability, interval * 1e3);
|
|
@@ -3120,8 +3133,8 @@ function useCms(id, intervalSeconds = 600, withLocalStorage = true, baseUrl, ten
|
|
|
3120
3133
|
const [timestamp, setTimestamp] = useState(((_b = getFromLocalStorage()) == null ? void 0 : _b.timestamp) || 0);
|
|
3121
3134
|
const [state, setState] = useState(loadedData || null);
|
|
3122
3135
|
const [error, setError] = useState(false);
|
|
3123
|
-
function getCms() {
|
|
3124
|
-
axios.get(url).then((res) => {
|
|
3136
|
+
async function getCms(signal) {
|
|
3137
|
+
return axios.get(url, { signal }).then((res) => {
|
|
3125
3138
|
if (isEmpty_1(res.data)) {
|
|
3126
3139
|
throw new Error(`CMS data '${id}' is an empty object`);
|
|
3127
3140
|
}
|
|
@@ -3135,10 +3148,11 @@ function useCms(id, intervalSeconds = 600, withLocalStorage = true, baseUrl, ten
|
|
|
3135
3148
|
saveToLocalStorage(res.data);
|
|
3136
3149
|
}
|
|
3137
3150
|
}).catch((e) => {
|
|
3138
|
-
|
|
3139
|
-
|
|
3151
|
+
if (e.code !== "ERR_CANCELED") {
|
|
3152
|
+
console.error(e);
|
|
3153
|
+
setError(true);
|
|
3154
|
+
}
|
|
3140
3155
|
});
|
|
3141
|
-
return;
|
|
3142
3156
|
}
|
|
3143
3157
|
function saveToLocalStorage(data) {
|
|
3144
3158
|
const t = new Date().valueOf();
|
|
@@ -3153,7 +3167,8 @@ function useCms(id, intervalSeconds = 600, withLocalStorage = true, baseUrl, ten
|
|
|
3153
3167
|
try {
|
|
3154
3168
|
const value = localStorage.getItem(key);
|
|
3155
3169
|
if (value) {
|
|
3156
|
-
|
|
3170
|
+
const val = JSON.parse(value);
|
|
3171
|
+
return val;
|
|
3157
3172
|
}
|
|
3158
3173
|
} catch (e) {
|
|
3159
3174
|
console.warn(e);
|
|
@@ -3161,10 +3176,22 @@ function useCms(id, intervalSeconds = 600, withLocalStorage = true, baseUrl, ten
|
|
|
3161
3176
|
return null;
|
|
3162
3177
|
}
|
|
3163
3178
|
useEffect(() => {
|
|
3179
|
+
console.log("CMS ID", id);
|
|
3164
3180
|
if (new Date().valueOf() - timestamp > intervalSeconds * 1e3) {
|
|
3165
|
-
|
|
3181
|
+
const controller = new AbortController();
|
|
3182
|
+
getCms(controller.signal);
|
|
3183
|
+
return () => controller.abort();
|
|
3184
|
+
}
|
|
3185
|
+
const val = getFromLocalStorage();
|
|
3186
|
+
if (val == null ? void 0 : val.value) {
|
|
3187
|
+
setState(val.value);
|
|
3188
|
+
setTimestamp(val.timestamp);
|
|
3189
|
+
} else {
|
|
3190
|
+
const controller = new AbortController();
|
|
3191
|
+
getCms(controller.signal);
|
|
3192
|
+
return () => controller.abort();
|
|
3166
3193
|
}
|
|
3167
|
-
}, []);
|
|
3194
|
+
}, [id]);
|
|
3168
3195
|
useInterval(getCms, intervalSeconds * 1e3);
|
|
3169
3196
|
return { value: state, isError: error, isLoading: !error && !state };
|
|
3170
3197
|
}
|
|
@@ -3744,5 +3771,5 @@ function getMediaUrl(url, size = 500) {
|
|
|
3744
3771
|
function useMediaUrl(url, size = 500) {
|
|
3745
3772
|
return getMediaUrl(url, size);
|
|
3746
3773
|
}
|
|
3747
|
-
export { addDiscounts, formatPrice, getGroupedBucketLines, getMediaUrl, groupOrderLines, isChannelOpen, isProductEnabled, summarizeLineDiscounts, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useKioskChannelsAvailability, useKioskMediaCms, useKioskMediaCmsWithContext, useLocalizedVenueMedia, useMediaUrl, useMenu, useOnClickOutside, useVenueCms };
|
|
3774
|
+
export { addDiscounts, formatPrice, getGroupedBucketLines, getMediaUrl, getProductAcronym, groupOrderLines, isChannelOpen, isProductEnabled, summarizeLineDiscounts, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useKioskChannelsAvailability, useKioskMediaCms, useKioskMediaCmsWithContext, useLocalizedVenueMedia, useMediaUrl, useMenu, useOnClickOutside, useVenueCms };
|
|
3748
3775
|
//# sourceMappingURL=index.es.js.map
|