@ledvance/ui-biz-bundle 1.0.71 → 1.0.73

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
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.0.71",
7
+ "version": "1.0.73",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -0,0 +1,158 @@
1
+ import React, { useCallback, useEffect } from 'react'
2
+ import Page from '@ledvance/base/src/components/Page'
3
+ import { Utils } from 'tuya-panel-kit'
4
+ import { StripScenePageUIState, StripSceneUIState } from '../scene/SceneInfo'
5
+ import { getRemoteFantasyScene, useFantasyScene } from '../scene/SceneAction'
6
+ import { useDeviceInfo } from '@ledvance/base/src/models/modules/NativePropsSlice'
7
+ import { useReactive } from 'ahooks'
8
+ import Strings from '@ledvance/base/src/i18n'
9
+ import res from '@ledvance/base/src/res'
10
+ import { FlatList } from 'react-native'
11
+ import Spacer from '@ledvance/base/src/components/Spacer'
12
+ import FantasyMoodItem from './FantasyMoodItem'
13
+ import { useNavigation, useRoute } from '@react-navigation/core'
14
+ import { ui_biz_routerKey } from '../../navigation/Routers'
15
+ const cx = Utils.RatioUtils.convertX
16
+
17
+ interface MoodPageUIState extends StripScenePageUIState {
18
+ staticTagChecked: boolean
19
+ dynamicTagChecked: boolean
20
+ originScene: StripSceneUIState[]
21
+ filteredMoods: StripSceneUIState[]
22
+ loading: boolean
23
+ }
24
+
25
+ export interface FantasyMoodPageProps {
26
+ featureId: string
27
+ switchLedDpCode: string
28
+ sceneDpCode: string
29
+ workModeDpCode: string
30
+ isStringLight?: boolean
31
+ isStripLight?: boolean
32
+ isSupportColor: boolean
33
+ isSupportTemperature: boolean
34
+ isSupportBrightness: boolean
35
+ }
36
+
37
+
38
+ const FantasyMoodPage = () => {
39
+ const routeParams = useRoute().params as FantasyMoodPageProps
40
+ const params: FantasyMoodPageProps = {
41
+ ...routeParams,
42
+ }
43
+ const [sceneId, setScene] = useFantasyScene(params.sceneDpCode, params.workModeDpCode, params.isStringLight)
44
+ const deviceInfo = useDeviceInfo()
45
+ const navigation = useNavigation()
46
+
47
+ const state = useReactive<MoodPageUIState>({
48
+ currentScene: undefined,
49
+ staticTagChecked: true,
50
+ dynamicTagChecked: true,
51
+ scenes: [],
52
+ flag: Symbol(),
53
+ originScene: [],
54
+ filteredMoods: [],
55
+ loading: false,
56
+ })
57
+
58
+ const getSceneList = useCallback(async (currentSceneId: number) => {
59
+ const res = await getRemoteFantasyScene(routeParams.featureId, deviceInfo.devId, { isStringLight: routeParams.isStringLight, isStripLight: routeParams.isStripLight })
60
+ if (res.success) {
61
+ state.scenes = res.data || []
62
+ state.currentScene = state.scenes.find(scene => scene.id === currentSceneId)
63
+ }
64
+ }, [])
65
+
66
+
67
+ useEffect(() => {
68
+ getSceneList(sceneId).then()
69
+ }, [state.flag, sceneId])
70
+
71
+ const navigateToEdit = useCallback((mode: 'edit' | 'add', currentMood?: StripSceneUIState) => {
72
+ navigation.navigate(ui_biz_routerKey.ui_biz_fantasy_mood_edit, {
73
+ mode,
74
+ currentMood,
75
+ moods: state.scenes,
76
+ moduleParams: params,
77
+ onSave: () => {
78
+ state.flag = Symbol()
79
+ },
80
+ })
81
+ }, [])
82
+
83
+ const getSwitchEnable = useCallback((id: number) =>{
84
+ return state.currentScene?.id === id
85
+ }, [state.currentScene?.id])
86
+
87
+ return (
88
+ <>
89
+ <Page
90
+ backText={deviceInfo.name}
91
+ headlineText={Strings.getLang('mood_overview_headline_text')}
92
+ headlineIcon={res.add}
93
+ onHeadlineIconClick={() => {
94
+ navigateToEdit('add', newScene)
95
+ }}
96
+ loading={state.loading}>
97
+ <Spacer height={cx(10)} />
98
+ <FlatList
99
+ data={state.scenes}
100
+ renderItem={({ item }) => {
101
+ return (
102
+ <FantasyMoodItem
103
+ enable={getSwitchEnable(item.id)}
104
+ mood={item}
105
+ onPress={() => {
106
+ navigateToEdit('edit', item)
107
+ }}
108
+ onSwitch={async _ => {
109
+ if (getSwitchEnable(item.id)) return
110
+ state.loading = true
111
+ await setScene(item)
112
+ state.loading = false
113
+ }} />
114
+ )
115
+ }}
116
+ ListHeaderComponent={() => (<Spacer height={cx(10)} />)}
117
+ ItemSeparatorComponent={() => (<Spacer />)}
118
+ ListFooterComponent={() => (<Spacer />)}
119
+ keyExtractor={item => `${item.id}`} />
120
+ </Page>
121
+ </>
122
+ )
123
+ }
124
+
125
+ const newScene = {
126
+ version: 1,
127
+ id: 1,
128
+ mode: 10,
129
+ name: '',
130
+ speed: 50,
131
+ loop: 0,
132
+ segmented: 0,
133
+ direction: 0,
134
+ excessive: 0,
135
+ optionB: 0,
136
+ optionC: 0,
137
+ image: '',
138
+ nodes: [
139
+ {
140
+ brightness: 0,
141
+ colorTemp: 0,
142
+ h: 0,
143
+ isColorNode: true,
144
+ s: 100,
145
+ v: 100
146
+ },
147
+ {
148
+ brightness: 0,
149
+ colorTemp: 0,
150
+ h: 60,
151
+ isColorNode: true,
152
+ s: 100,
153
+ v: 100
154
+ }
155
+ ]
156
+ }
157
+
158
+ export default FantasyMoodPage