@eohjsc/react-native-smart-city 0.7.24 → 0.7.26
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/index.js +2 -0
- package/package.json +1 -1
- package/src/Images/Common/search-menu.svg +7 -0
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplateStyle.js +2 -1
- package/src/commons/ActionGroup/OneBigButtonTemplateStyle.js +1 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -3
- package/src/commons/ActionGroup/TerminalBoxTemplate.js +1 -4
- package/src/commons/ActionGroup/TextBoxTemplate.js +1 -5
- package/src/commons/ActionGroup/ThreeButtonTemplate/components/ThreeButtonDefaultStyles.js +1 -1
- package/src/commons/ActionGroup/__test__/index.test.js +51 -0
- package/src/commons/ActionGroup/index.js +4 -0
- package/src/commons/Dashboard/MyDashboardDevice/__test__/index.test.js +171 -0
- package/src/commons/Dashboard/MyDashboardDevice/index.js +218 -0
- package/src/commons/Dashboard/MyDashboardDevice/styles.js +60 -0
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +0 -10
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +114 -48
- package/src/commons/Dashboard/MyUnit/index.js +74 -27
- package/src/commons/Dashboard/MyUnit/styles.js +16 -1
- package/src/commons/DateTimeRangeChange/index.js +1 -1
- package/src/commons/Device/ItemDevice.js +12 -3
- package/src/commons/Device/ItemDeviceWrapper.js +10 -2
- package/src/commons/SelectUnit/index.js +19 -5
- package/src/commons/SelectUnit/styles.js +0 -1
- package/src/commons/SubUnit/DeviceTemplate/DeviceTemplate.js +8 -3
- package/src/commons/Widgets/IFrame/IFrameStyles.js +1 -0
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfigStyles.js +1 -0
- package/src/configs/API.js +11 -0
- package/src/configs/AccessibilityLabel.js +2 -0
- package/src/configs/Constants.js +3 -0
- package/src/context/actionType.ts +4 -0
- package/src/context/mockStore.ts +5 -0
- package/src/context/reducer.ts +30 -5
- package/src/iot/mqtt.js +163 -47
- package/src/navigations/UnitStack.js +22 -0
- package/src/screens/Device/__test__/detail.test.js +42 -1
- package/src/screens/Device/__test__/mqttDetail.test.js +411 -190
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +27 -0
- package/src/screens/Device/components/DonutChart.js +5 -14
- package/src/screens/Device/components/SensorDisplayItem.js +92 -61
- package/src/screens/Device/components/VisualChart.js +0 -12
- package/src/screens/Device/detail.js +50 -14
- package/src/screens/Device/hooks/useDashboardDevice.js +34 -0
- package/src/screens/Device/styles.js +16 -0
- package/src/screens/SubUnit/AddSubUnit.js +18 -8
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +5 -3
- package/src/screens/Unit/GoToDetailUnit.js +30 -0
- package/src/screens/Unit/__test__/GoToDetailUnit.test.js +103 -0
- package/src/utils/FactoryGateway.js +105 -0
- package/src/utils/I18n/translations/en.js +4 -0
- package/src/utils/I18n/translations/vi.js +4 -0
- package/src/utils/Route/index.js +1 -0
- package/src/utils/Storage.js +18 -4
- package/src/utils/Utils.js +2 -1
- package/src/utils/Functions/preloadImages.js +0 -38
|
@@ -13,11 +13,14 @@ import _TextInput from '../../commons/Form/TextInput';
|
|
|
13
13
|
import Text from '../../commons/Text';
|
|
14
14
|
import { API, Colors } from '../../configs';
|
|
15
15
|
import { AccessibilityLabel } from '../../configs/Constants';
|
|
16
|
-
import { useSCContextSelector } from '../../context';
|
|
17
16
|
import useKeyboardShow from '../../hooks/Common/useKeyboardShow';
|
|
18
17
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
19
18
|
import { replace } from '../../navigations/utils';
|
|
20
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
axiosPost,
|
|
21
|
+
createFormData,
|
|
22
|
+
fetchWithCache,
|
|
23
|
+
} from '../../utils/Apis/axios';
|
|
21
24
|
import { useBackendPermission } from '../../utils/Permission/backend';
|
|
22
25
|
import Routes from '../../utils/Route';
|
|
23
26
|
import { ToastBottomHelper } from '../../utils/Utils';
|
|
@@ -29,7 +32,6 @@ const AddSubUnit = ({ route }) => {
|
|
|
29
32
|
const { dismissKeyboard } = useKeyboardShow();
|
|
30
33
|
const { navigate, goBack, dispatch } = useNavigation();
|
|
31
34
|
const permissions = useBackendPermission();
|
|
32
|
-
const myUnits = useSCContextSelector((state) => state.myUnits);
|
|
33
35
|
|
|
34
36
|
const {
|
|
35
37
|
unit,
|
|
@@ -42,11 +44,15 @@ const AddSubUnit = ({ route }) => {
|
|
|
42
44
|
const [wallpaper, setWallpaper] = useState('');
|
|
43
45
|
const [imageUrl, setImageUrl] = useState('');
|
|
44
46
|
const [showImagePicker, setShowImagePicker] = useState(false);
|
|
47
|
+
const [unitDetail, setUnitDetail] = useState({});
|
|
45
48
|
let awaitCreate = useRef(false);
|
|
46
49
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const fetchUnitDetail = useCallback(async () => {
|
|
51
|
+
await fetchWithCache(API.UNIT.UNIT_DETAIL(unit?.id), {}, (response) => {
|
|
52
|
+
const { success, data } = response;
|
|
53
|
+
success && setUnitDetail(data);
|
|
54
|
+
});
|
|
55
|
+
}, [unit?.id]);
|
|
50
56
|
|
|
51
57
|
const cleanData = () => {
|
|
52
58
|
setRoomName('');
|
|
@@ -133,7 +139,7 @@ const AddSubUnit = ({ route }) => {
|
|
|
133
139
|
} else {
|
|
134
140
|
awaitCreate.current = false;
|
|
135
141
|
if (
|
|
136
|
-
|
|
142
|
+
unitDetail?.stations?.length >= permissions?.max_stations_per_unit
|
|
137
143
|
) {
|
|
138
144
|
ToastBottomHelper.error(
|
|
139
145
|
t('reach_max_stations_per_unit', {
|
|
@@ -159,7 +165,7 @@ const AddSubUnit = ({ route }) => {
|
|
|
159
165
|
goBack,
|
|
160
166
|
navigate,
|
|
161
167
|
route.params,
|
|
162
|
-
|
|
168
|
+
unitDetail?.stations?.length,
|
|
163
169
|
permissions?.max_stations_per_unit,
|
|
164
170
|
]);
|
|
165
171
|
|
|
@@ -174,6 +180,10 @@ const AddSubUnit = ({ route }) => {
|
|
|
174
180
|
}
|
|
175
181
|
}, [imageUrl]);
|
|
176
182
|
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
fetchUnitDetail();
|
|
185
|
+
}, [fetchUnitDetail]);
|
|
186
|
+
|
|
177
187
|
const onChangeRoomName = useCallback(
|
|
178
188
|
(value) => {
|
|
179
189
|
setRoomName(value);
|
|
@@ -295,6 +295,11 @@ describe('Test AddSubUnit', () => {
|
|
|
295
295
|
isInsideUnit: false,
|
|
296
296
|
};
|
|
297
297
|
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
298
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(200, {
|
|
299
|
+
id: 1,
|
|
300
|
+
name: 'unit 1',
|
|
301
|
+
stations: [{ id: 1, name: 'station' }],
|
|
302
|
+
});
|
|
298
303
|
mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT(1)).reply(400, {});
|
|
299
304
|
await act(async () => {
|
|
300
305
|
tree = await create(
|
|
@@ -308,9 +313,6 @@ describe('Test AddSubUnit', () => {
|
|
|
308
313
|
},
|
|
309
314
|
},
|
|
310
315
|
},
|
|
311
|
-
myUnits: [
|
|
312
|
-
{ id: 1, name: 'unit 1', stations: [{ id: 1, name: 'station' }] },
|
|
313
|
-
],
|
|
314
316
|
})
|
|
315
317
|
);
|
|
316
318
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useNavigation } from '@react-navigation/native';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
import Routes from '../../utils/Route';
|
|
5
|
+
import SelectUnit from '../../commons/SelectUnit';
|
|
6
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
7
|
+
|
|
8
|
+
const GoToDetailUnit = () => {
|
|
9
|
+
const t = useTranslations();
|
|
10
|
+
const navigation = useNavigation();
|
|
11
|
+
|
|
12
|
+
const goToDetail = useCallback(
|
|
13
|
+
(item) => {
|
|
14
|
+
navigation.navigate(Routes.UnitDetail, {
|
|
15
|
+
unitId: item.id,
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
[navigation]
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<SelectUnit
|
|
23
|
+
title={t('text_select_a_unit')}
|
|
24
|
+
subTitle={t('text_select_go_to_unit_detail')}
|
|
25
|
+
onPressNext={goToDetail}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default GoToDetailUnit;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useNavigation } from '@react-navigation/native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import renderer, { act } from 'react-test-renderer';
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
import GoToDetailUnit from '../GoToDetailUnit';
|
|
9
|
+
import { Search } from '../../../commons/DevMode';
|
|
10
|
+
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
11
|
+
import Routes from '../../../utils/Route';
|
|
12
|
+
import api from '../../../utils/Apis/axios';
|
|
13
|
+
import { API } from '../../../configs';
|
|
14
|
+
|
|
15
|
+
const wrapComponent = () => (
|
|
16
|
+
<SCProvider initState={mockSCStore({})}>
|
|
17
|
+
<GoToDetailUnit />
|
|
18
|
+
</SCProvider>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
22
|
+
|
|
23
|
+
describe('Test GoToDetailUnit', () => {
|
|
24
|
+
let tree;
|
|
25
|
+
const data = [
|
|
26
|
+
{
|
|
27
|
+
id: 1,
|
|
28
|
+
name: 'Name 1',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 2,
|
|
32
|
+
name: 'Name 2',
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const mockedNavigate = useNavigation().navigate;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
mockedNavigate.mockReset();
|
|
39
|
+
mock.resetHistory();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('test render and navigate', async () => {
|
|
43
|
+
mock.onGet(API.SHARE.UNITS()).reply(200, data);
|
|
44
|
+
await act(async () => {
|
|
45
|
+
tree = await renderer.create(wrapComponent());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const instance = tree.root;
|
|
49
|
+
const unitItems = instance.findAllByProps({
|
|
50
|
+
accessibilityLabel: AccessibilityLabel.ITEM_UNIT,
|
|
51
|
+
});
|
|
52
|
+
expect(unitItems).toHaveLength(2);
|
|
53
|
+
const selectUnit = instance.findByProps({
|
|
54
|
+
accessibilityLabel: `${AccessibilityLabel.SELECT_UNIT_SELECT}-1`,
|
|
55
|
+
});
|
|
56
|
+
await act(async () => {
|
|
57
|
+
await selectUnit.props.onPress();
|
|
58
|
+
});
|
|
59
|
+
const rightClick = instance.findByProps({
|
|
60
|
+
accessibilityLabelPrefix: AccessibilityLabel.PREFIX.SELECT_UNIT,
|
|
61
|
+
});
|
|
62
|
+
await act(async () => {
|
|
63
|
+
await rightClick.props.onRightClick();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.UnitDetail, {
|
|
67
|
+
unitId: 1,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('test filter unit by name', async () => {
|
|
72
|
+
mock.onGet(API.SHARE.UNITS()).reply(200, data);
|
|
73
|
+
await act(async () => {
|
|
74
|
+
tree = await renderer.create(wrapComponent());
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const instance = tree.root;
|
|
78
|
+
const search = instance.findByType(Search);
|
|
79
|
+
await act(() => {
|
|
80
|
+
search.props.onSearch('Name 2');
|
|
81
|
+
});
|
|
82
|
+
const unitItems = instance.findAllByProps({
|
|
83
|
+
accessibilityLabel: AccessibilityLabel.ITEM_UNIT,
|
|
84
|
+
});
|
|
85
|
+
expect(unitItems).toHaveLength(1);
|
|
86
|
+
const selectUnit = instance.findByProps({
|
|
87
|
+
accessibilityLabel: `${AccessibilityLabel.SELECT_UNIT_SELECT}-2`,
|
|
88
|
+
});
|
|
89
|
+
await act(async () => {
|
|
90
|
+
await selectUnit.props.onPress();
|
|
91
|
+
});
|
|
92
|
+
const rightClick = instance.findByProps({
|
|
93
|
+
accessibilityLabelPrefix: AccessibilityLabel.PREFIX.SELECT_UNIT,
|
|
94
|
+
});
|
|
95
|
+
await act(async () => {
|
|
96
|
+
await rightClick.props.onRightClick();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(global.mockedNavigate).toHaveBeenCalledWith(Routes.UnitDetail, {
|
|
100
|
+
unitId: 2,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -423,6 +423,90 @@ export const gatewayDataFactory = {
|
|
|
423
423
|
chip: 7689,
|
|
424
424
|
icon_kit: null,
|
|
425
425
|
},
|
|
426
|
+
{
|
|
427
|
+
// Third Party
|
|
428
|
+
id: 9,
|
|
429
|
+
configs: [
|
|
430
|
+
{
|
|
431
|
+
id: 37,
|
|
432
|
+
status_texts: [],
|
|
433
|
+
is_on: false,
|
|
434
|
+
get_value_unit: '',
|
|
435
|
+
period_configs: [],
|
|
436
|
+
auto_triggers: [],
|
|
437
|
+
spotsensorconnect: null,
|
|
438
|
+
last_maxmin: null,
|
|
439
|
+
user_receive_email: [],
|
|
440
|
+
phone_send_sms: [],
|
|
441
|
+
status_configuration: {},
|
|
442
|
+
is_auto_release: false,
|
|
443
|
+
related_actions: [],
|
|
444
|
+
active: true,
|
|
445
|
+
name: 'LED',
|
|
446
|
+
is_read: true,
|
|
447
|
+
is_write: true,
|
|
448
|
+
range_min: null,
|
|
449
|
+
range_max: null,
|
|
450
|
+
unit: '',
|
|
451
|
+
scale: 1,
|
|
452
|
+
is_main: true,
|
|
453
|
+
is_chart: true,
|
|
454
|
+
is_report: true,
|
|
455
|
+
is_chart_column: false,
|
|
456
|
+
is_hide: false,
|
|
457
|
+
display_type: '',
|
|
458
|
+
is_alarm: false,
|
|
459
|
+
email_flags: false,
|
|
460
|
+
time_is_over: null,
|
|
461
|
+
maintain_time: 5,
|
|
462
|
+
number_send_email: null,
|
|
463
|
+
period_send_email: 15,
|
|
464
|
+
allow_min_value: 0,
|
|
465
|
+
allow_max_value: 0,
|
|
466
|
+
message: 'Thông báo.',
|
|
467
|
+
last_time_send_email: null,
|
|
468
|
+
ai_trans_offset_value: '0.000',
|
|
469
|
+
ai_trans_average_sample: 0,
|
|
470
|
+
last_values: [],
|
|
471
|
+
icon: '',
|
|
472
|
+
scale_write: 1,
|
|
473
|
+
lock: false,
|
|
474
|
+
flag: false,
|
|
475
|
+
index: 0,
|
|
476
|
+
decimal_behind: null,
|
|
477
|
+
active_filter: '',
|
|
478
|
+
high_level: 0,
|
|
479
|
+
low_level: 0,
|
|
480
|
+
value_converter: '',
|
|
481
|
+
ack: false,
|
|
482
|
+
sensor_type: '',
|
|
483
|
+
value_type: 'number',
|
|
484
|
+
enable_log_max_min: true,
|
|
485
|
+
log_value_mode: 1,
|
|
486
|
+
freq_log_data: 600,
|
|
487
|
+
number_days_storage: 180,
|
|
488
|
+
storage_start_date: '2025-01-07',
|
|
489
|
+
release_time: 0,
|
|
490
|
+
sensor: 9,
|
|
491
|
+
end_device: 4,
|
|
492
|
+
last_value: null,
|
|
493
|
+
last_value_log: null,
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
active: true,
|
|
497
|
+
name: 'LED',
|
|
498
|
+
mix: true,
|
|
499
|
+
index: 0,
|
|
500
|
+
icon: '',
|
|
501
|
+
is_managed_by_backend: true,
|
|
502
|
+
device_id: '',
|
|
503
|
+
last_updated: null,
|
|
504
|
+
connection_time: 60,
|
|
505
|
+
sent_email: false,
|
|
506
|
+
realtime_monitoring: false,
|
|
507
|
+
chip: 3,
|
|
508
|
+
icon_kit: null,
|
|
509
|
+
},
|
|
426
510
|
],
|
|
427
511
|
id: 7689,
|
|
428
512
|
sn: '57ae596e-ef65-4162-9b6f-4f67f2c86632',
|
|
@@ -523,4 +607,25 @@ export const gatewayDataFactory = {
|
|
|
523
607
|
],
|
|
524
608
|
chip: 7682,
|
|
525
609
|
},
|
|
610
|
+
third_party_gateway: {
|
|
611
|
+
id: 4,
|
|
612
|
+
sensors: [
|
|
613
|
+
{
|
|
614
|
+
id: 5,
|
|
615
|
+
configs: [
|
|
616
|
+
{
|
|
617
|
+
id: 5,
|
|
618
|
+
key: 'led',
|
|
619
|
+
value_type: 'number',
|
|
620
|
+
device: 5,
|
|
621
|
+
config: 37,
|
|
622
|
+
},
|
|
623
|
+
],
|
|
624
|
+
device_uid: '0x00158d00022fd388',
|
|
625
|
+
gateway: 4,
|
|
626
|
+
sensor: 9,
|
|
627
|
+
},
|
|
628
|
+
],
|
|
629
|
+
chip: 7689,
|
|
630
|
+
},
|
|
526
631
|
};
|
|
@@ -42,6 +42,9 @@ export default {
|
|
|
42
42
|
contact_infomation: 'Contact Infomation',
|
|
43
43
|
company_infomation: 'Company Infomation',
|
|
44
44
|
terms_and_condition: 'Terms & Conditions',
|
|
45
|
+
add_to_dashboard: 'Add to Dashboard',
|
|
46
|
+
remove_from_dashboard: 'Remove from Dashboard',
|
|
47
|
+
dashboard_devices: 'Dashboard Devices',
|
|
45
48
|
text_sub_units: 'Sub-units',
|
|
46
49
|
text_my_units: 'My Units',
|
|
47
50
|
text_shared_units: 'Shared Units',
|
|
@@ -379,6 +382,7 @@ export default {
|
|
|
379
382
|
select_a_sub_unit_want_add_device:
|
|
380
383
|
'Select a sub-unit that you want to add this device in',
|
|
381
384
|
text_select_a_unit_have_device: 'Select a unit that has this device',
|
|
385
|
+
text_select_go_to_unit_detail: 'Select a unit to view details',
|
|
382
386
|
text_select_permissions: 'Select permissions',
|
|
383
387
|
text_select_permissions_desc: 'Select permissions will be grant',
|
|
384
388
|
text_read_config: 'Read configs',
|
|
@@ -117,6 +117,9 @@ export default {
|
|
|
117
117
|
text_good_night: 'Chào buổi tối, {0}',
|
|
118
118
|
text_anonymous: '',
|
|
119
119
|
multi_unit: 'Nhiều đơn vị',
|
|
120
|
+
add_to_dashboard: 'Thêm vào Dashboard',
|
|
121
|
+
remove_from_dashboard: 'Loại khỏi Dashboard',
|
|
122
|
+
dashboard_devices: 'Thiết bị thường dùng',
|
|
120
123
|
text_my_units: 'Địa điểm của tôi',
|
|
121
124
|
text_shared_units: 'Địa điểm được chia sẻ ',
|
|
122
125
|
text_copyright:
|
|
@@ -432,6 +435,7 @@ export default {
|
|
|
432
435
|
text_select_a_gateway: 'Chọn một gateway',
|
|
433
436
|
text_select_a_unit_desc: 'Chọn 1 địa điểm bạn muốn thêm thành viên',
|
|
434
437
|
text_select_a_unit_have_device: 'Chọn một địa điểm có thiết bị này',
|
|
438
|
+
text_select_go_to_unit_detail: 'Chọn địa điểm để xem chi tiết',
|
|
435
439
|
select_a_sub_unit_want_add_device:
|
|
436
440
|
'Chọn một đơn vị con mà bạn muốn thêm thiết bị này vào',
|
|
437
441
|
text_select_permissions: 'Chọn hành động',
|
package/src/utils/Route/index.js
CHANGED
package/src/utils/Storage.js
CHANGED
|
@@ -4,16 +4,30 @@ export const STORAGE_KEY = {
|
|
|
4
4
|
FIREBASE_APP_CONFIG: 'app_config',
|
|
5
5
|
FIREBASE_EXCHANGE_RATES: 'exchange_rates',
|
|
6
6
|
FIREBASE_REVIEW_COMMENT_VIDEO: 'review_comment_video',
|
|
7
|
-
IS_FIRST_TIME_LOAD_MY_UNITS: 'IS_FIRST_TIME_LOAD_MY_UNITS',
|
|
8
|
-
IS_FIRST_TIME_LOAD_MY_SHARE_UNIT: 'IS_FIRST_TIME_LOAD_MY_SHARE_UNIT',
|
|
9
7
|
};
|
|
10
8
|
|
|
11
9
|
export const storeData = async (key, value) => {
|
|
12
|
-
return await AsyncStorage.setItem(
|
|
10
|
+
return await AsyncStorage.setItem(key, value);
|
|
13
11
|
};
|
|
14
12
|
|
|
15
13
|
export const getData = async (key) => {
|
|
16
|
-
return await AsyncStorage.getItem(
|
|
14
|
+
return await AsyncStorage.getItem(key);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const storeObject = async (key, value) => {
|
|
18
|
+
return await AsyncStorage.setItem(key, JSON.stringify(value));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getObject = async (key, defaultValue) => {
|
|
22
|
+
const value = await AsyncStorage.getItem(key);
|
|
23
|
+
if (value === null) {
|
|
24
|
+
return defaultValue;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(value);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
17
31
|
};
|
|
18
32
|
|
|
19
33
|
export const removeMultiple = async (keys) => {
|
package/src/utils/Utils.js
CHANGED
|
@@ -231,7 +231,8 @@ export const PIN_MAPPING = {
|
|
|
231
231
|
},
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
-
export const keyExtractor = (item, index) =>
|
|
234
|
+
export const keyExtractor = (item, index) =>
|
|
235
|
+
item?.id ? `id-${item.id}` : `index-${index}`;
|
|
235
236
|
|
|
236
237
|
export default {
|
|
237
238
|
validateEmail,
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import FastImage from 'react-native-fast-image';
|
|
2
|
-
import { API } from '../../configs';
|
|
3
|
-
import { axiosGet } from '../Apis/axios';
|
|
4
|
-
import { getData, STORAGE_KEY, storeData } from '../Storage';
|
|
5
|
-
|
|
6
|
-
export const preloadImagesFromUnits = async (units, storeKey) => {
|
|
7
|
-
const isFirstTime = await getData(storeKey);
|
|
8
|
-
if (units?.length && !isFirstTime) {
|
|
9
|
-
await storeData(storeKey, 'true');
|
|
10
|
-
const results = await Promise.all(
|
|
11
|
-
units.map(async (item) => {
|
|
12
|
-
const unitId =
|
|
13
|
-
storeKey === STORAGE_KEY.IS_FIRST_TIME_LOAD_MY_UNITS
|
|
14
|
-
? item?.id
|
|
15
|
-
: item?.unit?.id;
|
|
16
|
-
if (unitId) {
|
|
17
|
-
const { success, data } = await axiosGet(
|
|
18
|
-
API.UNIT.UNIT_DETAIL(unitId),
|
|
19
|
-
{},
|
|
20
|
-
true
|
|
21
|
-
);
|
|
22
|
-
return success && data;
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const icons = results
|
|
28
|
-
.map((item) => item?.stations?.map((i) => i?.background) || [])
|
|
29
|
-
.flat()
|
|
30
|
-
.filter(Boolean);
|
|
31
|
-
FastImage.preload(
|
|
32
|
-
icons.map((uri) => ({
|
|
33
|
-
uri,
|
|
34
|
-
priority: FastImage.priority.high,
|
|
35
|
-
}))
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
};
|