@ledvance/ui-biz-bundle 1.1.70 → 1.1.72

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.
@@ -1,386 +1,402 @@
1
- import React, { useCallback, useEffect, useMemo } from 'react';
2
- import Page from '@ledvance/base/src/components/Page';
3
- import { Utils } from 'tuya-panel-kit';
4
- import { saveMoodList, useWorkMode } from './MoodActions';
5
- import {
6
- useDeviceId,
7
- useDeviceInfo,
8
- useFlagMode,
9
- useMoods,
10
- } from '@ledvance/base/src/models/modules/NativePropsSlice';
11
- import { useReactive } from 'ahooks';
12
- import Strings from '@ledvance/base/src/i18n';
13
- import res from '@ledvance/base/src/res';
14
- import { FlatList, StyleSheet, View, Platform } from 'react-native';
15
- import Tag from '@ledvance/base/src/components/Tag';
16
- import Spacer from '@ledvance/base/src/components/Spacer';
17
- import InfoText from '@ledvance/base/src/components/InfoText';
18
- import CustomListDialog from '@ledvance/base/src/components/CustomListDialog';
19
- import MoodItem from './MoodItem';
20
- import { useNavigation } from '@react-navigation/core';
21
- import { MoodPageParams, MoodPageState, MoodUIInfo } from './Interface';
22
- import { getRemoteMoodList, useMoodScene } from './MoodActions';
23
- import { useParams } from '@ledvance/base/src/hooks/Hooks';
24
- import { ui_biz_routerKey } from '../../navigation/Routers'
25
- import { cloneDeep, filter, map } from 'lodash';
26
- import { saveFlagMode } from '@ledvance/ui-biz-bundle/src/modules/flags/FlagActions';
27
- import { WorkMode } from '@ledvance/base/src/utils/interface';
28
-
29
- const cx = Utils.RatioUtils.convertX;
30
-
31
- const MAX_MOOD_COUNT = 255;
32
-
33
- const MoodPage = () => {
34
- const params = useParams<MoodPageParams>();
35
- const deviceInfo = useDeviceInfo();
36
- const devId = useDeviceId();
37
- const navigation = useNavigation();
38
- const [moodInfo, setMoodInfo] = useMoodScene(params);
39
- const [moods, setMoods] = useMoods();
40
- const [mainWork, setMainWork] = useWorkMode(params.mainWorkMode);
41
- const [secondaryWork, setSecondaryWork] = useWorkMode(params.secondaryWorkMode!);
42
- const [flagMode, setFlagMode] = useFlagMode();
43
- const state = useReactive<MoodPageState>({
44
- currentMood: undefined,
45
- staticTagChecked: true,
46
- dynamicTagChecked: true,
47
- showAddMoodPopover: false,
48
- originMoods: cloneDeep(moods),
49
- filterMoods: [],
50
- loading: false,
51
- timerId: undefined as any,
52
- flag: Symbol(),
53
- });
54
-
55
- const moodIds = useMemo(() => {
56
- const mainIds = map(state.originMoods, 'id').filter(v => v !== undefined)
57
- const secondaryIds = map(state.originMoods.map(m => m.secondaryLamp) || [], 'id')
58
- return filter([...mainIds, ...secondaryIds], v => v !== undefined) as number[]
59
- }, [JSON.stringify(state.originMoods)])
60
-
61
- useEffect(() => {
62
- state.loading = true
63
- state.timerId = setTimeout(() => {
64
- getRemoteMoodList(
65
- devId,
66
- params,
67
- params.featureId
68
- ).then(res => {
69
- state.loading = false
70
- if (res.success && Array.isArray(res.data)) {
71
- console.log(res.data, '< --- res.data')
72
- state.originMoods = cloneDeep(res.data);
73
- }
74
- });
75
- }, 250);
76
-
77
- return () => {
78
- clearTimeout(state.timerId);
79
- };
80
- }, []);
81
-
82
- useEffect(() => {
83
- state.filterMoods = state.originMoods.filter(item => {
84
- return (
85
- (state.staticTagChecked && state.dynamicTagChecked) ||
86
- (!state.staticTagChecked && !state.dynamicTagChecked) ||
87
- (state.staticTagChecked && item.mainLamp.nodes.length < 2) ||
88
- (state.dynamicTagChecked &&
89
- (item.secondaryLamp.nodes.length > 1 || item.mainLamp.nodes.length > 1))
90
- );
91
- });
92
- }, [state.staticTagChecked, state.dynamicTagChecked, state.originMoods]);
93
-
94
- const navigationRoute = (isStatic: boolean, mode: 'add' | 'edit', currentMood?: MoodUIInfo) => {
95
- const path =
96
- mode === 'add'
97
- ? ui_biz_routerKey.ui_biz_mood_add
98
- : isStatic
99
- ? ui_biz_routerKey.ui_biz_static_mood_edit
100
- : !!(params.isMixLight || params.isCeilingLight)
101
- ? ui_biz_routerKey.ui_biz_dynamic_mix_mood_edit
102
- : ui_biz_routerKey.ui_biz_dynamic_mood_edit;
103
- navigation.navigate(path, {
104
- mode,
105
- isStatic,
106
- currentMood,
107
- moduleParams: params,
108
- moodIds,
109
- nameRepeat,
110
- modDeleteMood,
111
- });
112
- };
113
-
114
- const modDeleteMood = async (mode: 'add' | 'edit' | 'del' | 'set', currentMood: MoodUIInfo) => {
115
- const checkedMood: MoodUIInfo = {
116
- ...currentMood,
117
- mainLamp: {
118
- ...currentMood.mainLamp,
119
- nodes: currentMood.mainLamp.nodes.map(node => {
120
- if (mode !== 'del') {
121
- if (node.isColorNode) {
122
- node.brightness = 0;
123
- node.colorTemp = 0;
124
- } else {
125
- node.h = 0;
126
- node.s = 0;
127
- node.v = 0;
128
- if (!params.isSupportTemperature) {
129
- node.colorTemp = 100; // 适配dim灯
130
- }
131
- }
132
- return node;
133
- }
134
- return node;
135
- }),
136
- },
137
- secondaryLamp: {
138
- ...currentMood.secondaryLamp,
139
- nodes: currentMood.secondaryLamp && currentMood.secondaryLamp.nodes?.length
140
- ? currentMood.secondaryLamp.nodes.map(node => {
141
- if (mode !== 'del') {
142
- if (node.isColorNode) {
143
- node.brightness = 0;
144
- node.colorTemp = 0;
145
- } else {
146
- node.h = 0;
147
- node.s = 0;
148
- node.v = 0;
149
- if (!params.isSupportTemperature) {
150
- node.colorTemp = 100; // 适配dim灯
151
- }
152
- }
153
- return node;
154
- }
155
- return node;
156
- })
157
- : [],
158
- },
159
- };
160
- if (mode === 'set') {
161
- return setMoodInfo(checkedMood);
162
- }
163
- let newScene: MoodUIInfo[] = [];
164
- if (mode === 'add') {
165
- newScene = [checkedMood, ...state.originMoods];
166
- } else if (mode === 'del') {
167
- newScene = state.originMoods.filter(item => item.id !== checkedMood.id);
168
- } else {
169
- newScene = state.originMoods.map(item => {
170
- if (item.id === checkedMood.id) {
171
- return checkedMood;
172
- }
173
- return item;
174
- });
175
- }
176
- const mood = mode === 'del' ? (newScene.length === 0 ? undefined : newScene[0]) : checkedMood;
177
- const res = await saveMoodList(devId, newScene, params, params.featureId);
178
- if (res.success) {
179
- state.originMoods = cloneDeep(newScene);
180
- setMoods(cloneDeep(newScene));
181
- updateFlagMode();
182
- if (mood) {
183
- if (mode === 'del') {
184
- if (
185
- (mainWork !== WorkMode.Scene && secondaryWork !== WorkMode.Scene) ||
186
- (params.isCeilingLight
187
- ? currentMood.mainLamp.id !== moodInfo.mainLamp.id &&
188
- currentMood.secondaryLamp.id !== moodInfo.secondaryLamp.id
189
- : currentMood.id !== moodInfo.id)
190
- ) {
191
- return {
192
- success: true,
193
- };
194
- }
195
- }
196
- setMoodInfo(mood).then();
197
- } else {
198
- if (mainWork === WorkMode.Scene) {
199
- if (params.isCeilingLight) {
200
- setMainWork(WorkMode.White).then();
201
- } else {
202
- const work = getWorkMode(undefined, params);
203
- setMainWork(work).then();
204
- }
205
- }
206
- if (params.isCeilingLight && params.secondaryWorkMode && secondaryWork === WorkMode.Scene) {
207
- setSecondaryWork(WorkMode.Colour).then();
208
- }
209
- }
210
- return {
211
- success: true,
212
- };
213
- } else {
214
- return {
215
- success: false,
216
- };
217
- }
218
- };
219
-
220
- function getWorkMode(mood: MoodUIInfo | undefined, params: MoodPageParams): WorkMode {
221
- if (mood) return WorkMode.Scene;
222
- if (params.isFanLight || params.isUVCFan) return WorkMode.Control;
223
- if (params.isSupportColor) return WorkMode.Colour;
224
- return WorkMode.White;
225
- }
226
-
227
- const updateFlagMode = () => {
228
- if (flagMode?.flagMode) {
229
- saveFlagMode(
230
- devId,
231
- JSON.stringify({
232
- flagMode: false,
233
- flagId: undefined,
234
- })
235
- ).then();
236
- setFlagMode({
237
- flagMode: false,
238
- flagId: undefined,
239
- });
240
- }
241
- };
242
-
243
- const onAddMoodDialogItemClick = useCallback(
244
- (isStatic: boolean, _: number) => {
245
- if (!!state.originMoods) {
246
- navigationRoute(isStatic, 'add');
247
- }
248
- state.showAddMoodPopover = false;
249
- },
250
- [state.originMoods]
251
- );
252
-
253
- const getItemEnable = useCallback(
254
- (moodItem: MoodUIInfo) => {
255
- if (params.isCeilingLight) {
256
- return (
257
- moodInfo.mainLamp.id === moodItem.mainLamp.id &&
258
- moodInfo.secondaryLamp.id === moodItem.secondaryLamp.id &&
259
- (mainWork === WorkMode.Scene || secondaryWork === WorkMode.Scene)
260
- );
261
- } else {
262
- return moodInfo.id === moodItem.id && mainWork === WorkMode.Scene && !flagMode.flagMode;
263
- }
264
- },
265
- [moodInfo, mainWork]
266
- );
267
-
268
- const nameRepeat = useCallback((mood: MoodUIInfo) => {
269
- return !!state.originMoods.filter(m => !(params.isCeilingLight ? (m.mainLamp.id === mood.mainLamp.id && m.secondaryLamp.id === mood.secondaryLamp.id) : (m.id === mood.id))).find(m => m.name === mood.name)
270
- }, [state.originMoods, params.isCeilingLight])
271
-
272
- return (
273
- <>
274
- <Page
275
- backText={deviceInfo.name}
276
- headlineText={Strings.getLang('mood_overview_headline_text')}
277
- headlineIcon={state.originMoods.length < MAX_MOOD_COUNT ? res.add : undefined}
278
- onHeadlineIconClick={() => {
279
- if (params.isStringLight || params.isStripLight) {
280
- onAddMoodDialogItemClick(false, 1);
281
- } else {
282
- state.showAddMoodPopover = !state.showAddMoodPopover;
283
- }
284
- }}
285
- loading={state.loading}
286
- >
287
- <View style={styles.tagLine}>
288
- <Tag
289
- checked={state.staticTagChecked}
290
- text={Strings.getLang('mood_overview_filter_name_text1')}
291
- onCheckedChange={checked => {
292
- state.staticTagChecked = checked;
293
- }}
294
- />
295
- <Spacer width={cx(8)} height={0} />
296
- <Tag
297
- checked={state.dynamicTagChecked}
298
- text={Strings.getLang('mood_overview_filter_name_text2')}
299
- onCheckedChange={checked => {
300
- state.dynamicTagChecked = checked;
301
- }}
302
- />
303
- </View>
304
- <Spacer height={cx(10)} />
305
- {state.originMoods.length >= MAX_MOOD_COUNT && (
306
- <View style={styles.infoLine}>
307
- <Spacer height={cx(10)} />
308
- <InfoText
309
- icon={res.ic_warning_amber}
310
- text={Strings.getLang('mood_overview_warning_max_number_text')}
311
- contentColor={'#ff9500'}
312
- />
313
- <Spacer height={cx(6)} />
314
- </View>
315
- )}
316
- <FlatList
317
- data={state.filterMoods}
318
- renderItem={({ item }) => {
319
- return (
320
- <MoodItem
321
- enable={getItemEnable(item)}
322
- isMix={!!(params.isMixLight || params.isCeilingLight)}
323
- mood={item}
324
- onPress={() => {
325
- navigationRoute(item.mainLamp.nodes.length === 1, 'edit', item);
326
- }}
327
- onSwitch={async _ => {
328
- state.loading = true;
329
- await modDeleteMood('set', item);
330
- updateFlagMode();
331
- state.loading = false;
332
- }}
333
- />
334
- );
335
- }}
336
- ListHeaderComponent={() => <Spacer height={cx(10)} />}
337
- ItemSeparatorComponent={() => <Spacer />}
338
- ListFooterComponent={() => <Spacer />}
339
- keyExtractor={item => `${item.name}`}
340
- />
341
- </Page>
342
- <CustomListDialog
343
- show={state.showAddMoodPopover}
344
- style={styles.addMoodPopover}
345
- itemStyle={styles.popoverItem}
346
- onDismiss={() => {
347
- state.showAddMoodPopover = false;
348
- }}
349
- data={[
350
- {
351
- text: Strings.getLang('mood_overview_add_mood_text'),
352
- value: true,
353
- },
354
- {
355
- text: Strings.getLang('mood_overview_add_mood_text2'),
356
- value: false,
357
- },
358
- ]}
359
- onItemPress={onAddMoodDialogItemClick}
360
- />
361
- </>
362
- );
363
- };
364
-
365
- const styles = StyleSheet.create({
366
- tagLine: {
367
- flexDirection: 'row',
368
- marginHorizontal: cx(24),
369
- },
370
- infoLine: {
371
- marginHorizontal: cx(24),
372
- },
373
- addMoodPopover: {
374
- position: 'absolute',
375
- right: cx(60),
376
- top: Platform.OS === 'android' ? cx(90) : cx(130),
377
- maxWidth: cx(200),
378
- backgroundColor: '#fff',
379
- },
380
- popoverItem: {
381
- padding: cx(5),
382
- alignItems: 'flex-start',
383
- },
384
- });
385
-
386
- export default MoodPage;
1
+ import React, { useCallback, useEffect, useMemo } from 'react';
2
+ import Page from '@ledvance/base/src/components/Page';
3
+ import { Utils } from 'tuya-panel-kit';
4
+ import { saveMoodList, useSwitchLed, useWorkMode } from './MoodActions';
5
+ import {
6
+ useDeviceId,
7
+ useDeviceInfo,
8
+ useFlagMode,
9
+ useMoods,
10
+ } from '@ledvance/base/src/models/modules/NativePropsSlice';
11
+ import { useReactive, useUpdateEffect } from 'ahooks';
12
+ import Strings from '@ledvance/base/src/i18n';
13
+ import res from '@ledvance/base/src/res';
14
+ import { FlatList, StyleSheet, View, Platform } from 'react-native';
15
+ import Tag from '@ledvance/base/src/components/Tag';
16
+ import Spacer from '@ledvance/base/src/components/Spacer';
17
+ import InfoText from '@ledvance/base/src/components/InfoText';
18
+ import CustomListDialog from '@ledvance/base/src/components/CustomListDialog';
19
+ import MoodItem from './MoodItem';
20
+ import { useNavigation } from '@react-navigation/core';
21
+ import { MoodPageParams, MoodPageState, MoodUIInfo } from './Interface';
22
+ import { getRemoteMoodList, useMoodScene } from './MoodActions';
23
+ import { useParams } from '@ledvance/base/src/hooks/Hooks';
24
+ import { ui_biz_routerKey } from '../../navigation/Routers'
25
+ import { cloneDeep, filter, map } from 'lodash';
26
+ import { saveFlagMode } from '@ledvance/ui-biz-bundle/src/modules/flags/FlagActions';
27
+ import { WorkMode } from '@ledvance/base/src/utils/interface';
28
+
29
+ const cx = Utils.RatioUtils.convertX;
30
+
31
+ const MAX_MOOD_COUNT = 255;
32
+
33
+ const MoodPage = () => {
34
+ const params = useParams<MoodPageParams>();
35
+ const deviceInfo = useDeviceInfo();
36
+ const devId = useDeviceId();
37
+ const navigation = useNavigation();
38
+ const [moodInfo, setMoodInfo] = useMoodScene(params);
39
+ const [moods, setMoods] = useMoods();
40
+ const [mainWork, setMainWork] = useWorkMode(params.mainWorkMode);
41
+ const [secondaryWork, setSecondaryWork] = useWorkMode(params.secondaryWorkMode!);
42
+ const [switchLed] = useSwitchLed(params.switchLedDp)
43
+ const [flagMode, setFlagMode] = useFlagMode();
44
+
45
+ const state = useReactive<MoodPageState>({
46
+ currentMood: undefined,
47
+ staticTagChecked: true,
48
+ dynamicTagChecked: true,
49
+ showAddMoodPopover: false,
50
+ originMoods: cloneDeep(moods),
51
+ filterMoods: [],
52
+ loading: false,
53
+ timerId: undefined as any,
54
+ flag: Symbol(),
55
+ });
56
+
57
+ const moodIds = useMemo(() => {
58
+ const mainIds = map(state.originMoods, 'id').filter(v => v !== undefined)
59
+ const secondaryIds = map(state.originMoods.map(m => m.secondaryLamp) || [], 'id')
60
+ return filter([...mainIds, ...secondaryIds], v => v !== undefined) as number[]
61
+ }, [JSON.stringify(state.originMoods)])
62
+
63
+ useEffect(() => {
64
+ state.loading = true
65
+ state.timerId = setTimeout(() => {
66
+ getRemoteMoodList(
67
+ devId,
68
+ params,
69
+ params.featureId
70
+ ).then(res => {
71
+ state.loading = false
72
+ if (res.success && Array.isArray(res.data)) {
73
+ console.log(res.data, ' <--- res.data')
74
+ state.originMoods = cloneDeep(res.data);
75
+ }
76
+ });
77
+ }, 250);
78
+
79
+ return () => {
80
+ clearTimeout(state.timerId);
81
+ };
82
+ }, []);
83
+
84
+ useEffect(() => {
85
+ state.filterMoods = state.originMoods.filter(item => {
86
+ return (
87
+ (state.staticTagChecked && state.dynamicTagChecked) ||
88
+ (!state.staticTagChecked && !state.dynamicTagChecked) ||
89
+ (state.staticTagChecked && item.mainLamp.nodes.length < 2) ||
90
+ (state.dynamicTagChecked &&
91
+ (item.secondaryLamp.nodes.length > 1 || item.mainLamp.nodes.length > 1))
92
+ );
93
+ });
94
+ }, [state.staticTagChecked, state.dynamicTagChecked, state.originMoods]);
95
+
96
+ const navigationRoute = (isStatic: boolean, mode: 'add' | 'edit', currentMood?: MoodUIInfo) => {
97
+ const path =
98
+ mode === 'add'
99
+ ? ui_biz_routerKey.ui_biz_mood_add
100
+ : isStatic
101
+ ? ui_biz_routerKey.ui_biz_static_mood_edit
102
+ : !!(params.isMixLight || params.isCeilingLight)
103
+ ? ui_biz_routerKey.ui_biz_dynamic_mix_mood_edit
104
+ : ui_biz_routerKey.ui_biz_dynamic_mood_edit;
105
+ navigation.navigate(path, {
106
+ mode,
107
+ isStatic,
108
+ currentMood,
109
+ moduleParams: params,
110
+ moodIds,
111
+ nameRepeat,
112
+ modDeleteMood,
113
+ });
114
+ };
115
+
116
+ const modDeleteMood = async (mode: 'add' | 'edit' | 'del' | 'set', currentMood: MoodUIInfo) => {
117
+ const checkedMood: MoodUIInfo = {
118
+ ...currentMood,
119
+ mainLamp: {
120
+ ...currentMood.mainLamp,
121
+ nodes: currentMood.mainLamp.nodes.map(node => {
122
+ if (mode !== 'del') {
123
+ if (node.isColorNode) {
124
+ node.brightness = 0;
125
+ node.colorTemp = 0;
126
+ } else {
127
+ node.h = 0;
128
+ node.s = 0;
129
+ node.v = 0;
130
+ if (!params.isSupportTemperature) {
131
+ node.colorTemp = 100; // 适配dim灯
132
+ }
133
+ }
134
+ return node;
135
+ }
136
+ return node;
137
+ }),
138
+ },
139
+ secondaryLamp: {
140
+ ...currentMood.secondaryLamp,
141
+ nodes: currentMood.secondaryLamp && currentMood.secondaryLamp.nodes?.length
142
+ ? currentMood.secondaryLamp.nodes.map(node => {
143
+ if (mode !== 'del') {
144
+ if (node.isColorNode) {
145
+ node.brightness = 0;
146
+ node.colorTemp = 0;
147
+ } else {
148
+ node.h = 0;
149
+ node.s = 0;
150
+ node.v = 0;
151
+ if (!params.isSupportTemperature) {
152
+ node.colorTemp = 100; // 适配dim灯
153
+ }
154
+ }
155
+ return node;
156
+ }
157
+ return node;
158
+ })
159
+ : [],
160
+ },
161
+ };
162
+ if (mode === 'set') {
163
+ return setMoodInfo(checkedMood);
164
+ }
165
+ let newScene: MoodUIInfo[] = [];
166
+ if (mode === 'add') {
167
+ newScene = [checkedMood, ...state.originMoods];
168
+ } else if (mode === 'del') {
169
+ if (params.isCeilingLight) {
170
+ newScene = state.originMoods.filter(item => (item.mainLamp.id !== checkedMood.mainLamp.id) || (item.secondaryLamp.id !== checkedMood.secondaryLamp.id))
171
+ } else {
172
+ newScene = state.originMoods.filter(item => item.id !== checkedMood.id);
173
+ }
174
+ } else {
175
+ if (params.isCeilingLight) {
176
+ newScene = state.originMoods.map(item => {
177
+ if (item.mainLamp.id === checkedMood.mainLamp.id && item.secondaryLamp.id === checkedMood.secondaryLamp.id) {
178
+ return checkedMood;
179
+ }
180
+ return item;
181
+ });
182
+ } else {
183
+ newScene = state.originMoods.map(item => {
184
+ if (item.id === checkedMood.id) {
185
+ return checkedMood;
186
+ }
187
+ return item;
188
+ });
189
+ }
190
+ }
191
+ const mood = mode === 'del' ? (newScene.length === 0 ? undefined : newScene[0]) : checkedMood;
192
+ const res = await saveMoodList(devId, newScene, params, params.featureId);
193
+ if (res.success) {
194
+ state.originMoods = cloneDeep(newScene);
195
+ setMoods(cloneDeep(newScene));
196
+ updateFlagMode();
197
+ if (mood) {
198
+ if (mode === 'del') {
199
+ if (
200
+ (mainWork !== WorkMode.Scene && secondaryWork !== WorkMode.Scene) ||
201
+ (params.isCeilingLight
202
+ ? currentMood.mainLamp.id !== moodInfo.mainLamp.id &&
203
+ currentMood.secondaryLamp.id !== moodInfo.secondaryLamp.id
204
+ : currentMood.id !== moodInfo.id) || !switchLed
205
+ ) {
206
+ return {
207
+ success: true,
208
+ };
209
+ }
210
+ }
211
+ setMoodInfo(mood).then();
212
+ } else {
213
+ if (mainWork === WorkMode.Scene) {
214
+ if (params.isCeilingLight) {
215
+ setMainWork(WorkMode.White).then();
216
+ } else {
217
+ const work = getWorkMode(undefined, params);
218
+ setMainWork(work).then();
219
+ }
220
+ }
221
+ if (params.isCeilingLight && params.secondaryWorkMode && secondaryWork === WorkMode.Scene) {
222
+ setSecondaryWork(WorkMode.Colour).then();
223
+ }
224
+ }
225
+ return {
226
+ success: true,
227
+ };
228
+ } else {
229
+ return {
230
+ success: false,
231
+ };
232
+ }
233
+ };
234
+
235
+ function getWorkMode(mood: MoodUIInfo | undefined, params: MoodPageParams): WorkMode {
236
+ if (mood) return WorkMode.Scene;
237
+ if (params.isFanLight || params.isUVCFan) return WorkMode.Control;
238
+ if (params.isSupportColor) return WorkMode.Colour;
239
+ return WorkMode.White;
240
+ }
241
+
242
+ const updateFlagMode = () => {
243
+ if (flagMode?.flagMode) {
244
+ saveFlagMode(
245
+ devId,
246
+ JSON.stringify({
247
+ flagMode: false,
248
+ flagId: undefined,
249
+ })
250
+ ).then();
251
+ setFlagMode({
252
+ flagMode: false,
253
+ flagId: undefined,
254
+ });
255
+ }
256
+ };
257
+
258
+ const onAddMoodDialogItemClick = useCallback(
259
+ (isStatic: boolean, _: number) => {
260
+ if (!!state.originMoods) {
261
+ navigationRoute(isStatic, 'add');
262
+ }
263
+ state.showAddMoodPopover = false;
264
+ },
265
+ [state.originMoods]
266
+ );
267
+
268
+ const getItemEnable = useCallback(
269
+ (moodItem: MoodUIInfo) => {
270
+ if (params.isCeilingLight) {
271
+ return (
272
+ moodInfo.mainLamp.id === moodItem.mainLamp.id &&
273
+ moodInfo.secondaryLamp.id === moodItem.secondaryLamp.id &&
274
+ (mainWork === WorkMode.Scene || secondaryWork === WorkMode.Scene) && !flagMode.flagMode && switchLed
275
+ );
276
+ } else {
277
+ return moodInfo.id === moodItem.id && mainWork === WorkMode.Scene && !flagMode.flagMode && switchLed
278
+ }
279
+ },
280
+ [moodInfo, mainWork, secondaryWork, flagMode?.flagMode, switchLed]
281
+ );
282
+
283
+ const nameRepeat = useCallback((mood: MoodUIInfo) => {
284
+ return !!state.originMoods.filter(m => !(params.isCeilingLight ? (m.mainLamp.id === mood.mainLamp.id && m.secondaryLamp.id === mood.secondaryLamp.id) : (m.id === mood.id))).find(m => m.name === mood.name)
285
+ }, [state.originMoods, params.isCeilingLight])
286
+
287
+ return (
288
+ <>
289
+ <Page
290
+ backText={deviceInfo.name}
291
+ headlineText={Strings.getLang('mood_overview_headline_text')}
292
+ headlineIcon={state.originMoods.length < MAX_MOOD_COUNT ? res.add : undefined}
293
+ onHeadlineIconClick={() => {
294
+ if (params.isStringLight || params.isStripLight) {
295
+ onAddMoodDialogItemClick(false, 1);
296
+ } else {
297
+ state.showAddMoodPopover = !state.showAddMoodPopover;
298
+ }
299
+ }}
300
+ loading={state.loading}
301
+ >
302
+ <View style={styles.tagLine}>
303
+ <Tag
304
+ checked={state.staticTagChecked}
305
+ text={Strings.getLang('mood_overview_filter_name_text1')}
306
+ onCheckedChange={checked => {
307
+ state.staticTagChecked = checked;
308
+ }}
309
+ />
310
+ <Spacer width={cx(8)} height={0} />
311
+ <Tag
312
+ checked={state.dynamicTagChecked}
313
+ text={Strings.getLang('mood_overview_filter_name_text2')}
314
+ onCheckedChange={checked => {
315
+ state.dynamicTagChecked = checked;
316
+ }}
317
+ />
318
+ </View>
319
+ <Spacer height={cx(10)} />
320
+ {state.originMoods.length >= MAX_MOOD_COUNT && (
321
+ <View style={styles.infoLine}>
322
+ <Spacer height={cx(10)} />
323
+ <InfoText
324
+ icon={res.ic_warning_amber}
325
+ text={Strings.getLang('mood_overview_warning_max_number_text')}
326
+ contentColor={'#ff9500'}
327
+ />
328
+ <Spacer height={cx(6)} />
329
+ </View>
330
+ )}
331
+ <FlatList
332
+ data={state.filterMoods}
333
+ renderItem={({ item }) => {
334
+ return (
335
+ <MoodItem
336
+ enable={getItemEnable(item)}
337
+ isMix={!!(params.isMixLight || params.isCeilingLight)}
338
+ mood={item}
339
+ deviceTypeOption={params}
340
+ onPress={() => {
341
+ navigationRoute(item.mainLamp.nodes.length === 1, 'edit', item);
342
+ }}
343
+ onSwitch={async _ => {
344
+ state.loading = true;
345
+ await modDeleteMood('set', item);
346
+ updateFlagMode();
347
+ state.loading = false;
348
+ }}
349
+ />
350
+ );
351
+ }}
352
+ ListHeaderComponent={() => <Spacer height={cx(10)} />}
353
+ ItemSeparatorComponent={() => <Spacer />}
354
+ ListFooterComponent={() => <Spacer />}
355
+ keyExtractor={item => `${item.name}`}
356
+ />
357
+ </Page>
358
+ <CustomListDialog
359
+ show={state.showAddMoodPopover}
360
+ style={styles.addMoodPopover}
361
+ itemStyle={styles.popoverItem}
362
+ onDismiss={() => {
363
+ state.showAddMoodPopover = false;
364
+ }}
365
+ data={[
366
+ {
367
+ text: Strings.getLang('mood_overview_add_mood_text'),
368
+ value: true,
369
+ },
370
+ {
371
+ text: Strings.getLang('mood_overview_add_mood_text2'),
372
+ value: false,
373
+ },
374
+ ]}
375
+ onItemPress={onAddMoodDialogItemClick}
376
+ />
377
+ </>
378
+ );
379
+ };
380
+
381
+ const styles = StyleSheet.create({
382
+ tagLine: {
383
+ flexDirection: 'row',
384
+ marginHorizontal: cx(24),
385
+ },
386
+ infoLine: {
387
+ marginHorizontal: cx(24),
388
+ },
389
+ addMoodPopover: {
390
+ position: 'absolute',
391
+ right: cx(60),
392
+ top: Platform.OS === 'android' ? cx(90) : cx(130),
393
+ maxWidth: cx(200),
394
+ backgroundColor: '#fff',
395
+ },
396
+ popoverItem: {
397
+ padding: cx(5),
398
+ alignItems: 'flex-start',
399
+ },
400
+ });
401
+
402
+ export default MoodPage;