@ledvance/ui-biz-bundle 1.1.55 → 1.1.57

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.
Files changed (70) hide show
  1. package/package.json +2 -1
  2. package/src/modules/biorhythm/Router.ts +34 -0
  3. package/src/modules/fixedTime/Router.ts +26 -0
  4. package/src/modules/flags/FlagActions.ts +12 -4
  5. package/src/modules/flags/FlagPage.tsx +31 -11
  6. package/src/modules/flags/Router.ts +25 -0
  7. package/src/modules/history/Router.ts +16 -0
  8. package/src/modules/mood/FantasyRouter.ts +35 -0
  9. package/src/modules/mood/MixMood/Router.ts +44 -0
  10. package/src/modules/mood/Router.ts +53 -0
  11. package/src/modules/music/Router.ts +16 -0
  12. package/src/modules/powerOnBehavior/Router.ts +16 -0
  13. package/src/modules/randomTime/Router.ts +25 -0
  14. package/src/modules/sleepWakeup/Router.ts +25 -0
  15. package/src/modules/timeSchedule/Router.ts +25 -0
  16. package/src/modules/timer/Router.ts +16 -0
  17. package/src/navigation/Routers.d.ts +0 -7
  18. package/src/navigation/Routers.ts +15 -304
  19. package/src/newModules/childLock/ChildLockPage.tsx +97 -0
  20. package/src/newModules/childLock/Router.ts +16 -0
  21. package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -0
  22. package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -0
  23. package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +321 -0
  24. package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +392 -0
  25. package/src/newModules/energyConsumption/Router.ts +34 -0
  26. package/src/newModules/energyConsumption/co2Data.ts +23655 -0
  27. package/src/newModules/energyConsumption/component/BarChart.tsx +93 -0
  28. package/src/newModules/energyConsumption/component/EnergyModal.tsx +282 -0
  29. package/src/newModules/energyConsumption/component/Overview.tsx +116 -0
  30. package/src/newModules/fixedTime/FixedTimeActions.ts +234 -0
  31. package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +341 -0
  32. package/src/newModules/fixedTime/FixedTimePage.tsx +231 -0
  33. package/src/newModules/fixedTime/Router.ts +25 -0
  34. package/src/newModules/lightMode/LightModePage.tsx +204 -0
  35. package/src/newModules/lightMode/Router.ts +16 -0
  36. package/src/newModules/mood/AddMoodPage.tsx +178 -0
  37. package/src/newModules/mood/DynamicMoodEditorPage.tsx +653 -0
  38. package/src/newModules/mood/Interface.ts +219 -0
  39. package/src/newModules/mood/MixDynamicMoodEditor.tsx +781 -0
  40. package/src/newModules/mood/MoodActions.ts +235 -0
  41. package/src/newModules/mood/MoodInfo.ts +2151 -0
  42. package/src/newModules/mood/MoodItem.tsx +148 -0
  43. package/src/newModules/mood/MoodPage.tsx +385 -0
  44. package/src/newModules/mood/MoodParse.ts +442 -0
  45. package/src/newModules/mood/RecommendMoodItem.tsx +68 -0
  46. package/src/newModules/mood/Router.ts +53 -0
  47. package/src/newModules/mood/StaticMoodEditorPage.tsx +343 -0
  48. package/src/newModules/mood/tools.ts +12 -0
  49. package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -0
  50. package/src/newModules/overchargeSwitch/Router.ts +16 -0
  51. package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -0
  52. package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -0
  53. package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -0
  54. package/src/newModules/powerOnBehavior/Router.ts +16 -0
  55. package/src/newModules/randomTime/RandomTimeActions.ts +232 -0
  56. package/src/newModules/randomTime/RandomTimeDetailPage.tsx +322 -0
  57. package/src/newModules/randomTime/RandomTimePage.tsx +230 -0
  58. package/src/newModules/randomTime/Router.ts +25 -0
  59. package/src/newModules/randomTime/Summary.tsx +116 -0
  60. package/src/newModules/swithInching/Router.ts +16 -0
  61. package/src/newModules/swithInching/SwithInching.tsx +231 -0
  62. package/src/newModules/swithInching/SwithInchingAction.ts +55 -0
  63. package/src/newModules/swithInching/pickerView.tsx +91 -0
  64. package/src/newModules/timeSchedule/Interface.ts +111 -0
  65. package/src/newModules/timeSchedule/Router.ts +25 -0
  66. package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -0
  67. package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +662 -0
  68. package/src/newModules/timeSchedule/TimeSchedulePage.tsx +222 -0
  69. package/src/newModules/timeSchedule/components/ManuaSettings.tsx +259 -0
  70. package/src/newModules/timeSchedule/components/ScheduleCard.tsx +109 -0
