@eohjsc/react-native-smart-city 0.4.62 → 0.4.63
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/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { useSCContextSelector } from '../../context';
|
|
|
5
5
|
import { useRemoteControl } from '../../hooks/IoT';
|
|
6
6
|
import { useConfigGlobalState } from '../../iot/states';
|
|
7
7
|
import IconComponent from '../IconComponent';
|
|
8
|
+
import { Colors } from '../../configs';
|
|
8
9
|
|
|
9
10
|
const ItemQuickAction = memo(
|
|
10
11
|
({ sensor, wrapperStyle, setStatus, iconSize = 30 }) => {
|
|
@@ -21,18 +22,16 @@ const ItemQuickAction = memo(
|
|
|
21
22
|
const [action, setAction] = useState(sensor?.action);
|
|
22
23
|
// eslint-disable-next-line no-unused-vars
|
|
23
24
|
const [configValues, _] = useConfigGlobalState('configValues');
|
|
24
|
-
const [
|
|
25
|
+
const currentValue = configValues[config_id]?.value || 0;
|
|
26
|
+
const isFault = currentValue === 2; // phukhaco fault value
|
|
27
|
+
const [isOn, setIsOn] = useState(currentValue);
|
|
25
28
|
|
|
26
29
|
const sendRemoteCommand = useRemoteControl();
|
|
27
30
|
const [processing, setProcessing] = useState(false);
|
|
28
31
|
|
|
29
32
|
useEffect(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const configValue = configValues[config_id];
|
|
34
|
-
setIsOn(configValue?.value);
|
|
35
|
-
}, [configValues, config_id]);
|
|
33
|
+
setIsOn(currentValue);
|
|
34
|
+
}, [currentValue]);
|
|
36
35
|
|
|
37
36
|
useEffect(() => {
|
|
38
37
|
if (!quick_action) {
|
|
@@ -58,6 +57,10 @@ const ItemQuickAction = memo(
|
|
|
58
57
|
|
|
59
58
|
const userId = useSCContextSelector((state) => state?.auth.account.user.id);
|
|
60
59
|
const onActionPress = useCallback(async () => {
|
|
60
|
+
if (isFault) {
|
|
61
|
+
/* istanbul ignore next */
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
61
64
|
if (processing || !action) {
|
|
62
65
|
/* istanbul ignore next */
|
|
63
66
|
return;
|
|
@@ -87,6 +90,7 @@ const ItemQuickAction = memo(
|
|
|
87
90
|
}
|
|
88
91
|
setProcessing(false);
|
|
89
92
|
}, [
|
|
93
|
+
isFault,
|
|
90
94
|
processing,
|
|
91
95
|
action,
|
|
92
96
|
config_id,
|
|
@@ -108,12 +112,21 @@ const ItemQuickAction = memo(
|
|
|
108
112
|
onPress={onActionPress}
|
|
109
113
|
>
|
|
110
114
|
<View style={wrapperStyle}>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
{isFault ? (
|
|
116
|
+
<IconComponent
|
|
117
|
+
icon={'WarningOutlined'}
|
|
118
|
+
color={Colors.Red}
|
|
119
|
+
iconSize={iconSize}
|
|
120
|
+
size={iconSize}
|
|
121
|
+
/>
|
|
122
|
+
) : (
|
|
123
|
+
<IconComponent
|
|
124
|
+
icon={action?.icon_kit || action?.icon || 'PoweroffOutlined'}
|
|
125
|
+
isOn={isOn}
|
|
126
|
+
iconSize={iconSize}
|
|
127
|
+
size={iconSize}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
117
130
|
</View>
|
|
118
131
|
</TouchableOpacity>
|
|
119
132
|
);
|
|
@@ -17,12 +17,11 @@ const wrapComponent = (lastUpdated) => (
|
|
|
17
17
|
describe('Test ConnectedViewHeader', () => {
|
|
18
18
|
let tree;
|
|
19
19
|
|
|
20
|
-
beforeAll(() => {
|
|
21
|
-
Date.now = jest.fn(() => new Date('2021-01-24T12:00:00.000Z'));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
20
|
it('render ConnectedViewHeader', async () => {
|
|
25
|
-
const lastUpdated = moment(new Date('
|
|
21
|
+
const lastUpdated = moment(new Date('2019-01-24T05:00:00.629Z'));
|
|
22
|
+
|
|
23
|
+
const date = new Date('2021-01-24T12:00:00.000Z');
|
|
24
|
+
jest.spyOn(global, 'Date').mockImplementation(() => date);
|
|
26
25
|
await act(async () => {
|
|
27
26
|
tree = await create(wrapComponent(lastUpdated));
|
|
28
27
|
});
|