@redneckz/wildless-cms-uni-blocks 0.14.59 → 0.14.60
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/bundle/bundle.umd.js +48 -73
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/dist/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
- package/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js +4 -35
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/lib/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
- package/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js +3 -33
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +48 -73
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
- package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js +4 -35
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js +3 -1
- package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -10
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js +3 -33
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/src/components/ExchangeRateTile/ExchangeRateTile.tsx +3 -1
- package/mobile/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +7 -54
- package/package.json +1 -1
- package/src/components/ExchangeRateTile/ExchangeRateTile.tsx +3 -1
- package/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +7 -54
package/bundle/bundle.umd.js
CHANGED
|
@@ -3499,6 +3499,48 @@
|
|
|
3499
3499
|
};
|
|
3500
3500
|
const ErrorBlock = JSX(({ className = '', title, description, error, button, ...rest }) => (jsxs(BlockWrapper, { className: style('flex flex-col justify-center items-center', className), defaultPadding: style('p-6xl'), version: "transparent", ...rest, children: [jsx("div", { className: "flex justify-center", children: renderErrorContent(error) }), jsx(Headline, { title: title, description: description, headlineVersion: "XL", isEmbedded: true, className: "mb-2xl last:mb-0" }), button?.text ? jsx(Button, { version: button?.version, text: button?.text, ...button }) : null] })));
|
|
3501
3501
|
|
|
3502
|
+
const useLatestEvent = (eventBus, type, initialEvent) => {
|
|
3503
|
+
const [latestEvent, setLatestEvent] = useState(initialEvent || null);
|
|
3504
|
+
useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
|
|
3505
|
+
const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
|
|
3506
|
+
return [latestEvent, fireEvent];
|
|
3507
|
+
};
|
|
3508
|
+
|
|
3509
|
+
const REGION_URL = '/api/v1/region';
|
|
3510
|
+
const LOCATION_STORAGE_KEY = 'location';
|
|
3511
|
+
function useLocation(defaultLocation = 'Москва') {
|
|
3512
|
+
const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
|
|
3513
|
+
const selectCurrentLocation = useCallback((_) => {
|
|
3514
|
+
storeLocation(_);
|
|
3515
|
+
fireCurrentLocation(_);
|
|
3516
|
+
}, []);
|
|
3517
|
+
const { data } = useAsyncData(REGION_URL, fetchJSONUnsafe);
|
|
3518
|
+
useEffect(() => {
|
|
3519
|
+
if (data && !hasStoredLocation()) {
|
|
3520
|
+
fireCurrentLocation(data);
|
|
3521
|
+
}
|
|
3522
|
+
}, [data]);
|
|
3523
|
+
return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
|
|
3524
|
+
}
|
|
3525
|
+
const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
|
|
3526
|
+
const restoreLocation = () => {
|
|
3527
|
+
try {
|
|
3528
|
+
const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
|
|
3529
|
+
return data && JSON.parse(data);
|
|
3530
|
+
}
|
|
3531
|
+
catch (ex) {
|
|
3532
|
+
return null;
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
const storeLocation = (_) => {
|
|
3536
|
+
try {
|
|
3537
|
+
globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
|
|
3538
|
+
}
|
|
3539
|
+
catch (ex) {
|
|
3540
|
+
// Do nothing
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
3543
|
+
|
|
3502
3544
|
var Currency;
|
|
3503
3545
|
(function (Currency) {
|
|
3504
3546
|
Currency["RUB"] = "RUB";
|
|
@@ -3629,40 +3671,15 @@
|
|
|
3629
3671
|
};
|
|
3630
3672
|
|
|
3631
3673
|
const EXCHANGE_RATES_URL = '/api/v1/exchangerates';
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
const { data } = useAsyncData(EXCHANGE_RATES_URL
|
|
3674
|
+
function useFetchExchangeRateData(currentRegion) {
|
|
3675
|
+
const regionCode = currentRegion?.code || '000';
|
|
3676
|
+
const { data } = useAsyncData(EXCHANGE_RATES_URL + `?regionCode=${regionCode}`, fetchJSONUnsafe);
|
|
3635
3677
|
return data || {};
|
|
3636
3678
|
}
|
|
3637
|
-
const fetchData = async (urlExchangeRates) => {
|
|
3638
|
-
const region = await fetchRegion();
|
|
3639
|
-
const regionCode = region?.code || '000';
|
|
3640
|
-
const exchangeRates = await fetchExchangeRates(urlExchangeRates, regionCode);
|
|
3641
|
-
return { region, exchangeRates };
|
|
3642
|
-
};
|
|
3643
|
-
const fetchRegion = async () => {
|
|
3644
|
-
try {
|
|
3645
|
-
return await fetchJSONUnsafe(REGION_URL$1, { method: 'GET' });
|
|
3646
|
-
}
|
|
3647
|
-
catch (error) {
|
|
3648
|
-
console.log(error);
|
|
3649
|
-
return {};
|
|
3650
|
-
}
|
|
3651
|
-
};
|
|
3652
|
-
const fetchExchangeRates = async (url, regionCode) => {
|
|
3653
|
-
try {
|
|
3654
|
-
return await fetchJSONUnsafe(url + `?regionCode=${regionCode}`, {
|
|
3655
|
-
method: 'GET',
|
|
3656
|
-
});
|
|
3657
|
-
}
|
|
3658
|
-
catch (error) {
|
|
3659
|
-
console.log(error);
|
|
3660
|
-
return {};
|
|
3661
|
-
}
|
|
3662
|
-
};
|
|
3663
3679
|
|
|
3664
3680
|
const ExchangeRateTile = JSX(({ className = '', title = 'Курсы обмена валют', button, ...rest }) => {
|
|
3665
|
-
const
|
|
3681
|
+
const [currentLocation] = useLocation();
|
|
3682
|
+
const exchangeRates = useFetchExchangeRateData(currentLocation);
|
|
3666
3683
|
const currencyRates = getCurrencyRates(exchangeRates?.exchangeRate?.currencies);
|
|
3667
3684
|
const currencyRatesBuy = currencyRates.filter((_) => _.buyExchangeRate);
|
|
3668
3685
|
currencyRatesBuy.unshift({ currency: { currency: Currency.RUB } });
|
|
@@ -4017,48 +4034,6 @@
|
|
|
4017
4034
|
? 'text-primary-main'
|
|
4018
4035
|
: style(flat ? 'text-primary-text' : 'text-secondary-text', 'hover:text-primary-main'), 'group-data-transparent:text-white group-data-transparent:hover:text-primary-hover');
|
|
4019
4036
|
|
|
4020
|
-
const useLatestEvent = (eventBus, type, initialEvent) => {
|
|
4021
|
-
const [latestEvent, setLatestEvent] = useState(initialEvent || null);
|
|
4022
|
-
useEffect(() => eventBus.subscribe(type, (_) => setLatestEvent(_)), [eventBus, type]);
|
|
4023
|
-
const fireEvent = useCallback((_) => eventBus.fire(type, _), [eventBus, type]);
|
|
4024
|
-
return [latestEvent, fireEvent];
|
|
4025
|
-
};
|
|
4026
|
-
|
|
4027
|
-
const REGION_URL = '/api/v1/region';
|
|
4028
|
-
const LOCATION_STORAGE_KEY = 'location';
|
|
4029
|
-
function useLocation(defaultLocation = 'Москва') {
|
|
4030
|
-
const [currentLocation, fireCurrentLocation] = useLatestEvent(defaultEventBus, 'location', restoreLocation() ?? { name: defaultLocation });
|
|
4031
|
-
const selectCurrentLocation = useCallback((_) => {
|
|
4032
|
-
storeLocation(_);
|
|
4033
|
-
fireCurrentLocation(_);
|
|
4034
|
-
}, []);
|
|
4035
|
-
const { data } = useAsyncData(REGION_URL, fetchJSONUnsafe);
|
|
4036
|
-
useEffect(() => {
|
|
4037
|
-
if (data && !hasStoredLocation()) {
|
|
4038
|
-
fireCurrentLocation(data);
|
|
4039
|
-
}
|
|
4040
|
-
}, [data]);
|
|
4041
|
-
return [currentLocation ?? { name: defaultLocation }, selectCurrentLocation];
|
|
4042
|
-
}
|
|
4043
|
-
const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
|
|
4044
|
-
const restoreLocation = () => {
|
|
4045
|
-
try {
|
|
4046
|
-
const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
|
|
4047
|
-
return data && JSON.parse(data);
|
|
4048
|
-
}
|
|
4049
|
-
catch (ex) {
|
|
4050
|
-
return null;
|
|
4051
|
-
}
|
|
4052
|
-
};
|
|
4053
|
-
const storeLocation = (_) => {
|
|
4054
|
-
try {
|
|
4055
|
-
globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
|
|
4056
|
-
}
|
|
4057
|
-
catch (ex) {
|
|
4058
|
-
// Do nothing
|
|
4059
|
-
}
|
|
4060
|
-
};
|
|
4061
|
-
|
|
4062
4037
|
const REGIONS_URL = '/api/v1/regions';
|
|
4063
4038
|
function useRegions() {
|
|
4064
4039
|
const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe);
|
|
@@ -5825,7 +5800,7 @@
|
|
|
5825
5800
|
return (jsx("div", { className: "flex items-end absolute bottom-0 right-0 h-full pointer-events-none", children: jsx(LikeControl, { className: "rounded-tl-3xl sticky bottom-0 pointer-events-auto" }) }));
|
|
5826
5801
|
}
|
|
5827
5802
|
|
|
5828
|
-
const packageVersion = "0.14.
|
|
5803
|
+
const packageVersion = "0.14.59";
|
|
5829
5804
|
|
|
5830
5805
|
exports.Blocks = Blocks;
|
|
5831
5806
|
exports.ContentPage = ContentPage;
|