@redneckz/wildless-cms-uni-blocks 0.14.102 → 0.14.103
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 +25 -21
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/bundle/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/bundle/utils/fetchJSON.d.ts +3 -2
- package/bundle/utils/fetchMultitudeJSON.d.ts +2 -1
- package/dist/components/Calculator/useCalculatorParams.js.map +1 -1
- package/dist/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/dist/components/DepositFiltration/getPeriod.js +8 -3
- package/dist/components/DepositFiltration/getPeriod.js.map +1 -1
- package/dist/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/dist/components/DepositFiltration/useDepositsPeriods.js.map +1 -1
- package/dist/components/Depository/useDepository.js.map +1 -1
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/dist/components/Footer/useFooterData.js.map +1 -1
- package/dist/components/OfficesAtmsMap/useAtms.js.map +1 -1
- package/dist/components/SafeDepositRental/useGetRegions.js.map +1 -1
- package/dist/hooks/useLocation.js +1 -1
- package/dist/hooks/useLocation.js.map +1 -1
- package/dist/hooks/useRegions.js.map +1 -1
- package/dist/hooks/useSWRResource.js.map +1 -1
- package/dist/utils/fetchJSON.d.ts +3 -2
- package/dist/utils/fetchJSON.js +3 -3
- package/dist/utils/fetchJSON.js.map +1 -1
- package/dist/utils/fetchMultitudeJSON.d.ts +2 -1
- package/dist/utils/fetchMultitudeJSON.js +2 -2
- package/dist/utils/fetchMultitudeJSON.js.map +1 -1
- package/lib/components/Calculator/useCalculatorParams.js.map +1 -1
- package/lib/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/lib/components/DepositFiltration/getPeriod.js +8 -3
- package/lib/components/DepositFiltration/getPeriod.js.map +1 -1
- package/lib/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/lib/components/DepositFiltration/useDepositsPeriods.js.map +1 -1
- package/lib/components/Depository/useDepository.js.map +1 -1
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/lib/components/Footer/useFooterData.js.map +1 -1
- package/lib/components/OfficesAtmsMap/useAtms.js.map +1 -1
- package/lib/components/SafeDepositRental/useGetRegions.js.map +1 -1
- package/lib/hooks/useLocation.js +1 -1
- package/lib/hooks/useLocation.js.map +1 -1
- package/lib/hooks/useRegions.js.map +1 -1
- package/lib/hooks/useSWRResource.js.map +1 -1
- package/lib/utils/fetchJSON.d.ts +3 -2
- package/lib/utils/fetchJSON.js +2 -2
- package/lib/utils/fetchJSON.js.map +1 -1
- package/lib/utils/fetchMultitudeJSON.d.ts +2 -1
- package/lib/utils/fetchMultitudeJSON.js +2 -2
- package/lib/utils/fetchMultitudeJSON.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +25 -21
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/mobile/bundle/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/mobile/bundle/utils/fetchJSON.d.ts +3 -2
- package/mobile/bundle/utils/fetchMultitudeJSON.d.ts +2 -1
- package/mobile/dist/components/Calculator/useCalculatorParams.js.map +1 -1
- package/mobile/dist/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/mobile/dist/components/DepositFiltration/getPeriod.js +8 -3
- package/mobile/dist/components/DepositFiltration/getPeriod.js.map +1 -1
- package/mobile/dist/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/mobile/dist/components/DepositFiltration/useDepositsPeriods.js.map +1 -1
- package/mobile/dist/components/Depository/useDepository.js.map +1 -1
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/dist/components/Footer/useFooterData.js.map +1 -1
- package/mobile/dist/components/OfficesAtmsMap/useAtms.js.map +1 -1
- package/mobile/dist/components/SafeDepositRental/useGetRegions.js.map +1 -1
- package/mobile/dist/hooks/useLocation.js +1 -1
- package/mobile/dist/hooks/useLocation.js.map +1 -1
- package/mobile/dist/hooks/useRegions.js.map +1 -1
- package/mobile/dist/hooks/useSWRResource.js.map +1 -1
- package/mobile/dist/utils/fetchJSON.d.ts +3 -2
- package/mobile/dist/utils/fetchJSON.js +3 -3
- package/mobile/dist/utils/fetchJSON.js.map +1 -1
- package/mobile/dist/utils/fetchMultitudeJSON.d.ts +2 -1
- package/mobile/dist/utils/fetchMultitudeJSON.js +2 -2
- package/mobile/dist/utils/fetchMultitudeJSON.js.map +1 -1
- package/mobile/lib/components/Calculator/useCalculatorParams.js.map +1 -1
- package/mobile/lib/components/DepositFiltration/getPeriod.d.ts +1 -1
- package/mobile/lib/components/DepositFiltration/getPeriod.js +8 -3
- package/mobile/lib/components/DepositFiltration/getPeriod.js.map +1 -1
- package/mobile/lib/components/DepositFiltration/useDepositsPeriods.d.ts +1 -1
- package/mobile/lib/components/DepositFiltration/useDepositsPeriods.js.map +1 -1
- package/mobile/lib/components/Depository/useDepository.js.map +1 -1
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/lib/components/Footer/useFooterData.js.map +1 -1
- package/mobile/lib/components/OfficesAtmsMap/useAtms.js.map +1 -1
- package/mobile/lib/components/SafeDepositRental/useGetRegions.js.map +1 -1
- package/mobile/lib/hooks/useLocation.js +1 -1
- package/mobile/lib/hooks/useLocation.js.map +1 -1
- package/mobile/lib/hooks/useRegions.js.map +1 -1
- package/mobile/lib/hooks/useSWRResource.js.map +1 -1
- package/mobile/lib/utils/fetchJSON.d.ts +3 -2
- package/mobile/lib/utils/fetchJSON.js +2 -2
- package/mobile/lib/utils/fetchJSON.js.map +1 -1
- package/mobile/lib/utils/fetchMultitudeJSON.d.ts +2 -1
- package/mobile/lib/utils/fetchMultitudeJSON.js +2 -2
- package/mobile/lib/utils/fetchMultitudeJSON.js.map +1 -1
- package/mobile/src/components/Calculator/useCalculatorParams.ts +5 -2
- package/mobile/src/components/DepositFiltration/getPeriod.ts +10 -5
- package/mobile/src/components/DepositFiltration/useDepositsPeriods.ts +4 -6
- package/mobile/src/components/Depository/useDepository.ts +5 -2
- package/mobile/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +3 -3
- package/mobile/src/components/Footer/useFooterData.ts +3 -3
- package/mobile/src/components/OfficesAtmsMap/useAtms.ts +1 -4
- package/mobile/src/components/OfficesAtmsMap/useOffices.ts +1 -1
- package/mobile/src/components/SafeDepositRental/useGetRegions.ts +2 -2
- package/mobile/src/components/SafeDepositRental/useSafeBoxes.ts +1 -1
- package/mobile/src/hooks/useBranches.ts +1 -1
- package/mobile/src/hooks/useLocation.ts +5 -2
- package/mobile/src/hooks/useRegions.ts +2 -2
- package/mobile/src/hooks/useSWRResource.ts +8 -4
- package/mobile/src/utils/fetchJSON.ts +5 -6
- package/mobile/src/utils/fetchMultitudeJSON.ts +5 -5
- package/package.json +2 -2
- package/src/components/Calculator/useCalculatorParams.ts +5 -2
- package/src/components/DepositFiltration/getPeriod.ts +10 -5
- package/src/components/DepositFiltration/useDepositsPeriods.ts +4 -6
- package/src/components/Depository/useDepository.ts +5 -2
- package/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +3 -3
- package/src/components/Footer/useFooterData.ts +3 -3
- package/src/components/OfficesAtmsMap/useAtms.ts +1 -4
- package/src/components/OfficesAtmsMap/useOffices.ts +1 -1
- package/src/components/SafeDepositRental/useGetRegions.ts +2 -2
- package/src/components/SafeDepositRental/useSafeBoxes.ts +1 -1
- package/src/hooks/useBranches.ts +1 -1
- package/src/hooks/useLocation.ts +5 -2
- package/src/hooks/useRegions.ts +2 -2
- package/src/hooks/useSWRResource.ts +8 -4
- package/src/utils/fetchJSON.ts +5 -6
- package/src/utils/fetchMultitudeJSON.ts +5 -5
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
|
2
2
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
3
3
|
import { defaultEventBus } from '../EventBus/defaultEventBus';
|
|
4
4
|
import { useLatestEvent } from '../EventBus/useLatestEvent';
|
|
5
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
5
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
6
6
|
|
|
7
7
|
const REGION_URL = '/api/v1/region';
|
|
8
8
|
|
|
@@ -26,7 +26,10 @@ export function useLocation(defaultLocation = 'Москва'): [RegionData, (_:
|
|
|
26
26
|
fireCurrentLocation(_);
|
|
27
27
|
}, []);
|
|
28
28
|
|
|
29
|
-
const { data } = useAsyncData
|
|
29
|
+
const { data } = useAsyncData(
|
|
30
|
+
hasStoredLocation() ? null : REGION_URL,
|
|
31
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<RegionData>,
|
|
32
|
+
);
|
|
30
33
|
useEffect(() => {
|
|
31
34
|
if (data && !hasStoredLocation()) {
|
|
32
35
|
fireCurrentLocation(data);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
2
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
3
3
|
|
|
4
4
|
const REGIONS_URL = '/api/v1/regions';
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export interface Region {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function useRegions(): Region[] {
|
|
13
|
-
const { data } = useAsyncData<Region[]>
|
|
13
|
+
const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe as FetchJSONUnsafeType<Region[]>);
|
|
14
14
|
|
|
15
15
|
return data || [];
|
|
16
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type Fallback } from '../model/Fallback';
|
|
3
3
|
import { projectSettings } from '../ProjectSettings';
|
|
4
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
4
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
5
5
|
import { joinPath } from '../utils/url';
|
|
6
6
|
|
|
7
7
|
const EMPTY_VALUE = {};
|
|
@@ -26,9 +26,13 @@ export function useSWRResource<Data>(
|
|
|
26
26
|
`${filename}.json`,
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
const { data } = useAsyncData
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const { data } = useAsyncData(
|
|
30
|
+
filename ? path : null,
|
|
31
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<Data>,
|
|
32
|
+
{
|
|
33
|
+
fallback,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
32
36
|
|
|
33
37
|
return data || (EMPTY_VALUE as Data);
|
|
34
38
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export async function fetchJSON<R =
|
|
2
|
-
url: string,
|
|
3
|
-
options?: RequestInit,
|
|
4
|
-
): Promise<R | null> {
|
|
1
|
+
export async function fetchJSON<R = any>(url: string, options?: RequestInit): Promise<R | null> {
|
|
5
2
|
try {
|
|
6
3
|
return url ? await fetchJSONUnsafe(url, options) : null;
|
|
7
4
|
} catch (err) {
|
|
@@ -11,7 +8,9 @@ export async function fetchJSON<R = unknown>(
|
|
|
11
8
|
return null;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
export
|
|
11
|
+
export type FetchJSONUnsafeType<R> = (url: string, options?: RequestInit) => Promise<R>;
|
|
12
|
+
|
|
13
|
+
export const fetchJSONUnsafe: FetchJSONUnsafeType<any> = async (url, options) => {
|
|
15
14
|
const response = await fetch(url, {
|
|
16
15
|
...options,
|
|
17
16
|
headers: {
|
|
@@ -21,4 +20,4 @@ export async function fetchJSONUnsafe<R = unknown>(url: string, options?: Reques
|
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
return response.json();
|
|
24
|
-
}
|
|
23
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fetchJSON } from './fetchJSON';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const fetchPromises = urls.map((url) => fetchJSON
|
|
3
|
+
export type FetchMultitudeJSONType<R> = (...urls: string[]) => Promise<Awaited<R | null>[]>;
|
|
4
|
+
|
|
5
|
+
export const fetchMultitudeJSON: FetchMultitudeJSONType<any> = (...urls) => {
|
|
6
|
+
const fetchPromises = urls.map((url) => fetchJSON(url));
|
|
7
7
|
|
|
8
8
|
return Promise.all(fetchPromises);
|
|
9
|
-
}
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redneckz/wildless-cms-uni-blocks",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.103",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ЦК",
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
135
|
"@redneckz/json-ref": "^0.0.2",
|
|
136
|
-
"@redneckz/uni-jsx": "^2.6.
|
|
136
|
+
"@redneckz/uni-jsx": "^2.6.2",
|
|
137
137
|
"@tailwindcss/container-queries": "^0.1.0",
|
|
138
138
|
"@types/json-schema": "^7.0.11",
|
|
139
139
|
"glob": "^8.0.3",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
|
-
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
2
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
3
3
|
|
|
4
4
|
export function useCalculatorParams<Data>(dir: string) {
|
|
5
|
-
const { data } = useAsyncData
|
|
5
|
+
const { data } = useAsyncData(
|
|
6
|
+
`/wcms-resources/${dir}.json`,
|
|
7
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<Data>,
|
|
8
|
+
);
|
|
6
9
|
|
|
7
10
|
return data;
|
|
8
11
|
}
|
|
@@ -2,9 +2,14 @@ export interface SourceItem {
|
|
|
2
2
|
rateRows: Array<{ minMonths?: number; maxMonths?: number }>;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
type Source = Record<string, SourceItem>;
|
|
5
|
+
type Source = Record<string, SourceItem | null>;
|
|
6
6
|
|
|
7
|
-
export const getPeriod = (source: Source, content: Record<string, any>): number[] =>
|
|
8
|
-
source[content?.sourceBook]
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const getPeriod = (source: Source, content: Record<string, any>): number[] => {
|
|
8
|
+
const sourceItem = source[content?.sourceBook];
|
|
9
|
+
|
|
10
|
+
return sourceItem
|
|
11
|
+
? sourceItem?.rateRows
|
|
12
|
+
.map((el) => el.minMonths)
|
|
13
|
+
.filter((minMonths): minMonths is number => minMonths !== undefined)
|
|
14
|
+
: [];
|
|
15
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
3
3
|
import { type BlockDef } from '../../model/ContentPageDef';
|
|
4
|
-
import { fetchMultitudeJSON } from '../../utils/fetchMultitudeJSON';
|
|
4
|
+
import { fetchMultitudeJSON, type FetchMultitudeJSONType } from '../../utils/fetchMultitudeJSON';
|
|
5
5
|
import { unique } from '../../utils/unique';
|
|
6
6
|
import { zip } from '../../utils/zip';
|
|
7
7
|
import { getChildSourceBook } from './getChildSourceBook';
|
|
@@ -14,15 +14,13 @@ export function useDepositsPeriods(blocks: BlockDef[] | undefined) {
|
|
|
14
14
|
return { dirs: sourceBooks?.map((url) => `/wcms-resources/${url}.json`), source: sourceBooks };
|
|
15
15
|
}, [blocks]);
|
|
16
16
|
|
|
17
|
-
const { data = [] } = useAsyncData
|
|
17
|
+
const { data = [] } = useAsyncData(
|
|
18
18
|
dirs,
|
|
19
|
-
fetchMultitudeJSON
|
|
19
|
+
fetchMultitudeJSON as FetchMultitudeJSONType<SourceItem>,
|
|
20
20
|
);
|
|
21
21
|
|
|
22
22
|
return {
|
|
23
|
-
source: Object.fromEntries(
|
|
24
|
-
zip(source, data as SourceItem[]).filter(([, sourceData]) => Boolean(sourceData)),
|
|
25
|
-
),
|
|
23
|
+
source: Object.fromEntries(zip(source, data).filter(([, sourceData]) => Boolean(sourceData))),
|
|
26
24
|
months:
|
|
27
25
|
unique(
|
|
28
26
|
data
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
|
-
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
2
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
3
3
|
import { formatDate } from '../../utils/formatDate';
|
|
4
4
|
import { type DepositoryFiltrationState } from './Depository';
|
|
5
5
|
|
|
@@ -35,7 +35,10 @@ export const useDepository = ({ size, page, query, startDate, endDate }: UseDepo
|
|
|
35
35
|
|
|
36
36
|
const queryString = `?${searchParams.toString()}`;
|
|
37
37
|
|
|
38
|
-
const { data } = useAsyncData
|
|
38
|
+
const { data } = useAsyncData(
|
|
39
|
+
DEPOSITARY_URL + queryString,
|
|
40
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<DepositoryData>,
|
|
41
|
+
);
|
|
39
42
|
|
|
40
43
|
return { items: data?.content, totalPages: data?.totalPages };
|
|
41
44
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type ExchangeCurrencyItem } from '../../components/ExchangeRateTile/ExchangeCurrencyCalculator';
|
|
3
3
|
import { type RegionData } from '../../hooks/useLocation';
|
|
4
|
-
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
4
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
5
5
|
|
|
6
6
|
export interface ExchangeData {
|
|
7
7
|
exchangeRate?: {
|
|
@@ -15,9 +15,9 @@ const EXCHANGE_RATES_URL = '/api/v1/exchangerates';
|
|
|
15
15
|
export function useFetchExchangeRateData(currentRegion: RegionData) {
|
|
16
16
|
const regionCode = currentRegion?.code || '000';
|
|
17
17
|
|
|
18
|
-
const { data } = useAsyncData
|
|
18
|
+
const { data } = useAsyncData(
|
|
19
19
|
EXCHANGE_RATES_URL + `?regionCode=${regionCode}`,
|
|
20
|
-
fetchJSONUnsafe
|
|
20
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<ExchangeData>,
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
return data || {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type FooterContent } from '../../components/Footer/FooterContent';
|
|
3
3
|
import { projectSettings } from '../../ProjectSettings';
|
|
4
|
-
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
4
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
5
5
|
|
|
6
6
|
export function useFooterData(): FooterContent {
|
|
7
|
-
const { data } = useAsyncData
|
|
7
|
+
const { data } = useAsyncData(
|
|
8
8
|
`/wcms-resources/${projectSettings.FOOTER || 'footer'}.json`,
|
|
9
|
-
fetchJSONUnsafe
|
|
9
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<FooterContent>,
|
|
10
10
|
);
|
|
11
11
|
|
|
12
12
|
return data || {};
|
|
@@ -5,10 +5,7 @@ import { type Atm } from './OfficesAtmsMapProps';
|
|
|
5
5
|
const EMPTY_VALUE = [];
|
|
6
6
|
|
|
7
7
|
export function useAtms(regionCode?: string) {
|
|
8
|
-
const { data = EMPTY_VALUE } = useAsyncData
|
|
9
|
-
`/api/v1/atms?regionCode=${regionCode}`,
|
|
10
|
-
fetchMap,
|
|
11
|
-
);
|
|
8
|
+
const { data = EMPTY_VALUE } = useAsyncData(`/api/v1/atms?regionCode=${regionCode}`, fetchMap);
|
|
12
9
|
|
|
13
10
|
return data;
|
|
14
11
|
}
|
|
@@ -5,7 +5,7 @@ import { type Branch } from './OfficesAtmsMapProps';
|
|
|
5
5
|
const EMPTY_VALUE = [];
|
|
6
6
|
|
|
7
7
|
export function useOffices(regionCode?: string) {
|
|
8
|
-
const { data = EMPTY_VALUE } = useAsyncData
|
|
8
|
+
const { data = EMPTY_VALUE } = useAsyncData(
|
|
9
9
|
`/api/v1/branches?regionCode=${regionCode}`,
|
|
10
10
|
fetchMap,
|
|
11
11
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
|
-
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
2
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
3
3
|
|
|
4
4
|
const REGIONS_URL = '/api/v1/regions';
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export interface Region {
|
|
|
12
12
|
const EMPTY_VALUE = [];
|
|
13
13
|
|
|
14
14
|
export function useGetRegions(): Region[] {
|
|
15
|
-
const { data } = useAsyncData<Region[]>
|
|
15
|
+
const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe as FetchJSONUnsafeType<Region[]>);
|
|
16
16
|
|
|
17
17
|
return data || EMPTY_VALUE;
|
|
18
18
|
}
|
|
@@ -28,7 +28,7 @@ const SAFEBOXES_URL = '/api/v1/safeboxes';
|
|
|
28
28
|
const EMPTY_VALUE = [];
|
|
29
29
|
|
|
30
30
|
export function useSafeBoxes(regionCode?: string): Branch[] {
|
|
31
|
-
const { data } = useAsyncData
|
|
31
|
+
const { data } = useAsyncData(
|
|
32
32
|
regionCode ? `${SAFEBOXES_URL}?regionCode=${regionCode}` : null,
|
|
33
33
|
fetchSafeBoxes,
|
|
34
34
|
);
|
package/src/hooks/useBranches.ts
CHANGED
|
@@ -28,7 +28,7 @@ const BRANCHES_URL = '/api/v1/branches';
|
|
|
28
28
|
const EMPTY_VALUE = [];
|
|
29
29
|
|
|
30
30
|
export function useBranches(regionCode?: string): Branch[] {
|
|
31
|
-
const { data } = useAsyncData
|
|
31
|
+
const { data } = useAsyncData(
|
|
32
32
|
regionCode ? `${BRANCHES_URL}?regionCode=${regionCode}` : null,
|
|
33
33
|
fetchSafeBoxes,
|
|
34
34
|
);
|
package/src/hooks/useLocation.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
|
2
2
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
3
3
|
import { defaultEventBus } from '../EventBus/defaultEventBus';
|
|
4
4
|
import { useLatestEvent } from '../EventBus/useLatestEvent';
|
|
5
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
5
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
6
6
|
|
|
7
7
|
const REGION_URL = '/api/v1/region';
|
|
8
8
|
|
|
@@ -26,7 +26,10 @@ export function useLocation(defaultLocation = 'Москва'): [RegionData, (_:
|
|
|
26
26
|
fireCurrentLocation(_);
|
|
27
27
|
}, []);
|
|
28
28
|
|
|
29
|
-
const { data } = useAsyncData
|
|
29
|
+
const { data } = useAsyncData(
|
|
30
|
+
hasStoredLocation() ? null : REGION_URL,
|
|
31
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<RegionData>,
|
|
32
|
+
);
|
|
30
33
|
useEffect(() => {
|
|
31
34
|
if (data && !hasStoredLocation()) {
|
|
32
35
|
fireCurrentLocation(data);
|
package/src/hooks/useRegions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
2
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
3
3
|
|
|
4
4
|
const REGIONS_URL = '/api/v1/regions';
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export interface Region {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function useRegions(): Region[] {
|
|
13
|
-
const { data } = useAsyncData<Region[]>
|
|
13
|
+
const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe as FetchJSONUnsafeType<Region[]>);
|
|
14
14
|
|
|
15
15
|
return data || [];
|
|
16
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type Fallback } from '../model/Fallback';
|
|
3
3
|
import { projectSettings } from '../ProjectSettings';
|
|
4
|
-
import { fetchJSONUnsafe } from '../utils/fetchJSON';
|
|
4
|
+
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
5
5
|
import { joinPath } from '../utils/url';
|
|
6
6
|
|
|
7
7
|
const EMPTY_VALUE = {};
|
|
@@ -26,9 +26,13 @@ export function useSWRResource<Data>(
|
|
|
26
26
|
`${filename}.json`,
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
const { data } = useAsyncData
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const { data } = useAsyncData(
|
|
30
|
+
filename ? path : null,
|
|
31
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<Data>,
|
|
32
|
+
{
|
|
33
|
+
fallback,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
32
36
|
|
|
33
37
|
return data || (EMPTY_VALUE as Data);
|
|
34
38
|
}
|
package/src/utils/fetchJSON.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export async function fetchJSON<R =
|
|
2
|
-
url: string,
|
|
3
|
-
options?: RequestInit,
|
|
4
|
-
): Promise<R | null> {
|
|
1
|
+
export async function fetchJSON<R = any>(url: string, options?: RequestInit): Promise<R | null> {
|
|
5
2
|
try {
|
|
6
3
|
return url ? await fetchJSONUnsafe(url, options) : null;
|
|
7
4
|
} catch (err) {
|
|
@@ -11,7 +8,9 @@ export async function fetchJSON<R = unknown>(
|
|
|
11
8
|
return null;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
|
-
export
|
|
11
|
+
export type FetchJSONUnsafeType<R> = (url: string, options?: RequestInit) => Promise<R>;
|
|
12
|
+
|
|
13
|
+
export const fetchJSONUnsafe: FetchJSONUnsafeType<any> = async (url, options) => {
|
|
15
14
|
const response = await fetch(url, {
|
|
16
15
|
...options,
|
|
17
16
|
headers: {
|
|
@@ -21,4 +20,4 @@ export async function fetchJSONUnsafe<R = unknown>(url: string, options?: Reques
|
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
return response.json();
|
|
24
|
-
}
|
|
23
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fetchJSON } from './fetchJSON';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const fetchPromises = urls.map((url) => fetchJSON
|
|
3
|
+
export type FetchMultitudeJSONType<R> = (...urls: string[]) => Promise<Awaited<R | null>[]>;
|
|
4
|
+
|
|
5
|
+
export const fetchMultitudeJSON: FetchMultitudeJSONType<any> = (...urls) => {
|
|
6
|
+
const fetchPromises = urls.map((url) => fetchJSON(url));
|
|
7
7
|
|
|
8
8
|
return Promise.all(fetchPromises);
|
|
9
|
-
}
|
|
9
|
+
};
|