@ledvance/group-ui-biz-bundle 1.0.105 → 1.0.107

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,256 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo } from "react";
2
- import { ScrollView, Text, StyleSheet, FlatList, View, Image } from "react-native";
3
- import { useNavigation, useRoute } from '@react-navigation/core'
4
- import { Utils } from 'tuya-panel-kit'
5
- import Page from "@ledvance/base/src/components/Page";
6
- import I18n from "@ledvance/base/src/i18n";
7
- import { useDeviceInfo, useTimeSchedule, useUAGroupInfo } from "@ledvance/base/src/models/modules/NativePropsSlice";
8
- import res from "@ledvance/base/src/res";
9
- import Spacer from "@ledvance/base/src/components/Spacer";
10
- import InfoText from "@ledvance/base/src/components/InfoText"
11
- import DeleteButton from "@ledvance/base/src/components/DeleteButton"
12
- import ScheduleCard from "./ScheduleCard";
13
- import { ui_biz_routerKey } from "../../navigation/Routers";
14
- import { addTimeSchedule, modDelTimeSchedule, getTimeSchedule, modifyTimeSchedule } from "./TimeScheduleActions";
15
- import { Timer } from './Interface'
16
- import { useReactive, useUpdateEffect } from "ahooks";
17
- import { cloneDeep } from "lodash";
18
- import { SceneInfo } from "../mood/SceneInfo";
19
- import { StripState } from "./TimeScheduleDetailPage";
20
-
21
-
22
- const { convertX: cx } = Utils.RatioUtils
23
- const MAX_NUM = 30
24
- interface HSV {
25
- h: number
26
- s: number
27
- v: number
28
- }
29
-
30
- interface DrawToolDataType {
31
- hsv: HSV
32
- brightness: number
33
- temperature: number
34
- stripState?: StripState
35
- isColor?: boolean
36
- }
37
-
38
- export interface TimeSchedulePageParams {
39
- isSupportColor: boolean
40
- isSupportTemperature: boolean
41
- isSupportBrightness: boolean
42
- isSupportMood?: boolean
43
- isStringLight?: boolean
44
- isStripLight?: boolean
45
- isMatterLight?: boolean
46
- isSupportFan?: boolean
47
- isSupportUVC?: boolean
48
- switchLedCode?: string
49
- switchSocket1?: string
50
- switchSocket2?: string
51
- switchSocket3?: string
52
- switchSocketUSB?: string
53
- switchFan?: string
54
- fanModeCode?: string
55
- fanSpeedCode?: string
56
- workModeCode: string
57
- brightValueCode?: string
58
- brightValueFormatter?: (bright: number) => number
59
- brightValueParser?: (bright: number) => number
60
- tempValueCode?: string
61
- tempValueFormatter?: (temp: number) => number
62
- tempValueParser?: (temp: number) => number
63
- sceneDataCode?: string
64
- sceneDataDp2Obj?: (sceneDp: string) => SceneInfo
65
- sceneDataObj2Dp?: (scene: any) => string
66
- colorDataCode?: string
67
- colorDataDp2Obj?: (hex: string) => HSV
68
- colorDataObj2Dp?: (hsv: HSV) => string
69
- drawToolDataCode?: string
70
- drawToolDataObj2Dp?: (dpData: DrawToolDataType) => string
71
- drawToolDataDp2Obj?: (dp:string) => DrawToolDataType
72
- }
73
-
74
- const TimeSchedulePage = () => {
75
- const deviceInfo = useDeviceInfo()
76
- const navigation = useNavigation()
77
- const uaGroupInfo = useUAGroupInfo()
78
- const [timeScheduleStatus, setTimeScheduleStatus] = useTimeSchedule()
79
- const props = cloneDeep(useRoute().params) as TimeSchedulePageParams
80
- const state = useReactive({
81
- timeScheduleList: [] as Timer[],
82
- flag: Symbol(),
83
- loading: false
84
- })
85
-
86
- const isMaxSchedule = useMemo(() => state.timeScheduleList.length >= MAX_NUM, [state.timeScheduleList])
87
-
88
- useUpdateEffect(() => {
89
- const status = state.timeScheduleList.some(item => item.status === 1)
90
- if (status !== timeScheduleStatus) {
91
- setTimeScheduleStatus(status)
92
- }
93
- }, [JSON.stringify(state.timeScheduleList)])
94
-
95
- useEffect(() => {
96
- getTimeScheduleList().then()
97
- }, [state.flag])
98
-
99
- const navigateToEdit = useCallback((mode: 'add' | 'edit', timeSchedule?: Timer) => {
100
- const path = ui_biz_routerKey.group_ui_biz_time_schedule_edit
101
- navigation.navigate(path, {
102
- mode,
103
- name: path,
104
- timeSchedule,
105
- modDeleteTimeSchedule,
106
- refreshFn: () => {
107
- state.flag = Symbol()
108
- },
109
- ...props
110
- })
111
- }, [])
112
-
113
- const modDeleteTimeSchedule = async (mode: 'add' | 'edit' | 'del', timeSchedule: Timer, ids: string) => {
114
- if (mode === 'add') {
115
- return addTimeSchedule({
116
- ...timeSchedule,
117
- bizId: uaGroupInfo.tyGroupId.toString(),
118
- actions: timeSchedule.dps
119
- })
120
- } else if (mode === 'edit') {
121
- return modifyTimeSchedule({
122
- ...timeSchedule,
123
- bizId: uaGroupInfo.tyGroupId.toString(),
124
- actions: timeSchedule.dps
125
- })
126
- } else {
127
- return modDelTimeSchedule({
128
- bizId: uaGroupInfo.tyGroupId.toString(),
129
- status: timeSchedule.status,
130
- ids,
131
- })
132
- }
133
- }
134
-
135
- const getTimeScheduleList = async () => {
136
- const res = await getTimeSchedule({
137
- bizId: uaGroupInfo.tyGroupId.toString()
138
- })
139
- if (res.success) {
140
- state.timeScheduleList = res.data || []
141
- } else {
142
- state.timeScheduleList = []
143
- }
144
- }
145
-
146
- return (
147
- <Page
148
- backText={deviceInfo.name}
149
- onBackClick={navigation.goBack}
150
- headlineText={I18n.getLang('timeschedule_overview_headline_text')}
151
- headlineIcon={isMaxSchedule ? undefined : res.device_panel_schedule_add}
152
- onHeadlineIconClick={() => {
153
- navigateToEdit('add')
154
- }}
155
- loading={state.loading}
156
- >
157
- <ScrollView nestedScrollEnabled={true}>
158
- <Text style={styles.overviewDescription}>{I18n.getLang('timeschedule_overview_description_text')}</Text>
159
- <Spacer height={cx(10)} />
160
- {isMaxSchedule && <InfoText
161
- text={I18n.getLang('motion_detection_time_schedule_notifications_warning_text')}
162
- icon={res.ic_warning_amber}
163
- style={{ marginHorizontal: cx(24) }}
164
- textStyle={{ color: '#000' }}
165
- iconStyle={{ tintColor: '#ff9500' }}
166
- />}
167
- <FlatList
168
- data={state.timeScheduleList}
169
- renderItem={({ item }) =>
170
- (<ScheduleCard
171
- item={item}
172
- onEnableChange={(enable) => {
173
- state.loading = true
174
- modDeleteTimeSchedule('del', {
175
- ...item,
176
- status: enable ? 1 : 0
177
- }, item.id.toString()).then((res) => {
178
- if (res.success) {
179
- state.timeScheduleList = state.timeScheduleList.map(schedule => {
180
- if (schedule.id === item.id) {
181
- return {
182
- ...schedule,
183
- status: enable ? 1 : 0
184
- }
185
- }
186
- return schedule
187
- })
188
- }
189
- state.loading = false
190
- })
191
- }}
192
- onPress={() => {
193
- navigateToEdit('edit', item)
194
- }}
195
- onLongPress={() => { }}
196
- />)}
197
- keyExtractor={(item) => item.id.toString()}
198
- ListEmptyComponent={() => (
199
- <View style={styles.emptyContainer}>
200
- <Spacer height={cx(60)} />
201
- <Image
202
- style={styles.emptyImage}
203
- source={{ uri: res.ldv_timer_empty }}
204
- resizeMode="contain"
205
- />
206
- <InfoText
207
- icon={res.device_panel_schedule_alert}
208
- text={I18n.getLang('timeschedule_overview_empty_information_text')}
209
- style={{ width: 'auto', alignItems: 'center' }}
210
- textStyle={{ color: '#000', flex: undefined }}
211
- iconStyle={{ tintColor: '#000' }}
212
- />
213
- <Spacer height={cx(16)} />
214
- <DeleteButton
215
- style={styles.addBtn}
216
- text={`${I18n.getLang('timeschedule_overview_empty_button_add_text')}`}
217
- textStyle={{ fontSize: cx(12) }}
218
- onPress={() => {
219
- navigateToEdit('add')
220
- }}
221
- />
222
- </View>
223
- )}
224
- ListHeaderComponent={() => <Spacer height={cx(10)} />}
225
- ItemSeparatorComponent={() => <Spacer />}
226
- ListFooterComponent={() => <Spacer height={cx(30)} />}
227
- />
228
- </ScrollView>
229
- </Page>
230
- )
231
- }
232
-
233
-
234
- const styles = StyleSheet.create({
235
- overviewDescription: {
236
- color: '#000',
237
- marginHorizontal: cx(24)
238
- },
239
- emptyImage: {
240
- width: cx(225),
241
- height: cx(198),
242
- },
243
- emptyContainer: {
244
- marginHorizontal: cx(24),
245
- alignItems: 'center'
246
- },
247
- addBtn: {
248
- height: cx(45),
249
- width: 'auto',
250
- minWidth: cx(150),
251
- paddingHorizontal: cx(16),
252
- backgroundColor: '#f60'
253
- }
254
- })
255
-
256
- export default TimeSchedulePage