@@ -0,0 +1,231 @@
1
+ import React, { memo, useCallback } from "react";
2
+ import { FlatList, Image, ScrollView, StyleSheet, Text, View } from 'react-native'
3
+ import Page from "@ledvance/base/src/components/Page";
4
+ import { useDeviceInfo, useSystemTimeFormate } from "@ledvance/base/src/models/modules/NativePropsSlice";
5
+ import { useNavigation, useRoute } from '@react-navigation/core'
6
+ import I18n from "@ledvance/base/src/i18n";
7
+ import res from "@ledvance/base/src/res";
8
+ import { ui_biz_routerKey } from "../../navigation/Routers";
9
+ import { useReactive, useUpdateEffect } from "ahooks";
10
+ import Spacer from "@ledvance/base/src/components/Spacer";
11
+ import TextButton from '@ledvance/base/src/components/TextButton'
12
+ import { SwitchButton, Utils } from "tuya-panel-kit";
13
+ import { FixedTimerUiItem, useFixedTime } from "./FixedTimeActions";
14
+ import Card from "@ledvance/base/src/components/Card";
15
+ import { convertMinutesTo12HourFormat, loopText } from "@ledvance/base/src/utils/common";
16
+ import { cloneDeep } from "lodash";
17
+ import dayjs from "dayjs";
18
+
19
+ const { convertX: cx } = Utils.RatioUtils
20
+ const MAX_NUM = 10
21
+
22
+ export interface FixedTimePageParams {
23
+ fixedTimeDpCode: string
24
+ conflictDps: {
25
+ randomTimeDp?: string
26
+ biorhythmDp?: string
27
+ sleepWakeUpDp?: string
28
+ }
29
+ isPlug?: boolean
30
+ showTags?: boolean
31
+ applyDps: {
32
+ label: string
33
+ value: string
34
+ }[]
35
+ isSupportColor: boolean
36
+ isSupportTemperature: boolean
37
+ isSupportBrightness: boolean
38
+ }
39
+
40
+ const FixedTimePage = () => {
41
+ const navigation = useNavigation()
42
+ const devInfo = useDeviceInfo()
43
+ const params = useRoute().params as FixedTimePageParams
44
+ const is24Hour = useSystemTimeFormate()
45
+ const [fixedTime, setFixedTime] = useFixedTime(params.fixedTimeDpCode, params.isPlug)
46
+ const state = useReactive({
47
+ loading: false,
48
+ fixedTimeList: cloneDeep(fixedTime)
49
+ })
50
+
51
+ useUpdateEffect(() => {
52
+ state.fixedTimeList = cloneDeep(fixedTime)
53
+ }, [fixedTime])
54
+
55
+ const navigateToEdit = useCallback((mode: 'add' | 'edit', scheduleItem: FixedTimerUiItem) => {
56
+ navigation.navigate(ui_biz_routerKey.ui_biz_fixed_time_edit_new, {
57
+ ...params,
58
+ mode,
59
+ scheduleItem: cloneDeep(scheduleItem),
60
+ onPost
61
+ })
62
+ }, [])
63
+
64
+ const showMaxNumTip = useCallback(() => {
65
+ return state.fixedTimeList.length >= MAX_NUM
66
+ }, [state.fixedTimeList.length])
67
+
68
+ const onPost = useCallback(async (mode: 'add' | 'edit' | 'del', fixedTime: FixedTimerUiItem) => {
69
+ const cloneFixedTimeList = cloneDeep(state.fixedTimeList)
70
+ const idx = state.fixedTimeList.findIndex(f => f.index === fixedTime.index)
71
+ if (mode === 'edit') {
72
+ cloneFixedTimeList.splice(idx, 1, fixedTime)
73
+ }
74
+ if (mode === 'del') cloneFixedTimeList.splice(idx, 1)
75
+ const newFixedTimeList = mode === 'add' ? [...state.fixedTimeList, fixedTime] : cloneFixedTimeList
76
+ return setFixedTime(newFixedTimeList)
77
+ }, [state.fixedTimeList])
78
+
79
+ return (
80
+ <Page
81
+ backText={devInfo.name}
82
+ headlineText={I18n.getLang('fixedTimeCycle_socket_headline')}
83
+ headlineIcon={!showMaxNumTip() ? res.device_panel_schedule_add : undefined}
84
+ loading={state.loading}
85
+ onBackClick={navigation.goBack}
86
+ onHeadlineIconClick={() => {
87
+ navigateToEdit('add', newFixedTime())
88
+ }}
89
+ >
90
+ {state.fixedTimeList.length > 0 ?
91
+ <ScrollView nestedScrollEnabled={true}>
92
+ <Text style={{
93
+ color: '#000',
94
+ marginLeft: cx(24),
95
+ }}>{I18n.getLang('timeschedule_overview_description_text')}</Text>
96
+ <Spacer height={cx(10)} />
97
+ {showMaxNumTip() && <View style={{ marginHorizontal: cx(24), flexDirection: 'row' }}>
98
+ <Image style={{ width: cx(16), height: cx(16), tintColor: '#ff9500' }} source={res.ic_warning_amber} />
99
+ <Text>{I18n.getLang('fixedtimecycle_warning_max_number_text')}</Text>
100
+ </View>}
101
+ <FlatList
102
+ data={state.fixedTimeList}
103
+ renderItem={({ item }) => (
104
+ <FixedTimeCard
105
+ is24Hour={is24Hour}
106
+ fixedTime={item}
107
+ onSwitch={async (v) => {
108
+ state.loading = true
109
+ await onPost('edit', {
110
+ ...item,
111
+ enable: v
112
+ })
113
+ state.loading = false
114
+ }}
115
+ onPress={() => {
116
+ navigateToEdit('edit', item)
117
+ }}
118
+ />
119
+ )}
120
+ keyExtractor={(item: any) => `${item?.index}`}
121
+ ItemSeparatorComponent={() => <Spacer />}
122
+ ListHeaderComponent={<Spacer height={cx(10)} />}
123
+ ListFooterComponent={<Spacer />}
124
+ />
125
+ </ScrollView> :
126
+ <View style={{ flex: 1, marginTop: cx(60), alignItems: 'center' }}>
127
+ <Image
128
+ style={{ width: cx(225), height: cx(198) }}
129
+ source={{ uri: res.ldv_timer_empty }}
130
+ resizeMode="contain" />
131
+ <View style={{ flexDirection: 'row', alignItems: 'center' }}>
132
+ <Image
133
+ source={{ uri: res.device_panel_schedule_alert }}
134
+ style={{ width: cx(16), height: cx(16) }}
135
+ />
136
+ <Text style={{ color: '#000', fontSize: cx(12) }}>
137
+ {I18n.getLang('fixedTimeCycle_information_text')}
138
+ </Text>
139
+ </View>
140
+ <Spacer />
141
+ <TextButton
142
+ text={I18n.getLang('fixedTimeCycle_bttn_text')}
143
+ style={{
144
+ backgroundColor: '#f60',
145
+ borderRadius: cx(6),
146
+ paddingVertical: cx(12),
147
+ paddingHorizontal: cx(24),
148
+ }}
149
+ textStyle={{ color: '#fff' }}
150
+ onPress={() => {
151
+ navigateToEdit('add', newFixedTime())
152
+ }} />
153
+ </View>
154
+ }
155
+ </Page>
156
+ )
157
+ }
158
+
159
+ const FixedTimeCard = memo((props: {
160
+ is24Hour: boolean
161
+ fixedTime: FixedTimerUiItem,
162
+ onSwitch: (enable: boolean) => void,
163
+ onPress: () => void
164
+ }) => {
165
+ const { is24Hour, fixedTime, onSwitch, onPress } = props
166
+ return (
167
+ <Card style={styles.randomTimingCard} onPress={onPress}>
168
+ <Spacer height={cx(16)} />
169
+ <View style={styles.switchLine}>
170
+ <Text style={styles.time}>
171
+ {`${convertMinutesTo12HourFormat(fixedTime.startTime, is24Hour)} - ${convertMinutesTo12HourFormat(fixedTime.endTime, is24Hour)}`}</Text>
172
+ <SwitchButton
173
+ style={styles.switchBtn}
174
+ value={fixedTime.enable}
175
+ thumbStyle={{ elevation: 0 }}
176
+ onValueChange={onSwitch} />
177
+ </View>
178
+ <Text style={styles.loopText}>{loopText(fixedTime.weeks)}</Text>
179
+ <Spacer height={cx(5)} />
180
+ <Text style={styles.loopText}>{fixedTime.name}</Text>
181
+ <Spacer />
182
+ </Card>
183
+ )
184
+ })
185
+
186
+ const newFixedTime = () => {
187
+ const startTime = dayjs().hour() * 60 + dayjs().minute()
188
+ return {
189
+ name: '',
190
+ enable: true,
191
+ weeks: [0, 0, 0, 0, 0, 0, 0],
192
+ startTime: startTime,
193
+ endTime: startTime + 60,
194
+ closeTime: 1,
195
+ openTime: 1,
196
+ channel: 1,
197
+ color: {
198
+ h: 0,
199
+ s: 100,
200
+ v: 100,
201
+ brightness: 100,
202
+ temperature: 0,
203
+ }
204
+ }
205
+ }
206
+
207
+ const styles = StyleSheet.create({
208
+ randomTimingCard: {
209
+ marginHorizontal: cx(24),
210
+ paddingHorizontal: cx(16),
211
+ },
212
+ switchLine: {
213
+ flexDirection: 'row',
214
+ alignItems: 'center',
215
+ },
216
+ time: {
217
+ flex: 1,
218
+ color: '#000',
219
+ fontSize: cx(16),
220
+ fontWeight: 'bold',
221
+ fontFamily: 'helvetica_neue_lt_std_bd',
222
+ },
223
+ switchBtn: {},
224
+ loopText: {
225
+ color: '#000',
226
+ fontSize: cx(14),
227
+ fontFamily: 'helvetica_neue_lt_std_roman',
228
+ },
229
+ })
230
+
231
+ export default FixedTimePage
@@ -0,0 +1,25 @@
1
+ import {NavigationRoute} from "tuya-panel-kit";
2
+ import NewFixedTimePage from "./FixedTimePage";
3
+ import NewFixedTimeDetailPage from "./FixedTimeDetailPage";
4
+ import {ui_biz_routerKey} from "../../navigation/Routers";
5
+
6
+ const NewFixedTimePageRouters: NavigationRoute[] = [
7
+ {
8
+ name: ui_biz_routerKey.ui_biz_fixed_time_new,
9
+ component: NewFixedTimePage,
10
+ options: {
11
+ hideTopbar: true,
12
+ showOfflineView: false,
13
+ },
14
+ },
15
+ {
16
+ name: ui_biz_routerKey.ui_biz_fixed_time_edit_new,
17
+ component: NewFixedTimeDetailPage,
18
+ options: {
19
+ hideTopbar: true,
20
+ showOfflineView: false,
21
+ },
22
+ }
23
+ ]
24
+
25
+ export default NewFixedTimePageRouters
@@ -0,0 +1,204 @@
1
+ import React, { PropsWithChildren } from 'react'
2
+ import { Image, ScrollView, StyleSheet, Text, TouchableOpacity, View, ViewProps } from 'react-native'
3
+ import Page from '@ledvance/base/src/components/Page'
4
+ import {useDeviceInfo, useDp} from '@ledvance/base/src/models/modules/NativePropsSlice'
5
+ import I18n from '@ledvance/base/src/i18n'
6
+ import { Utils } from 'tuya-panel-kit'
7
+ import Spacer from '@ledvance/base/src/components/Spacer'
8
+ import Card from '@ledvance/base/src/components/Card'
9
+ import res from '@ledvance/base/src/res'
10
+ import { useReactive, useUpdateEffect } from 'ahooks'
11
+ import { useParams } from '@ledvance/base/src/hooks/Hooks'
12
+ import {Result} from "@ledvance/base/src/models/modules/Result";
13
+
14
+ const { convertX: cx } = Utils.RatioUtils
15
+
16
+ const LIGHT_MODE_RELAY = 'relay'
17
+ const LIGHT_MODE_POS = 'pos'
18
+ const LIGHT_MODE_OFF = 'off'
19
+ const LIGHT_MODE_ON = 'on'
20
+
21
+ export interface LightModePageParams {
22
+ lightModeCode: string
23
+ }
24
+
25
+ type LightMode = 'relay' | 'pos' | 'off' | 'on'
26
+
27
+ export const useLightMode = (code: string): [LightMode, (v: LightMode) => Promise<Result<any>>] => {
28
+ return useDp(code)
29
+ }
30
+
31
+ const LightModePage = () => {
32
+ const params = useParams<LightModePageParams>()
33
+ const deviceInfo = useDeviceInfo()
34
+ const [lightMode, setLightMode] = useLightMode(params.lightModeCode)
35
+
36
+ const state = useReactive({
37
+ lightMode: lightMode,
38
+ loading: false,
39
+ })
40
+
41
+ useUpdateEffect(() => {
42
+ state.lightMode = lightMode
43
+ }, [lightMode])
44
+
45
+ return (
46
+ <Page
47
+ backText={deviceInfo.name}
48
+ headlineText={I18n.getLang('matterplug_LED')}
49
+ loading={state.loading}>
50
+ <ScrollView style={styles.root} nestedScrollEnabled={true}>
51
+ <Text style={styles.desc}>
52
+ {I18n.getLang('matterplug_description')}
53
+ </Text>
54
+ <Spacer />
55
+ <View style={styles.modeSelectGroup}>
56
+ <Spacer height={cx(8)} />
57
+ <Text style={styles.modeTip}>
58
+ {I18n.getLang('matterplug_heading')}
59
+ </Text>
60
+ <Spacer height={cx(8)} />
61
+ <Card style={styles.modeSelectCard}>
62
+ <Spacer height={cx(12)} />
63
+ <LightModeItem
64
+ enable={state.lightMode === LIGHT_MODE_RELAY}
65
+ title={I18n.getLang('matterplug_option1title')}
66
+ content={I18n.getLang('matterplug_option1description')}
67
+ onPress={async () => {
68
+ state.lightMode = LIGHT_MODE_RELAY
69
+ await setLightMode(state.lightMode)
70
+ }} />
71
+ <View style={styles.line} />
72
+ <Spacer height={cx(8)} />
73
+ <LightModeItem
74
+ enable={state.lightMode === LIGHT_MODE_POS}
75
+ title={I18n.getLang('matterplug_option2title')}
76
+ content={I18n.getLang('matterplug_option2description')}
77
+ onPress={async () => {
78
+ state.lightMode = LIGHT_MODE_POS
79
+ await setLightMode(state.lightMode)
80
+ }} />
81
+ <View style={styles.line} />
82
+ <Spacer height={cx(8)} />
83
+ <LightModeItem
84
+ enable={state.lightMode === LIGHT_MODE_OFF}
85
+ title={I18n.getLang('matterplug_option3title')}
86
+ content={I18n.getLang('matterplug_option3description')}
87
+ onPress={async () => {
88
+ state.lightMode = LIGHT_MODE_OFF
89
+ await setLightMode(state.lightMode)
90
+ }} />
91
+ <Spacer height={cx(8)} />
92
+ <View style={styles.line} />
93
+ <LightModeItem
94
+ enable={state.lightMode === LIGHT_MODE_ON}
95
+ title={I18n.getLang('matterplug_option4title')}
96
+ content={I18n.getLang('matterplug_option4description')}
97
+ onPress={async () => {
98
+ state.lightMode = LIGHT_MODE_ON
99
+ await setLightMode(state.lightMode)
100
+ }} />
101
+ <Spacer height={cx(4)} />
102
+ </Card>
103
+ <Spacer height={cx(8)} />
104
+ </View>
105
+ </ScrollView>
106
+ </Page>
107
+ )
108
+ }
109
+
110
+ interface LightModeItemProps extends PropsWithChildren<ViewProps> {
111
+ onPress: () => void
112
+ title: string
113
+ content: string
114
+ enable: boolean
115
+ }
116
+
117
+ function LightModeItem(props: LightModeItemProps) {
118
+ return (
119
+ <TouchableOpacity onPress={props.onPress}>
120
+ <View style={styles.itemRoot}>
121
+ <View style={styles.itemTextGroup}>
122
+ <Text style={styles.itemTitle}>{props.title}</Text>
123
+ <Spacer height={cx(4)} />
124
+ <Text style={styles.itemContent}>{props.content}</Text>
125
+ </View>
126
+ <Image
127
+ source={{ uri: res.ic_check }}
128
+ style={[
129
+ styles.itemCheckedIcon,
130
+ {
131
+ display: props.enable ? 'flex' : 'none',
132
+ },
133
+ ]} />
134
+ </View>
135
+ </TouchableOpacity>
136
+ )
137
+ }
138
+
139
+ const styles = StyleSheet.create({
140
+ root: {
141
+ flex: 1,
142
+ },
143
+ desc: {
144
+ marginHorizontal: cx(24),
145
+ color: '#000',
146
+ fontSize: cx(14),
147
+ fontWeight: 'bold',
148
+ fontFamily: 'helvetica_neue_lt_std_bd',
149
+ },
150
+ tipText: {
151
+ marginHorizontal: cx(24),
152
+ color: '#000',
153
+ fontSize: cx(14),
154
+ fontFamily: 'helvetica_neue_lt_std_roman',
155
+ },
156
+ modeSelectGroup: {
157
+ marginHorizontal: cx(24),
158
+ backgroundColor: '#f6f6f6',
159
+ borderRadius: cx(4),
160
+ },
161
+ modeTip: {
162
+ marginHorizontal: cx(8),
163
+ color: '#000',
164
+ fontSize: cx(14),
165
+ fontWeight: 'bold',
166
+ fontFamily: 'helvetica_neue_lt_std_bd',
167
+ },
168
+ modeSelectCard: {
169
+ marginHorizontal: cx(8),
170
+ },
171
+ line: {
172
+ height: cx(1),
173
+ marginHorizontal: cx(12),
174
+ backgroundColor: '#3C3C435B',
175
+ },
176
+ itemRoot: {
177
+ flexDirection: 'row',
178
+ alignItems: 'center',
179
+ paddingHorizontal: cx(12),
180
+ paddingBottom: cx(8),
181
+ },
182
+ itemTextGroup: {
183
+ flex: 1,
184
+ marginEnd: cx(12),
185
+ justifyContent: 'center',
186
+ },
187
+ itemTitle: {
188
+ color: '#000',
189
+ fontSize: cx(14),
190
+ fontFamily: 'helvetica_neue_lt_std_roman',
191
+ },
192
+ itemContent: {
193
+ color: '#666',
194
+ fontSize: cx(14),
195
+ fontFamily: 'helvetica_neue_lt_std_roman',
196
+ },
197
+ itemCheckedIcon: {
198
+ width: cx(32),
199
+ height: cx(32),
200
+ marginEnd: cx(4),
201
+ },
202
+ })
203
+
204
+ export default LightModePage
@@ -0,0 +1,16 @@
1
+ import {NavigationRoute} from "tuya-panel-kit";
2
+ import LightModePage from "./LightModePage";
3
+ import {ui_biz_routerKey} from "../../navigation/Routers";
4
+
5
+ const LightModePageRouters: NavigationRoute[] = [
6
+ {
7
+ name: ui_biz_routerKey.ui_biz_light_mode,
8
+ component: LightModePage,
9
+ options:{
10
+ hideTopbar: true,
11
+ showOfflineView: false,
12
+ }
13
+ }
14
+ ]
15
+
16
+ export default LightModePageRouters
@@ -0,0 +1,178 @@
1
+ import Strings from '@ledvance/base/src/i18n';
2
+ import Page from '@ledvance/base/src/components/Page';
3
+ import React, { useCallback } from 'react';
4
+ import { FlatList, StyleSheet, Text, View } from 'react-native';
5
+ import { Utils } from 'tuya-panel-kit';
6
+ import RecommendMoodItem from './RecommendMoodItem';
7
+ import Spacer from '@ledvance/base/src/components/Spacer';
8
+ import { useReactive } from 'ahooks';
9
+ import { useNavigation, useRoute } from '@react-navigation/native';
10
+ import {
11
+ MoodPageParams,
12
+ MoodNodeTransitionMode,
13
+ MoodUIInfo,
14
+ MoodJumpGradientMode,
15
+ } from './Interface';
16
+ import { Result } from '@ledvance/base/src/models/modules/Result';
17
+ import { RouterKey } from 'navigation/Router';
18
+ import { difference, head, map, range } from 'lodash';
19
+ import { RecommendMood, getRecommendMixMoods, getRecommendMoods } from './MoodInfo';
20
+
21
+ const cx = Utils.RatioUtils.convertX;
22
+
23
+ export interface AddMoodPageParams {
24
+ isStatic: boolean;
25
+ moods: MoodUIInfo[];
26
+ moduleParams: MoodPageParams;
27
+ modDeleteMood: (mode: 'add' | 'edit' | 'del', currentMood: MoodUIInfo) => Promise<Result<any>>;
28
+ }
29
+
30
+ interface AddMoodPageState {
31
+ data: RecommendMood[];
32
+ }
33
+
34
+ const AddMoodPage = () => {
35
+ const navigation = useNavigation();
36
+ const routeParams = useRoute().params as AddMoodPageParams;
37
+ const moduleParams = routeParams.moduleParams;
38
+ const isMix = !!(moduleParams.isMixLight || moduleParams.isCeilingLight);
39
+ const state = useReactive<AddMoodPageState>({
40
+ data: isMix
41
+ ? getRecommendMixMoods(routeParams.isStatic, moduleParams)
42
+ : getRecommendMoods(routeParams.isStatic, moduleParams),
43
+ });
44
+
45
+ const getFormateItem = item => {
46
+ return {
47
+ ...item,
48
+ version: 0,
49
+ secondaryLamp: item.secondaryLamp ?? {
50
+ nodes: [],
51
+ mode: 0,
52
+ speed: 75,
53
+ },
54
+ };
55
+ };
56
+
57
+ const onMoodItemClick = useCallback(
58
+ (moodItem: RecommendMood) => {
59
+ const useIds = map(routeParams.moods, 'id');
60
+ const idRange = range(0, 256);
61
+ const id: number = head(difference(idRange, useIds)) || -1;
62
+ console.log(id, '< --- id ---- >')
63
+ const url = routeParams.isStatic
64
+ ? RouterKey.ui_biz_static_mood_edit
65
+ : !!(moduleParams.isCeilingLight || moduleParams.isMixLight)
66
+ ? RouterKey.ui_biz_dynamic_mix_mood_edit
67
+ : RouterKey.ui_biz_dynamic_mood_edit;
68
+ const currentMood = moodItem.mainLamp
69
+ ? { ...moodItem, id }
70
+ : newMood(id, moduleParams.isSupportColor, routeParams.isStatic, moduleParams);
71
+ navigation.navigate(url, {
72
+ mode: 'add',
73
+ currentMood,
74
+ moods: routeParams.moods,
75
+ moduleParams,
76
+ modDeleteMood: routeParams.modDeleteMood,
77
+ });
78
+ },
79
+ [routeParams]
80
+ );
81
+
82
+ return (
83
+ <Page
84
+ backText={Strings.getLang('add_new_static_mood_system_back')}
85
+ headlineText={Strings.getLang(
86
+ routeParams.isStatic
87
+ ? 'add_new_static_mood_headline_text'
88
+ : 'add_new_dynamic_mood_headline_text'
89
+ )}
90
+ >
91
+ <View style={styles.root}>
92
+ <Text style={styles.desc}>
93
+ {Strings.getLang(
94
+ routeParams.isStatic
95
+ ? 'add_new_static_mood_description_text'
96
+ : 'add_new_dynamic_mood_description_text'
97
+ )}
98
+ </Text>
99
+ <FlatList
100
+ style={{ flex: 1 }}
101
+ data={state.data}
102
+ renderItem={({ item }) => {
103
+ return (
104
+ <RecommendMoodItem
105
+ title={item.name}
106
+ isMix={isMix}
107
+ mood={getFormateItem(item)}
108
+ onPress={() => {
109
+ onMoodItemClick(item);
110
+ }}
111
+ />
112
+ );
113
+ }}
114
+ ItemSeparatorComponent={() => <Spacer />}
115
+ ListHeaderComponent={() => <Spacer />}
116
+ ListFooterComponent={() => <Spacer />}
117
+ keyExtractor={item => item.name}
118
+ />
119
+ </View>
120
+ </Page>
121
+ );
122
+ };
123
+
124
+ const styles = StyleSheet.create({
125
+ root: {
126
+ flex: 1,
127
+ flexDirection: 'column',
128
+ },
129
+ desc: {
130
+ color: '#000',
131
+ fontSize: cx(16),
132
+ marginHorizontal: cx(24),
133
+ marginTop: cx(12),
134
+ },
135
+ });
136
+
137
+ export default AddMoodPage;
138
+
139
+ function newMood(
140
+ id: number,
141
+ isColorMode: boolean,
142
+ isStatic: boolean,
143
+ moduleParams: MoodPageParams
144
+ ): MoodUIInfo {
145
+ const jump = moduleParams.isStringLight
146
+ ? MoodJumpGradientMode.StringJump
147
+ : moduleParams.isStripLight
148
+ ? MoodJumpGradientMode.StripJump
149
+ : MoodJumpGradientMode.SourceJump;
150
+ const node = {
151
+ brightness: 100,
152
+ colorTemp: 100,
153
+ h: 0,
154
+ s: 100,
155
+ v: 100,
156
+ isColorNode: !!(moduleParams.isCeilingLight || moduleParams.isMixLight) ? false : isColorMode,
157
+ };
158
+ return {
159
+ version: 0,
160
+ name: '',
161
+ image: '',
162
+ id,
163
+ mainLamp: {
164
+ speed: 75,
165
+ enable: true,
166
+ fanEnable: true,
167
+ fanSpeed: 1,
168
+ mode: isStatic ? MoodNodeTransitionMode.Static : jump,
169
+ nodes: isStatic ? [node] : [node, { ...node }],
170
+ },
171
+ secondaryLamp: {
172
+ enable: false,
173
+ mode: 0,
174
+ speed: 75,
175
+ nodes: [],
176
+ },
177
+ };
178
+ }